Site icon Franky's Web

Powershell: Search registry of clients for CAS array and report

Here I had has already shown a tool with which the server name in the Outlook profile can be changed. For example, from a single server to a CAS array. The tool can be easily executed via a login script, for example. However, the question then arises as to whether all clients have been "caught" and whether the server name has been changed correctly. For this purpose, I have built a small Powershell script that searches the registry of the clients for the new server name. The script only needs to be fed with a CSV file containing the user names and computer names. Something like this:

Prerequisite for the script is a user who has access to the registry of the PCs, i.e. a domain admin and this Powershell module:

http://archive.msdn.microsoft.com/PSRemoteRegistry

Here is the script:

$logfilepath = „D:\user.csv“
$casarray = „cas.frankysweb.local“
$domain = „frankysweb.local“

#————————————————————————————-

$logfile = import-csv $logfilepath -Delimiter „;“
foreach ($line in $logfile)
{

$user = $line.Username
$computername = $line.hostname

#Check if Host alive

if (test-connection -computername $computername -count 1 -quiet)
{

#Username to SID
$objUser = New-Object System.Security.Principal.NTAccount(„$domain“, „$user“)
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$SID = $strSID.Value

#search remote registry

$regkey = „$SID\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles“

if (get-regkey -ComputerName $computername -hive „Users“ -key $sid -name Software -ErrorAction SilentlyContinue)
{

if (get-regkey -ComputerName $computername -hive „Users“ -key „$sid\Software\Microsoft\Windows NT\CurrentVersion“ -name „Windows Messaging Subsystem“ -ErrorAction SilentlyContinue)
{
$outlookprofile = get-regkey -ComputerName $computername -hive „Users“ -key $regkey -name * -ErrorAction SilentlyContinue | get-regvalue -type String -recurse
if ($outlookprofile -match „$casarray“)
{
write-host „Benutzer:`t$user`tComputer:`t$computername`tStatus:`tCAS Array gefunden“ -foregroundcolor „green“
}
else
{
write-host „Benutzer:`t$user`tComputer:`t$computername`tStatus:`tCAS Array nicht gefunden“ -foregroundcolor „red“
}
}
else
{
write-host „Benutzer:`t$user`tComputer:`t$computername`tStatus:`tOutlook nicht gefunden“ -foregroundcolor „yellow“
}
}
else
{
write-host „Benutzer:`t$user`tComputer:`t$computername`tStatus:`tSID nicht gefunden“ -foregroundcolor „yellow“
}
}
else
{
write-host „Benutzer:`t$user`tComputer:`t$computername`tStatus:`tPC aus“ -foregroundcolor „gray“
}
}

Good luck.

Exit mobile version