Powershell. Свой WMI класс
28 Nov 2019
local_offer
powershell
local_offer
wmi
Import-Module "C:\Program Files\WindowsPowerShell\Modules\WMI-Commands\WMI-Commands.psm1"
$customClassName = "SBS_ComputerSystemProduct"
New-WMIClass -ClassName $customClassName
New-WMIProperty -ClassName $customClassName -PropertyName Name
New-WMIProperty -ClassName $customClassName -PropertyName InventoryNumber
New-WMIProperty -ClassName $customClassName -PropertyName SecurityStickerNumber
New-WMIProperty -ClassName $customClassName -PropertyName SecurityStickerIsBroken
Set-WMIPropertyQualifier -ClassName $customClassName -PropertyName Name -key
$array | % {
$InventoryClass = [wmiclass]("root/cimv2:" + $customClassName)
$NewInvClass = $InventoryClass.CreateInstance()
$NewInvClass.Name = $_.Name
$NewInvClass.InventoryNumber = $_.InventoryNumber
$NewInvClass.SecurityStickerNumber = $_.SecurityStickerNumber
$NewInvClass.SecurityStickerIsBroken = $false
$NewInvClass.Put()
}
Проверяем:
$customClassName = "SBS_ComputerSystemProduct"
$sbsprop = Get-WMIObject $customClassName
$sbsprop
Заполняем:
$customClassName = "SBS_ComputerSystemProduct"
$sbsprop = Get-WMIObject $customClassName
$sbsprop.InventoryNumber = "740245"
$sbsprop.SecurityStickerNumber = "22223452354636"
$sbsprop.put()