Parity123
asked on
Powershell : Remoting
Hello Experts,
How would I capture the output of running a remote command locally on my machine. I need to capture the output to a file locally on my machine. The output should be Computername, result. (There should be only 1 folder.)
$computers = gc c:\computers.txt
foreach ($computer in $computers) {
Invoke-Command -Computername $computer - ScriptBlock { Get-ChildItem "c:\appoutput"}
}
Thanks for your assistance,
How would I capture the output of running a remote command locally on my machine. I need to capture the output to a file locally on my machine. The output should be Computername, result. (There should be only 1 folder.)
$computers = gc c:\computers.txt
foreach ($computer in $computers) {
Invoke-Command -Computername $computer - ScriptBlock { Get-ChildItem "c:\appoutput"}
}
Thanks for your assistance,
ASKER
I want to save the results to a file locally.
ASKER
If I want to do something for each machine within the script block { if exist c:\appout\123.bin $existentry = "yes", output to local file $computer, $existentry }
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
Thanks
In general I'd recommend something like this.
Open in new window
or make use of fan-out remoting (running on multiple remote machines at once)
Open in new window
When you run a command against a remote machine like above, the returned object has a "PsComputerName" property with the value being the name of the computer it was returned from.
You could pipe either of the above commands to a Select statement to choose specific properties and output to a file. If you wanted to save to a variable you could just preface the Invoke-Command line with "$variable = ".