1
votes

I am trying to retrieve a registry value from each computer using a for each loop and then output that value to a folder in a csv. That part works fine. The part I am having an issue with is having powershell connect to the remote computers.

This is running internal only I have admin rights across all workstations Firewalls are configured to allow all traffic to pass

When I run this script I get this error for every workstation it tried to connect to:

Enter-PSSession : Connecting to remote server workstationX failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic. At C:\Users\Rich_Ellis\Desktop\O365\O365Channels\O365Channel.ps1:5 char:2 + {Enter-PSSession -ComputerName $Computer + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (workstationX:String) [Enter-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

My script is:

$Computers = Get-Content "C:\Users\Rich_Ellis\Desktop\O365\O365Channels\computers.txt"

    foreach ($Computer in $Computers)

{Enter-PSSession -ComputerName $Computer 

$key = 'HKLM:\SOFTWARE\Microsoft\Office\CLickToRun\Configuration'
(Get-ItemProperty -Path $key -Name CDNBaseUrl).CDNBaseUrl | Export-CSV -path "\\s00itstorage\OfficeChannel\$($env:COMPUTERNAME)-O365Channel03292018.csv"}

Any help would be appreciated. TIA

1
The error pretty much tells you what to check. Did you check those things?EBGreen

1 Answers

0
votes

Molding a previous answer to your use-case:

$HKEY_LOCAL_MACHINE = 2147483650
$GwmiArgs = @{
    Class     = 'StdRegProv'
    Namespace = 'Root\Default'
    List      = $True
}

ForEach ($Computer in @(Get-Content -Path 'C:\Users\Rich_Ellis\Desktop\O365\O365Channels\computers.txt'))
{
    $GwmiArgs['ComputerName'] = $Computer
    $Registry = Get-WmiObject @GwmiArgs
    $Registry.GetStringValue(
        $HKEY_LOCAL_MACHINE,
        'SOFTWARE\Microsoft\Office\ClickToRun\Configuration',
        'CDNBaseUrl'
    ).sValue | Export-CSV -Path "\\s00itstorage\OfficeChannel\$Computer-O365Channel03292018.csv"
}

This uses wmi instead of psremoting to poll the information which may be easier to rely on as it is already configured/enabled on most PCs and can utilize IP addresses due to DCOM/RPC (psremoting only supports kerberos by default)

This solution can be further improved by using Invoke-WmiMethod instead of creating a wmi object for each poll, but I haven't done the work already for that!