1

I am writing a PowerShell script that reads in a list of hosts from a file. I have tried two separate methods, having issues with both.

First Method:

$WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig }

This gives the following error message on some of the hosts:

WSManFault
    + CategoryInfo          : NotSpecified: (WSManFault:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : svclebetapool01.lehi.micron.com

    Message = Access is denied. 
Error number:  -2147024891 0x80070005
Access is denied. 

Second Method:

$WinRM = C:\PSTools\PsExec.exe \\$server -s winrm.cmd quickconfig -q

This sets $WinRM to the exit code (1 on successful execution). If I redirect the output with > or >>, then it displays the PsExec copyright. I am looking for the exact message that is created by the WinRM quickconfig command so that I know how to handle it in different situations.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Kilik
  • 53
  • 1
  • 5

1 Answers1

0

if your intention is to enable PowerShell remoting, then you can

C:\PSTools\PsExec.exe \\$server PowerShell.exe -c "Enable-PSRemoting -Force"

or

wmic /node:$Server process call create "PowerShell.exe -c 'Enable-PSRemoting -Force'"
Prasoon Karunan V
  • 2,916
  • 2
  • 12
  • 26
  • What I am intending to do is run the winrm quickconfig command on all of the remote servers and return the outcome, whether that be it's already configured, the firewall needs enabled, or whatever other potential outcomes that may arise from it. The script saves a list of servers that I can then go in and configure WinRM if need be. I tried both of the mentioned lines of code above, but am still getting the "Access is denied" error. – Kilik Aug 16 '18 at 17:41
  • Account you are running with should have admin access in the remote machines or if you have the credentials of account with admin privilege you can specify the same using `-u` and `-p` options of `psexec`. – Prasoon Karunan V Aug 18 '18 at 16:01