zoukankan      html  css  js  c++  java
  • Powershell Get-registerkey(susid)

    $servers=get-content D:serverregister.txt
    Get-registerkey -ComputerName $servers | select computer,susid| Export-Csv d:
    egisterkey1.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
    ootdefault:StdRegProv"
                
                ## Query SusClientId from the registry
               $RegWUAUsusid = $WMI_Reg.GetStringValue($HKLM,"SOFTWAREMicrosoftWindowsCurrentVersionWindowsUpdate","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
  • 相关阅读:
    爬虫练习
    爬取豆瓣电影top250
    简单爬虫
    正则提取子域名和ip
    用户体验培训总结
    测试经验总结
    项目管理知识总结
    读书笔记——《留住好员工:爱他们,还是失去他们?》
    ISTQB学习笔记
    数据结构和算法with Python
  • 原文地址:https://www.cnblogs.com/thescentedpath/p/registerkey.html
Copyright © 2011-2022 走看看