Powershell 在DC'上获得修补程序;s和show DC';你错过了什么
但是,powershell脚本按原样工作;它只显示安装了它的DC,不添加缺少它的DC(补丁)。我如何添加代码来添加DC名称,即使它缺少补丁Powershell 在DC'上获得修补程序;s和show DC';你错过了什么,powershell,dns,patch,Powershell,Dns,Patch,但是,powershell脚本按原样工作;它只显示安装了它的DC,不添加缺少它的DC(补丁)。我如何添加代码来添加DC名称,即使它缺少补丁 $default_log = $env:userprofile + "\Desktop\report_dc_installed_Hotfixes.csv" $KBPatch = Read-Host "Enter the KB Number" get-hotfix -id $KBPatch -ComputerName ((get-adforest).gl
$default_log = $env:userprofile + "\Desktop\report_dc_installed_Hotfixes.csv"
$KBPatch = Read-Host "Enter the KB Number"
get-hotfix -id $KBPatch -ComputerName ((get-adforest).globalcatalogs) | `select @{name='ServerName';expression={$_.CSName}},HotFixID,InstalledBy,InstalledOn | `export-csv $default_log -append –NoTypeInformation
我会这样做[未经测试]
$default_log = $env:userprofile + "\Desktop\report_dc_installed_Hotfixes.csv"
$KBPatch = Read-Host "Enter the KB Number"
(get-adforest).globalcatalogs | % {
$hf_installed = $true
try {
$hf = get-hotfix -id $KBPatch -ComputerName $_ -ErrorAction Stop
} catch {
$hf_installed = $false
}
if ($hf_installed) {
$hf | `select @{name='ServerName';expression={$_.CSName}},@{name='HotfixInstalled';expression={$hf_installed}},HotFixID,InstalledBy,InstalledOn | `export-csv $default_log -append –NoTypeInformation
} else {
[pscustomobject] @{
'ServerName'=$_;
'HotfixInstalled'=$hf_installed
} | export-csv $default_log -append –NoTypeInformation
}
}
逻辑解释:
…你为什么不直接使用原力?你想要输出什么?全球目录。从那里开始 你想知道关于他们的什么?他们的名字,选择那个。他们是否安装了修补程序。选择那个 你想把它放在哪里?在您的CSV中。把它放在那里
(Get-ADForest).GlobalCatalogs |
Select-Object @{Name='ServerName'; Expression={$_}},
@{Name="HotFixInstalled"; Expression={
[bool](Get-HotFix -Id $KBPatch -ComputerName $_ -EA SilentlyContinue)
}} |
Export-Csv -Path $DefaultLog -Append –NoTypeInformation
你怎么能做到?重写代码以迭代GC服务器列表,如果安装了修补程序,则输出
$true
;如果未安装修补程序,则输出$false
。