我已經撰寫了一個腳本來將所有已安裝的補丁匯出到一個 CSV 檔案中,并且我已經為輸出添加了服務器啟動時間變數,但是我的輸出有一個帶有啟動時間的名稱,我只需要日期和時間特定服務器,但不是輸出中的最后一個啟動時間字
輸出 @{lastbootuptime=1/14/2022 4:44:54 AM}
<#
Script to list all installed MS Patches on a remote system and export
.DESCRIPTION
This Script is used to check for all installed MS Patchesres on the specified servers and to export.
#>
## Clear the PS Console
Clear-Host
## Remove the Existing Out file
$FileName = "C:\Users\a-lchandrakanthredd\Desktop\Test\Installed_Patches.csv"
if (Test-Path $FileName) {
Remove-Item $FileName
Write-Host "Deleted the Existing OutPut file" -BackgroundColor Red -ForegroundColor Green
}
## List of Servers to check for Installed Patches
$serversToCheck = Get-Content "C:\Users\a-lchandrakanthredd\Desktop\Test\Servers.txt"
## Define the Output file path
$outfile = "C:\Users\a-lchandrakanthredd\Desktop\Test\Installed_Patches.csv"
## Lopping through specified servers
ForEach ( $server in $serversToCheck )
{
##Server Boot Time
$BootTime = Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime
Get-WmiObject Win32_QuickFixEngineering -ComputerName $server |
Where-Object { $_.InstalledOn -gt (Get-Date).AddMonths(-3) } |
Select-Object -Property PSComputerName, __PATH, Description, InstalledOn, HotFixID, InstalledBy, @{n='Server_Boot_Time';e={$BootTime}} |
Export-Csv -Path $outfile -Append
}
uj5u.com熱心網友回復:
您只需要將$BootTime變數修改為:
$BootTime = (Get-CimInstance -ClassName win32_operatingsystem).lastbootuptime
或者
Get-CimInstance -ClassName win32_operatingsystem | select -ExpandProperty lastbootuptime
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415808.html
標籤:
上一篇:為什么將外部應用程式通過管道傳輸到Select-Object-First1將$LastExitCode設定為-1?
