CI to Monitor Path Variable

As mentioned in Previous Post, we’ve had upgrades fail due to non-standard path variables. I’ve created a CI that captures the path and looks for specific things then reports Compliant, or reports the issue, which we track with reports.  We use this in our PreAssessment / PreFlight Rules, so if this is Non-Compliant, it prevents the machine from Upgrading.

CI Images:

 

Script:

#Get Current Path
$Environment = [System.Environment]::GetEnvironmentVariable("Path", "Machine")

 
    foreach ($path in ($Environment).Split(";"))
        {
        if ($path -eq "C:\WINDOWS\system32"){$Path_System32 = $true}
        if ($path -eq "C:\WINDOWS"){$Path_Windows = $true}
        if ($path -eq "C:\WINDOWS\System32\Wbem"){$Path_Wbem = $true}
        if ($path -eq "C:\WINDOWS\System32\WindowsPowerShell\v1.0\"){$Path_PoSH64 = $true}
        if ($path -like "*SysWOW64\WindowsPowerShell\v1.0*"){$Path_PoSH32 = $true}
        }

    #This runs a PowerShell Instance in the default environment to determine if 32 or 64 bit.
    $Running64bit = PowerShell.exe -command [Environment]::Is64BitProcess 

    #Logic Section

    #Was Powershell running 32Bit?
    if ($Running64bit –eq $false)
        {
        $SystemPathStatus = "Fail - Using 32bit PowerShell"
        Write-Output "System Path Status: $SystemPathStatus"
        }
    else
        {
        #Is there other Path issues?
        if ($Path_System32 -eq $null -or $Path_Windows -eq $null -or $Path_Wbem -eq $null -or $Path_PoSH64 -eq $null )
            {
            $SystemPathStatus = "Fail - Missing Critical Path Information"
            Write-Output "System Path Status: $SystemPathStatus"

            }
        else
            {
            $SystemPathStatus = "Pass"
            Write-Output "Compliant"
            }
        }

Reporting… yeah, I still need to blog a bunch of reports, for now, just to show that it works. 🙂

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.