This commit is contained in:
2020-09-28 15:14:18 -04:00
parent f3b3552726
commit 54754d4d6b
3 changed files with 51 additions and 23 deletions
+22 -4
View File
@@ -1,6 +1,12 @@
## Get contents of SYSTEM PATH environment variable
## Source the tools script if it isn't already available
If ( !($MSPName) ) { . $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) }
## Set the name of the log file
$LogName = 'Cleanup-SystemPath'
## Get contents of SYSTEM PATH environment variable
$REG_ENVVAR = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
$CURRENT_PATH = (Get-Itemproperty -Path $REG_ENVVAR -Name Path).Path
$CURRENT_PATH = (Get-ItemProperty -Path $REG_ENVVAR -Name Path).Path
$NEW_PATH = $null
$REMOVE_PATH =$null
@@ -19,6 +25,18 @@ Foreach ( $path in $CURRENT_PATH.Split(";") )
}
}
Write-Output "Removed Paths:`n`r${REMOVE_PATH}"
Log "Removed Paths:`n`r${REMOVE_PATH}" -Name $LogName
Set-ItemProperty -Path $REG_ENVVAR -Name Path -Value $NEW_PATH
Try { Set-ItemProperty -Path $REG_ENVVAR -Name Path -Value $NEW_PATH }
Catch
{
$_.Exception.Message | Log -Error -Name $LogName
Log "Failed to cleanup system path, using original values" -Error -Name $LogName
Try { Set-ItemProperty -Path $REG_ENVVAR -Name Path -Value $CURRENT_PATH }
Catch
{
$_.Exception.Message | Log -Error -Name $LogName
Log "This is not good... !! DO NOT RESTART UNTIL SYSTEM PATH IS FIXED !!" -Error -Name $LogName
Exit
}
}