$servers=get-content D:\serverregister.txtGet$servers
Function Get-registerkey
Reference a part of the code in the previous article to make changes to query the Susid of the server from the registry
Functionget-registerkey{<# #>[Cmdletbinding ()]param([Parameter (Position=0,valuefrompipeline=$true, valuefrompipelinebypropertyname=$true)] [Alias ("CN","Computer")] [string[]]$ComputerName="$env: COMPUTERNAME", [String]$ErrorLog ) Begin{ }## End Begin Script BlockProcess { Foreach($Computer inch $ComputerName) {Try {## Querying WMI for build version $WMI _os= Get-wmiobject-class Win32_operatingsystem-property BuildNumber, Csname-computername$Computer-erroraction Stop## Making Registry connection to the Local/remote computer $HKLM= [UInt32]"0x80000002" $WMI _reg= [WMIClass]"\ \ $Computer \root\default:StdRegProv" ## Query Susclientid from the registry $RegWUAUsusid=$WMI _reg. GetStringValue ($HKLM,"software\microsoft\windows\currentversion\windowsupdate\","Susclientid") $WUAUsusid=$RegWUAUsusid. svalue## Creating Custom psobject and Select-object Splat $SelectSplat= @{ Property=(' computer ', ' Susid ')} New-object-typename Psobject-property @{Computer=$WMI _os. CSName Susid=$WUAUsusid } | Select-object @Selectsplat} Catch {Write-warning"$Computer ': $_" ## If $ErrorLog, log the file to a user specified Location/path If($ErrorLog) { out-file-inputobject"$Computer ', $_"-filepath$ErrorLog-Append}} }## End Foreach ($Computer in $ComputerName)}## End Process End{ }## end End }## End Function get-registerkey
View Code
Powershell Get-registerkey (SUSID)