Using computername within Invoke-command

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.

Thanks,

Cory

%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

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

Best regards
Stig

Edit: Dave beat me to it :slight_smile: