Powershell 2.0 - 调用-wmimethod 并在 gridview 中获取计算机名称
Powershell 2.0 - Invoke-wmimethod and get the computer name in gridview
我有一个 powershell script/gui,我想用它向所有 ActiveDirectory 广播消息 computers.The 消息确实被广播到所有工作站,但我想获取计算机名称(作为输出)如果可能,在通过网格视图为每台计算机运行 invoke-wmimthod 之前。
function BroadcastMulti{
Import-Module active*
try{
$msg = read-host "Enter your message "
$List = Get-ADComputer -Filter {Name -like "PC*"} | Select -ExpandName
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "msg /time:3600 * $msg" -ComputerName $List
}catch{
[System.Windows.Forms.MessageBox]::Show("Input was not entered correctly")
}
}
}
function BroadcastMulti{
Import-Module active*
try{
$msg = read-host "Enter your message "
$List = Get-ADComputer -Filter {Name -like "Computer*"} | Select-Object -ExpandProperty Name
foreach($_ in $list){
Write-Host $_
$_ | Out-File C:\SupportTools\BroadcastReport.txt -Append
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "msg /time:43200 * $msg" -ComputerName $_
}
#[System.Windows.Forms.MessageBox]::Show("Message sent to all workstations")
}catch{
[System.Windows.Forms.MessageBox]::Show("There was an error, please try again")
}
}
我有一个 powershell script/gui,我想用它向所有 ActiveDirectory 广播消息 computers.The 消息确实被广播到所有工作站,但我想获取计算机名称(作为输出)如果可能,在通过网格视图为每台计算机运行 invoke-wmimthod 之前。
function BroadcastMulti{
Import-Module active*
try{
$msg = read-host "Enter your message "
$List = Get-ADComputer -Filter {Name -like "PC*"} | Select -ExpandName
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "msg /time:3600 * $msg" -ComputerName $List
}catch{
[System.Windows.Forms.MessageBox]::Show("Input was not entered correctly")
}
}
}
function BroadcastMulti{
Import-Module active*
try{
$msg = read-host "Enter your message "
$List = Get-ADComputer -Filter {Name -like "Computer*"} | Select-Object -ExpandProperty Name
foreach($_ in $list){
Write-Host $_
$_ | Out-File C:\SupportTools\BroadcastReport.txt -Append
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "msg /time:43200 * $msg" -ComputerName $_
}
#[System.Windows.Forms.MessageBox]::Show("Message sent to all workstations")
}catch{
[System.Windows.Forms.MessageBox]::Show("There was an error, please try again")
}
}