码迷,mamicode.com
首页 > 系统相关 > 详细

Powershell Get-registerkey(susid)

时间:2017-06-26 22:26:40      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:computer   eating   and   div   input   bin   gif   txt   window   

 

$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

 

Powershell Get-registerkey(susid)

标签:computer   eating   and   div   input   bin   gif   txt   window   

原文地址:http://www.cnblogs.com/scentpath/p/registerkey.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!