I'm loading a json file that contains a list of computer names and each of them contains a list of files I need to operate on. For this example, I'm just displaying the file sizes.
But I'm getting file not found errors. I think it's because new-pssession
is not activated or opened. I confirmed the file does exist on the remote computers. Is there something I need to do to "activate/open" the session after new-pssession
?
$cred = Get-Credential -UserName admin -Message "Enter Password"
$computers = Get-Content "sample.json" | ConvertFrom-Json
foreach($computer in $computers){
$s = new-pssession -ComputerName $computer.computer -Credential $cred
foreach($file in $computer.files){
write-host $file has (get-item $file).length "bytes"
}
remove-pssession $s
}
json file
[
{
"computer": "machine1",
"files": [
"c:\\temp\\done.png",
"c:\\temp\\Permissions.xlsx"
]
},
{
"computer": "machine2",
"files": [
"c:\\software\\TortoiseSVN.msi",
"c:\\software\\TortoiseSVN.txt"
]
}
]