PowerShell - Powershell. Key Management Service Report

Ответить
Аватара пользователя
KATOCHIMOTO

PowerShell - Powershell. Key Management Service Report

Сообщение KATOCHIMOTO »

Имеется вот такой скрипт (есть в интернете):




Цитата:



Get-WmiObject -class Win32_NTLogEvent -computerName $RemoteComputerName -filter "Logfile='Key Management Service' And EventCode=12290" | foreach-object {



$_ | Add-Member noteproperty "Return Code" $_.InsertionStrings[1]

$_ | Add-Member noteproperty "Minimum Count To Activate" $_.InsertionStrings[2]

$_ | Add-Member noteproperty Machine $_.InsertionStrings[3]

$_ | Add-Member noteproperty "Client Machine ID" $_.InsertionStrings[4]

$_ | Add-Member noteproperty "Client Time" $_.InsertionStrings[5]

$_ | Add-Member noteproperty "VM Info" $_.InsertionStrings[6]

$_ | Add-Member noteproperty "Licensing Status" $_.InsertionStrings[7]

$_ | Add-Member noteproperty "Time to Expiration, min" $_.InsertionStrings[8]

$_ | Add-Member noteproperty "Activation ID" $_.InsertionStrings[9]



write-output $_ | select-object RecordNumber, Machine, "Return Code", "Minimum Count To Activate", "Client Machine ID", "Client Time", "VM Info", "Licensing Status", "Time to Expiration, min", "Activation ID"

}



выводит инфу вот так


Цитата:



RecordNumber : 16002

Machine : C-DC1.contoso.com

Return Code : 0x0

Minimum Count To Activate : 5

Client Machine ID : *******-***-***-***-*******

Client Time : 2014/02/10 15:52

VM Info : 1

Licensing Status : 1

Time to Expiration, min : 249120

Activation ID : ******-****-*****-****-******



Значения он берет из журнала событий. Как сделать что бы выдаваемое значения в VM Info вместо 1, было- Virtual machine, а если 0 то Phisical Machine ? и License Status в зависимости от 0 до 4 выдало не цифру а Licensed status:

0 -Unlicensed

1 - Licensed

2 - Out-Of-Box Grace Period

3 - Out-Of-Tolerance Grace Period

4 -Non-Genuine Grace Period
Аватара пользователя
Kazun

Re: PowerShell - Powershell. Key Management Service Report

Сообщение Kazun »

Код:

Код: Выделить всё

$pc = @{1="Virtual machine";0="Phisical Machine"}
PS > $pc[1]
Virtual machine
PS > $a | Foreach {$pc[$_."VM Info"]}
Virtual machine



Код:

Код: Выделить всё

$lic = @{0="Unlicensed";1="Licensed";3="Out-Of-Tolerance Grace Period";4="Non-Genuine Grace Period"}
Аватара пользователя
KATOCHIMOTO

Re: PowerShell - Powershell. Key Management Service Report

Сообщение KATOCHIMOTO »

а как бы его в код вставить ?

Я не совсем хорошо разбираюсь.
Аватара пользователя
KATOCHIMOTO

Re: PowerShell - Powershell. Key Management Service Report

Сообщение KATOCHIMOTO »

Код:

Код: Выделить всё

$pc = @{1="Virtual machine";0="Phisical Machine"}
$lic = @{0="Unlicensed";1="Licensed";3="Out-Of-Tolerance Grace Period";4="Non-Genuine Grace Period"}
Get-WmiObject -class Win32_NTLogEvent ...... | Foreach {
	..........
	$_ | Add-Member noteproperty "VM Info" $pc[[int]$_.InsertionStrings[6]]
	$_ | Add-Member noteproperty "Licensing Status" $lic[[int]$_.InsertionStrings[7]]
	.......
}
Ответить

Вернуться в «Скриптовые языки администрирования Windows»