I need help to to execute a command in loop for multiple servers, I have these command I want to run them in a loop for multiple servers<\/p>\n
Invoke-Command -Computer ‘IP’ -ScriptBlock {Remove-Item -Path $args[0] -force } -ArgumentList 'c:\\Folder'<\/p>\n
$Session = New-PSSession -ComputerName “IP” -Credential “user-name”
\nCopy-Item \"C:\\Folder\" -Destination \"C:\" -ToSession $Session<\/p>\n
Also how do I pass the password for the copy command ?
\nAny help is appreciated.<\/p>","upvoteCount":2,"answerCount":38,"datePublished":"2021-02-22T15:13:55.000Z","author":{"@type":"Person","name":"spiceuser-3fkxp","url":"https://community.spiceworks.com/u/spiceuser-3fkxp"},"acceptedAnswer":{"@type":"Answer","text":"
you’d use invoke -command instead and a foreach loop<\/p>\n