1

So I'm using a powershell script to build a Json file to make sure all the Versions of software are up to date across all domains sites (Several different Data centers that use different domain names. I have a special vpn that has trusts to all the domains so from my laptop I am able to access all the Domains without issue.

I at first thought it was a credential issue so i remove that portion but it seems to be network level and I'm not sure why as I can RDP, browse to the network paths, etc.

Connecting to remote server servera failed with the following error message : WinRM cannot process the request. The following error occurred while using Kerberos authentication: Cannot find the computer servera. Verify that the computer exists on the network and that the name provided is spelled correctly. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (servera:String) [], PSRemotingTransportException + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken

[CmdletBinding()]
Param (
    [Parameter(ValueFromPipeline = $true,
        ValueFromPipelinebyPropertyName = $true)]
    [Alias("Servers")]
    [string[]]$Name = (Get-Content "c:\versioncheck\servers.txt"),  
    [string]$Credential = "svcStatusCheck",
    [string]$PathToCred = "c:\versioncheck"
)
Begin {
    Function Get-Credentials {
        Param (
            [String]$AuthUser = $env:USERNAME
        )
        $Key = [byte]29, 36, 18, 74, 72, 75, 85, 52, 73, 44, 0, 21, 98, 76, 99, 28


        $CredFile = $AuthUser.Replace("\", "~")
        $File = $PathToCred + "\Credentials-$CredFile.crd"

        If (-not (Test-Path $File)) {
            (Get-Credential $AuthUser).Password | ConvertFrom-SecureString -Key $Key | Set-Content $File
        }

        $Password = Get-Content $File | ConvertTo-SecureString -Key $Key
        $AuthUser = (Split-Path $File -Leaf).Substring(12).Replace("~", "\")
        $AuthUser = $AuthUser.Substring(0, $AuthUser.Length - 4)
        $Credential = New-Object System.Management.Automation.PsCredential($AuthUser, $Password)
        Return $Credential
    }
}
Process {

    $AllServers = @()

    ForEach ($Computer in $Name) {
        $AllServers += $Computer
    }
}

End {
    ForEach ($Computer in $AllServers) {
        Write-Host "$(Get-Date): Script begins!"

        write-host "Checking $computer"
        Invoke-Command -cn $computer -credential $Credential -ScriptBlock { Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object @{Label = "ServerName"; Expression = {$env:computername}}, DisplayName, Publisher, DisplayVersion,InstallDate | Where-object { $_.Publisher -match "Software" } | ConvertTo-Json -depth 100 | Out-File "c:\versioncheck\InstalledApps.json"}
    } 
}
Ericrs
  • 29
  • 6
  • Perhaps this is related: https://stackoverflow.com/a/30747948/45375 – mklement0 Sep 04 '17 at 03:14
  • A few asides: `[byte]29, 36, 18, 74, 72, 75, 85, 52, 73, 44, 0, 21, 98, 76, 99, 28` doesn't create a `[byte[]]` array - use `[byte[]] (29, 36, ...)`. Your `process` block doesn't work as intended with pipeline input - put `$AllServers = @()` in your `begin` block, and use `$AllServers += $Name` in your `process` block. – mklement0 Sep 04 '17 at 03:17
  • Also: It is best to [avoid `Write-Host`](http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/). – mklement0 Sep 04 '17 at 03:18

1 Answers1

0

You need to enable psremoting on the remote computers receiving the commands using the enable-psremoting cmdlet. This cmdlet prepares a machine to receive Windows Powershell commands sent from WS-MAN

Enable-PSRemoting

Itchydon
  • 2,572
  • 6
  • 19
  • 33
  • all have psremoting enabled. I run other scripts off them to check for disk space, cpu, memory, etc. – Ericrs Sep 02 '17 at 00:30