Scenario 3 – using PowerShell to get the Configuration Manager installation directory
One of the most common automation tasks that we carry out for Configuration Manager is the Configuration Manager health check framework. This primarily involves detecting the Configuration Manager installation directory.
It is not good practice to use the installation directory variable as static, but it is always advised that you make the variable dynamic, so that the script becomes more flexible and reusable. This example shows how PowerShell can be used to access the Configuration Manager installation directory:
Set-Location 'HKLM\SOFTWARE\Microsoft\SMS\Identification\ Installation Directory' $AllProp = Get-ItemProperty -path "HKLM\SOFTWARE\Microsoft\SMS\Identification\ Installation Directory" $InstallDir = $AllProp."Installation directory" Write-Host "$InstallDir"
You can use Set-Location
only if you are not specifying the full path for the Get-ItemProperty
cmdlet. Here, we use the full path for both cmdlets...