Running WinRM quickconfig for remote servers

0

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.

powershell-remoting
psexec
invoke-command
winrm
asked on Stack Overflow Aug 15, 2018 by Skyler • edited Aug 15, 2018 by Ansgar Wiechers

1 Answer

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'"
answered on Stack Overflow Aug 15, 2018 by Prasoon Karunan V

User contributions licensed under CC BY-SA 3.0