:たとえば
$ComputerName= ‘computername here’
[System.Net.Dns]::GetHostAddresses(“$ComputerName”).IPAddressToString
$ComputerIPAddress = ‘that computer ip here'
[System.Net.Dns]::GetHostEntry($ComputerIPAddress).HostName
$whateverlist = Get-Content .\yourlistofservers.txt
# or you can..
$whateverlist = @"
machine1
machine2
machine3
etc
"@
$Scriptblock = {
param($machine);
$pingOk = Test-Connection -cn $machine -BufferSize 16 -Count 1 -EA silentlyContinue
if ($pingOk)
{
# Do whatever if it responds to pinging
# Maybe store the property in a list, put it out to a file etc.
[System.Net.Dns]::GetHostAddresses(“$machine”).IPAddressToString
# Use whatever method you like to get IP of the computer, even use the above output.
# Me being lazy:
$ip = [System.Net.Dns]::GetHostAddresses(“$machine”).IPAddressToString
[System.Net.Dns]::GetHostEntry($ip).HostName
}
}
# Then you can get the job, do whatever. Do it in a foreach for best results.
foreach ($machine in $whateverlist)
{
Start-Job -ScriptBlock $Scriptblock -ArgumentList $machine
}
# To crack open the eggs and get the goodies:
Receive-Job * -Keep | Out-File ".\whatevermanijustworkhere.txt"
ここできれいですコピー:
$whateverlist = Get-Content .\yourlistofservers.txt
$whateverlist = @"
machine1
machine2
machine3
etc
"@
$Scriptblock = {
param($machine);
$pingOk = Test-Connection -cn $machine -BufferSize 16 -Count 1 -EA silentlyContinue
if ($pingOk)
{
$ip = [System.Net.Dns]::GetHostAddresses(“$machine”).IPAddressToString
$ip
[System.Net.Dns]::GetHostEntry($ip).HostName
}
}
foreach ($machine in $whateverlist)
{
Start-Job -ScriptBlock $Scriptblock -ArgumentList $machine
}
Receive-Job * -Keep | Out-File ".\whatevermanijustworkhere.txt"
出典:
https://adsecurity.org/?p=305
アクションをパラレル化するためにInvoke-Parallelを使用します。https://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430 –
@MickyBalladelli 'Invoke-Parallel -scriptfile c:\ work \ reverse.ps1 - inputobject $(get-content c:work \ test.txt)-runspacetimeout 10 -throttle 10 'この行を使ってテストを実行します。 reverse.ps1ファイルのコードは次のようになります: '$ hostname = [System.Net.Dns] :: GetHostEntry($ _)。HostName $ results = @()foreach($ホスト名$ホスト){if($ホスト名が見つかりません "}} $ result | = $ _ +"、 "+ホスト名が見つかりません" out-file c:\ work \ Results.txt'の出力は空白です。ここでどこが間違っているのか分かりますか? –
scriptfileの代わりに '-ScriptBlock'パラメータを使用してみてください。私はそれを使います。 '-ImportVariables'パラメータは、あなたが定義した変数をランスペースにインポートさせるのも面白いです。 –