powershell脚本按原样工作;它只显示安装它的DC,并且不添加缺少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).globalcatalogs) | `select @{name='ServerName';expression={$_.CSName}},HotFixID,InstalledBy,InstalledOn | `export-csv $default_log -append –NoTypeInformation
答案 0 :(得分:1)
你想要的输出是什么?全球目录。从那里开始。
您想了解他们什么?他们的名字,选择那个。他们是否安装了修补程序。选择那个。
你想要它在哪里?在您的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
答案 1 :(得分:0)
这是我怎么做的[未经测试] ......
$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
}
}
逻辑解释:
..你为什么不用力?