powershell AD-GET-Windows的补丁

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell AD-GET-Windows的补丁相关的知识,希望对你有一定的参考价值。

$ddate = $($(get-date).addDays(-365))
$OUPath ='OU=Servers'
$computers = Get-ADComputer -Filter {LastLogonDate -gt $ddate -and passwordlastset -gt $ddate} -SearchBase $OUPath

$Results = @()
 
foreach ($computer in $computers){
    #write-host $computer -Properties * | LastLogonDate
    #Get-ADComputer -identity $computer.Name -Properties * | FT Name, LastLogonDate -Autosize
    if(Test-NetConnection -ComputerName $computer.Name -Port 5985 -InformationLevel Quiet -ErrorAction silentlycontinue){
        $Results += Invoke-Command -ComputerName $computer.Name -ScriptBlock { Get-HotFix }
    }
    else {
        $FailedComputers += $computer.Name
    }
}
#https://community.spiceworks.com/how_to/139222-how-to-list-all-windows-updates-using-powershell?utm_source=copy_paste&utm_campaign=growth
#$Session = New-Object -ComObject "Microsoft.Update.Session"
#$Searcher = $Session.CreateUpdateSearcher()
#$historyCount = $Searcher.GetTotalHistoryCount()
#$Searcher.QueryHistory(0, $historyCount) | Select-Object Date,@{name="Operation"; expression={switch($_.operation){1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}}, @{name="Status"; expression={switch($_.resultcode){1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};4 {"Failed"}; 5 {"Aborted"} }}}, Title,  Description | Export-Csv -NoType "$Env:userprofile\Desktop\Windows Updates.csv"

$ddate = $($(get-date).addDays(-365))
$OUPath ='ou path'
$computers = Get-ADComputer -Filter {LastLogonDate -gt $ddate -and passwordlastset -gt $ddate} -SearchBase $OUPath


foreach ($computer in $computers){
    #write-host $computer -Properties * | LastLogonDate
    #Get-ADComputer -identity $computer.Name -Properties * | FT Name, LastLogonDate -Autosize
    Get-HotFix -ComputerName $computer.Name
    #Get-HotFix -ComputerName $computer.Name | Export-Csv -NoType "$Env:userprofile\Desktop\Patches\$($computer.Name) + Windows Updates.csv"

    <#
    $testSession = New-PSSession -Computer $computer.Name
    if(-not($testSession))
    {
        Write-Warning "$computer.Name inaccessible!"
    }
    else
    {   
        Invoke-Command -Session $testSession -ScriptBlock {
            Get-HotFix
        }

        Remove-PSSession $testSession
    }
    #>
}


以上是关于powershell AD-GET-Windows的补丁的主要内容,如果未能解决你的问题,请参考以下文章

powershell怎么运行

powershell PowerShell:启动PowerShell作为其他用户提升

powershell [提示输入powershell] #powershell #input #prompt

powershell 测量PowerShell命令或PowerShell脚本的速度

powershell远程下载exe并执行

powershell 使用啥端口