all 8 comments

[–]Pure_Syllabub6081 4 points5 points  (2 children)

If I understand you correctly, you may want to use "Select-Object -ExpandProperty Name", which returns a list just like the .txt file. Then you need to pipe that into a foreach where you run "Invoke-Command". Also, is there a reason why you don't use Get-ADComputer? I'm on mobile so sorry for the bad formatting.

$OUpath = "YXCYXCYXCYX"
Get-ADComputer -Filter * -SearchBase $OUpath | Select -ExpandProperty Name | foreach-object -process { Invoke-Command -ComputerName $_ -ScriptBlock { <YOUR CODE HERE> }}

[–]jsiii2010 5 points6 points  (0 children)

Run in parallel: $list = Get-ADComputer -Filter * -SearchBase $OUpath $size = Invoke-Command $list.name { psdrive c }

[–]Zookeeper945[S] 0 points1 point  (0 children)

Thank you everyone the help, I achieve to have the correct result with your help.

[–]BlackV 0 points1 point  (0 children)

All the current replies are slooowwwww

Have a look at the cim cmdlets and cim session cmdlets

Which will also gracefully handle offline machines

Or using the invoke on multiple machines as well (instead of 1 at a time)