heres what i have so far
$computername = 'PC-123456'
$user = 'JDoe'
Invoke-Command $computername {
mkdir "\\flileShare\users$\$user\BKUP" -Force
Move-item 'c:\MyFive9.reg' -Destination "\\flileShare\users$\$user\BKUP"
} -Auth CredSSP -Cred $cred
im looking to pass $user within the Invoke-Command script block
You pass arguments via the ArgumentList parameter:
$computername = 'PC-123456'
$user = 'JDoe'
Invoke-Command $computername {
$user = $args[0]
mkdir "\\flileShare\users$\$user\BKUP" -Force
Move-item 'c:\MyFive9.reg' -Desination "\\flileShare\users$\$user\BKUP"
} -Auth CredSSP -Cred $cred -ArgumentList $user
The script block also allows you to specify named parameters, so you can do this, too:
$computername = 'PC-123456'
$user = 'JDoe'
Invoke-Command $computername {
param(
$user
)
mkdir "\\flileShare\users$\$user\BKUP" -Force
Move-item 'c:\MyFive9.reg' -Desination "\\flileShare\users$\$user\BKUP"
} -Auth CredSSP -Cred $cred -ArgumentList $user
donj
3
You can also use $using:user in v3+.
Thanks Guys got it working with your help