powershell workflows empty variables

recently began exploring workflows in order to execute things parallel but have been running into problems. the list with ip’s i want to use always end up empty within the workflow.

here’s the code with no workflow:

$ips = Import-Csv C:UsersAdministratorDocumentstest.csv | Select-Object "ipaddress" foreach ($ip in $ips) { $address = $ip.ipaddress if(Test-Connection -ComputerName $address -Quiet) { Write-Host $address " is reachable" $s = New-PSSession $address -Credential "Admin" Invoke-Command -Session $s -ScriptBlock { Write-Host "Trying to add client to domain" HOSTNAME try { Add-Computer -DomainName "Domain" -LocalCredential admin -Credential Domainadministrator -OUPath "OU=PC's,OU=Devices,DC=Domain,DC=net" -Force -ErrorAction Stop Write-Host "added to domain" } catch { Write-Host "error joining the domain" } finally { $ErrorActionPreference = "Continue" } } Restart-Computer -wait $address -Credential admin -Protocol WSMan } else { Write-Host $address " not reachable" } } 

And here’s my failed try to turn it into a workflow:

$iplist = Import-Csv C:UsersAdministratorDocumentstest.csv | Select-Object "ipaddress" workflow adddomain{ Param($ips) Write-Output $ips foreach -parallel ($ip in $ips) { $address = $ip.ipaddress if(Test-Connection -ComputerName $address -Quiet) { Write-Output $address " is reachable" $s = New-PSSession $address -Credential "Admin" Invoke-Command -Session $s -ScriptBlock { Write-Output "Trying to add client to domain" HOSTNAME try { $ErrorActionPreference = "Stop" Add-Computer -DomainName "Domain" -LocalCredential admin -Credential Domainadministrator -OUPath "OU=PC's,OU=Devices,DC=Domain,DC=net" -Force Write-Host "added to domain" } catch { Write-Output "error joining the domain" } finally { $ErrorActionPreference = "Continue" } } } else { Write-Output $address " not reachable" } } } adddomain -InputObject $iplist 

any1 have any clue what i’m doing wrong here?

submitted by /u/fabiaville
[link] [comments]

Leave a Reply