0
votes

I have follow issue: I trying to run remote command on my server (windows server 2012 r2) via powershell command, powershell script looks follow

$password = ConvertTo-SecureString $pass -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PsCredential($deployadmin,$password)
$scriptBlock1 = {Get-NetAdapter}
Invoke-Command -computername $server -Credential $credentials -scriptblock $scriptBlock1

and I've get an error 'Access is denied'

I've tryied to run on server Enable-PSRemoting for allow remote connection. I use credential for user that is Administrator on that server.

Strange thing, that this command is succeeds for credentials of another user on this server, those user is also Administrator.

What I'm missing ? Thank for any advice

Update:

command Test-WSMan $server is succeeds

try command winrm quickconfigthe system suggested setting up a remote access, after the configuration, the Invoke-Command command was executed without errors

I would be grateful if anyone would explain this behavior

1

1 Answers

0
votes

Fun!

When you execute winrm quickconfig the following happens:

  1. Starts the WinRM service
  2. Set the WinRM service type to auto start
  3. Create a listener to accept requests on any IP address
  4. Enable firewall exception for WS-Management traffic (for http only)

This article has additional detail.