SCCM – PowerShell – Remove Reg Keys on Remote Computers

email me

I wrote this to remove GPRequestedSiteAssignmentCode and AssignedSiteCode registry values under the HKLM\SOFTWARE\Microsoft\SMS\Mobile Client registry key. Just add the computer names into the computers.txt file and run. Note, WINRM will need to be enabled on the remote computers/servers.

Clear-Host
$user = Read-Host "Enter Domain\Username"
$credential = Get-Credential -Credential "$user"
$Computers = Get-Content "c:\PowerShell\computers.txt"
try
{
Invoke-Command -ComputerName $Computers -Credential $credential -ScriptBlock {Remove-ItemProperty -Path HKLM:"\SOFTWARE\Microsoft\SMS\Mobile Client" -name AssignedSiteCode}
Invoke-Command -ComputerName $Computers -Credential $credential -ScriptBlock {Remove-ItemProperty -Path HKLM:"\SOFTWARE\Microsoft\SMS\Mobile Client" -name GPRequestedSiteAssignmentCode}
}
catch
{
$output = $_
$output
}