11

I created a Windows VM on Windows Azure with winrm over SSL set.

But, I can't connect it using a powershell script.

When I'm running the following:

​Enter-PSSession -ConnectionUri https://myniceapp.cloudapp.net:5986 
                -Credential "hostname/username"  
                -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)

I'm getting a prompt asking for password and after I type it I manage to connect.

But, when I try to automate it, it always returns with "Access is denied"

$securePassword = ConvertTo-SecureString -AsPlainText -Force "password"
$cred = New-Object System.Management.Automation.PSCredential "hostname/username", $securePassword 
​Enter-PSSession -ConnectionUri https://myniceapp.cloudapp.net:5986 -Credential $mycreds -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)

Any ideas?

Edit

The full error looks like this:

Enter-PSSession : Connecting to remote server myniceaspp.cloudapp.net failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.

At line:1 char:1
+ Enter-PSSession -ConnectionUri https://myniceaspp.cloudapp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (https:// myniceaspp...udapp.net:5986/:Uri) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
  • 1
    could be the case where the user you use is a machine admin but not a domain admin. – Aravind Mar 27 '14 at 12:42
  • @Aravind doesn't that mean I shouldn't be able to connect using the prompt either? – Guy Korland Mar 27 '14 at 13:06
  • hmm. That was the scenario I had this issue. depends on whether this VM is part of a domain(AD). If it is just one VM the above case is not applicable. I had got this working http://michaelwasham.com/windows-azure-powershell-reference-guide/introduction-remote-powershell-with-windows-azure/ – Aravind Mar 27 '14 at 16:44
  • For one, you switch between using `$cred` and `$mycreds` -- that won't work. -- But also your syntax is wrong -- it should be this: `$securePassword = ("securePassword" | ConvertTo-SecureString -AsPlainText -Force);` and then the next line to `$mycreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "userName", $securePassword;` – BrainSlugs83 Jun 04 '18 at 04:47

1 Answers1

20

Had similar problems recently. Would suggest you carefully check if the user you're connecting with has proper authorizations on the remote machine.

You can review permissions using the following command.

Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell

Found this tip here:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/17/configure-remote-security-settings-for-windows-powershell.aspx

It fixed it for me.

Olivier Boudry
  • 801
  • 7
  • 17
  • 2
    This is the identical issue we had when using an explicit AD group (*e.g. "mydomain\Server Admins"*) for server Administrator permissions.The only workaround is to explicitly add the user to the `Microsoft.Powershell` PS session configuration.The other workaround is to make the user an explicit local admin. **PSSession** doesn't seem to traverse user groups all the way down when group inheritance is being used.. – SliverNinja - MSFT Jul 20 '15 at 19:27