can't start script remotely

hello guys, i have followed all the steps in this link http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/

to run my script remotely using Invoke-Command -ComputerName 192.168.8.134 -credential Administrator -ScriptBlock {& "c:\update\run.bat"} 

$Turl1 = "http://localhost/Vscripts/" 
$Turl2 = "http://localhost/Vscripts/versions.txt"

$TtempFile1 = "$(Get-Location)\temp1.tmp"
$TtempFile2 = "$(Get-Location)\temp2.tmp"

$TscriptsLocation = "$(Get-Location)\"
$autoConfigFile   = Join-Path $TscriptsLocation "\config\auto_config.xml"

$autoEnable     = $true


if ((test-path $autoConfigFile) -and $autoEnable){
    $auto_configs = [xml] (gc $autoConfigFile)
    $auto_var = $auto_configs.auto_config.config.obj

    $auto_var | % {
        if (-not $autoEnable){$autoValue = $false} else {$autoValue = $_.value}
        Set-Variable -name $_.name -value $autoValue
    }

    $auto_App_list = @{
        'a'   = $XML_auto_a_folder
        'b'  = $XML_auto_b_folder
        'c' = $XML_auto_v_folder
    }
}

 . .\sbin\start.ps1

but i am still getting this error message 

. : The term '.\sbin\start.ps1' is not recognized as the name of a cmdlet, 
    + CategoryInfo          : NotSpecified: (. : The term '....e of a cmdlet, :String) [], RemoteExceptio 
   n
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : 192.168.8.134
 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:\update\run.ps1:35 char:3
+ . .\sbin\start.ps1
+   ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\sbin\start.ps1:String) [], Co 
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
NotSpecified: (:) [], RemoteException
by the way when using  Enter-PSSession and then run the script from there everything works fine



  • Edited by Vagharsh 20 hours 38 minutes ago
July 13th, 2015 6:29am

Hi Vagharsh,

I can see two dots at the end, ..\sbin\start.ps1 Please remove one dot ( and i am assuming you are in the current directory).

Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 6:42am

now i got this error
.\sbin\start.ps1 : The term '.\sbin\start.ps1' is not recognized as the name 
    + CategoryInfo          : NotSpecified: (.\sbin\start.ps...ed as the name :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : 192.168.8.134
 
of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try 
again.
At C:\update\run.ps1:35 char:1
+ .\sbin\start.ps1
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\sbin\start.ps1:String) [], Co 
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
NotSpecified: (:) [], RemoteException

July 13th, 2015 6:47am

Remove the line ..\sbin\start.ps1 from the powershell script.



Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 7:19am

i have other several ps1 s in my scripts that i load them on the road . i am including those scripts when i need them 
July 13th, 2015 7:23am

and now another one. 
The term '.\sbin\start.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (.\sbin\start.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : 192.168.8.134

Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 7:36am

Comment the line 

#..\sbin\start.ps1

in the powershell script. 

Put  "Powershell.exe  -File <filePath to your run.bat>" in your batch file. Then invoke your command.

Invoke-Command -ComputerName 192.168.8.134 -credential Administrator -ScriptBlock {& "c:\update\run.bat"} 

This should work .


July 13th, 2015 7:43am

it would be total look the way you are saying. i am running this script from my machine 
Invoke-Command -ComputerName 192.168.8.134 -credential Administrator -ScriptBlock {& "c:\update\run.ps1"} 
on the remote machine i have removed the bat file and still the same error 
The term '.\sbin\start.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (.\sbin\start.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : 192.168.8.134
i think it is not able to include those Powershell files i don't know why . 
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 7:56am

Since you are running the invoke-Command from your machine, I assume the ps1 is there on your machine itself. The batch file tries to find the file in remote machines but is unsuccessful, since the file is not there at all. Placing the ps1 file on remote machine will make it work, but it defeats the whole purpose of remoting. I would recommend you to use PSSession.
July 13th, 2015 8:06am

all the files are on the remote machine .. i have used the pssession and it works but i need fully automation ..
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 8:09am

Replied from Slack...

Try this:

invoke-command -computername 'whatever' {$pwd}

That will return the directory you are working in on the remote system. You will need to do Set-Location in your script, before you call the sbin\start.ps1 script.

Alternatively, you can dot source the full path:

. "C:\Path\To\sbin\start.ps1"

Cheers!


July 13th, 2015 8:28am

Use FilePath parameter instead of ScriptBlock .

invoke-command -comp 192.168.8.134 -filepath c:\update\run.ps1

This will result Invoke-Command cmdlet to run the "run.ps1" on the computer listed in comp parameter.The command uses the FilePath parameter to specify the script file. This command allows you to run the script on the remote computers.

Note: Keep the PS1 file in the designated location on your machine.
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2015 8:35am

i had the add the location of the script manually in the script, then set-location to that  and everything worked very good, i was just wondering that isn't there a way to set the location in an dynamic way so that if i move the script location it gets it automatically.  ?
July 13th, 2015 8:46am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics