Author Posts

March 8, 2016 at 1:32 pm

Invoke-Command -Command {robocopy C:\Users \\Server\share\Backup\%computername%\Users /E /ZB} -ComputerName (Get-Content C:\Scripts\Computers.txt) -AsJob -Credential $cred -Authentication CredSSP

This creates a folder called %computername% instead of a folder for each computer. How do I correct this and where should I be looking to find this answer? I'm usually pretty good at finding the answer, usually in the PS help, but not sure where to start on this one.



March 8, 2016 at 1:36 pm

%computername% is the old DOS way of getting at environment variables. In PowerShell, it's $env:computername

Invoke-Command -Command {robocopy C:\Users \\Server\share\Backup\$env:computername\Users /E /ZB} -ComputerName (Get-Content C:\Scripts\Computers.txt) -AsJob -Credential $cred -Authentication CredSSP

March 8, 2016 at 1:37 pm

Powershell doesn't understand every command that Cmd does.
Try to exchange your %computername% with $env:COMPUTERNAME

Best regards

Edit: Dave beat me to it 🙂