Search code examples
powershellremote-accessinvoke-commandwinrm

How to use winrm to send commands from a Domain to a Workgroup (mixed domains) without using credentials


I am trying to run a powershell invoke-command on a vmware image I have: invoke-command -computer [vmware host] -scriptBlock { commands }

This does not work because my client where I run the command is on a domain and the vm image is in a workgroup (mixed domains)

After some research, I have added the vmware host to trusted hosts (Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value [vmware host]) and if I supply credentials (administrator/password) the command works.

My question is: Is there a way to make it work without explicitly supplying the credentials e.g. either opening up the vmware host to all kinds of access or then somehow saving the credentials permanently on my client computer so that I don't need to supply them in a call using the "invoke-command -credential argument". I don't have the flexibility of adding the "-credential" argument as this code is maintained by other team.

I know I could add trust between the domains (to use kerberos) but that option is not available to me.


Solution

  • This is about all you can do. Use PSDefaultParameters.

    http://technet.microsoft.com/en-us/library/hh847819.aspx

    $PSDefaultParameterValues = @{ 
      "Enter-PSSession:Credential" = $cred  
      "Invoke-Command:Credential" = $cred
    }