Sen ileriye yönelik aşağıdakileri yapın ve arama ters foreach döngüsünde bir scriptblock içinde tamamlamayı ve Start-İş yapabilirsiniz: Örneğin
$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"
İşte temiz kopya:
$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"
Kaynak:
https://adsecurity.org/?p=305
https://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430 –
@MickyBalladelli 'Invoke-Parallel -scriptfile c: \ work \ reverse.ps1 - işlemleri paralel hale getirmek için Invoke-Paralel'i kullanıyorum inputobject $ (get-content c: iş \ test.txt) -runspacetimeout 10 -throttle 10 'Bu satırı denemek ve test etmek için kullanıyorum. reverse.ps1 dosyasındaki kod şöyledir: '$ hostname = [System.Net.Dns] :: GetHostEntry ($ _). HostName $ results = @() foreach ($ hostname içinde $ host) {if ($) hostname) {$ results + = $ _ + "," + $ hostname} else {results + = $ _ + "," + "Ana Bilgisayar Adı bulunamadı"}} $ sonuç | dosya dışı c: \ work \ Results.txt' çıktı boş. Nerede yanlış gittiğimi görüyor musun? –
Script dosyası yerine '-ScriptBlock' parametresini kullanmayı deneyin, nasıl kullandığımı. '-ImportVariables' parametresi de, runspac'ların tanımladığınız değişkenleri içe aktarmasına izin vermek açısından ilginçtir. –