0
我遇到了這個非常有用且簡單的powershell腳本來編寫事件日誌。 我的問題是我想寫結果作爲事件消息。我得到了類似於$ result變量的東西,但不完全像在屏幕上打印的那樣。有人能指出我正確的方向嗎?將Powershell變量結果附加到事件日誌中
begin {
$EventHashInformation = @{
LogName = 'Application'
Source = 'My Script'
EventId = 2783
EntryType = 'Information'
}
$EventHashWarning = @{
LogName = 'Application'
Source = 'My Script'
EventId = 2784
EntryType = 'Warning'
}
Write-EventLog @EventHashInformation -Message 'Script started'
}
process {
try {
$result = Get-CimInstance -ClassName Win32_Bios -ErrorAction Stop
Write-EventLog @EventHashInformation -Message $result
} catch {
Write-EventLog @EventHashWarning -Message 'Error occurred while queried Win32_Bios'
}
}
end {
Write-EventLog @EventHashInformation -Message 'Script finished'
}
這是我在事件得到日誌
Win32_BIOS: BIOS Date: 05/23/12 17:15:53 Ver: 09.00.06 (Name = "BIOS Date: 05/23/12 17:15:53 Ver: 09.0..., SoftwareElementID = "BIOS Date: 05/23/12 17:15:53 Ver: 09.0..., SoftwareElementState = 3, TargetOperatingSystem = 0, Version = "VRTUAL - 5001223") : %2
這就是我需要(在PowerShell中絲網印刷)
SMBIOSBIOSVersion : 60KT38AUS
Manufacturer : LENOVO
Name : Lenovo ThinkStation BIOS Ver 60KT38.0
SerialNumber : MJWNY54
Version : LENOVO - 60400d0
你可以展示你的得到和你的期望NG? – ArcSet