Powershell Get-registerkey(susid)

 

$servers=get-content D:\serverregister.txt
Get-registerkey -ComputerName $servers | select computer,susid| Export-Csv d:\registerkey1.csv -NoTypeInformation 

 

Function Get-registerkey

引用前一篇文章中的代码的一部分做修改,从注册表中查询server的susid

Function Get-registerkey
{
<#
 
#>
[CmdletBinding()]
param(
        [Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
        [Alias("CN","Computer")]
        [String[]]$ComputerName="$env:COMPUTERNAME",
        [String]$ErrorLog
        )
 
Begin {  }## End Begin Script Block
Process {
  Foreach ($Computer in $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

 

posted @ 2017-06-26 21:32  寻香径  阅读(479)  评论(0编辑  收藏  举报