Hi
what I want to achieve here is
connect to the remote computer
execute a bat file which contains the following code
[pre]
PowerShell -Command “Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted” >> “c:\temp\StartupLog.txt” 2>&1
PowerShell c:\users\username\Documents\AdDumpTalent.ps1 >> “c:\temp\StartupLog.txt” 2>&1
[/pre]
showing progress by preference in the console
once finished the output file needs to be copied to my local machine
this is what I have sofar
[pre]
$path =“c:\Temp”
$bat = “copy.bat”
$file =“AdDumpTalent.ps1”
$resultpath =“C:\Temp\Talent”
$destination = “c:\temp\Talent_result”
$cred = Import-Clixml -Path “${env:\userprofile}\paul.Cred”
$session = new-PSSession -ComputerName myserver.com -Credential $cred
$remotejob = Invoke-Command -session $session -ScriptBlock {
“cmd.exe /c $path$bat”
copy-item “$resultpath” -Destination “$destination” -FromSession $session
} -ArgumentList $bat -AsJob $remotejob|wait-job
Remove-PSSession -Session $session
[/pre]
however when I try to run this code I get this error
[pre]
Invoke-Command : A positional parameter cannot be found that accepts argument ‘$null’.
At line:8 char:15
- $remotejob = Invoke-Command -session $session -ScriptBlock {
-
- CategoryInfo : InvalidArgument: ( [Invoke-Command], ParameterBindingException
- FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand
[/pre]
Paul