Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

invoke command on remote machine is not working using powershell

I ran the below commands on my machine to download data from one server to another server using the invoke command

Enable-PSRemoting -force 

Enter-PSSession Server1

invoke-command -computername Server1 -credential:'domjack' {c:emp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}

ERROR is: Failed: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

but when i run the above command on my machine as

c:emp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true

it works as expected.

Is there something i am missing when i execute it remotely....please help me.

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this good References:
http://www.ravichaganti.com/blog/?p=1108
http://technet.microsoft.com/en-us/magazine/ff700227.aspx

It might be something to do with the TrustedHosts or Authentication setting of a client. You can set it like this:WinRM set winrm/config/client @{TrustedHosts="*"}

Read more about this here: http://blogs.dirteam.com/blogs/sanderberkouwer/archive/2008/02/23/remotely-managing-your-server-core-using-winrm-and-winrs.aspx

I use

powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -NoLogo

I use this code:

try
{

    Invoke-Command -credential $testCred -computer $ServerName -scriptblock { 
        param([String]$scriptDeploy, [String]$destino)  &"$scriptDeploy" 'parametro1' $destino
        $ScriptBlockOutput = $Error
    } -ArgumentList $RutaRemotaParaScriptDeInstalacion, "$dirRemotoDestino" 

    "`r`n`r`nOK para script de despliegue"
    exit 0;

}
catch
{
    "`r`n`r`nError en script de despliegue"
    "`r`nError in " + $_.InvocationInfo.ScriptName + " at line: " + $_.InvocationInfo.ScriptLineNumber + ", offset: " + $_.InvocationInfo.OffsetInLine + ".";

    exit -1
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...