I have two separate forests not joined via a trust relationship. Both forests use the same WSUS server for patch management. I am creating a script that queries the WSUS database for the different target groups so that I can use the PSWINDOWSUPDATE module to target specific patch groups. The WSUS server is domain joined to one of the forests. From the untrusted forest, I want to connect to the WSUS server to query the target group. I cant figure out how to specify alternate credential with the [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer .net class. So I used new-pssession with secure cred to connect to the server and run the query. This creates the variable on the WSUS server itself rather than where I am running the script. I want to put the target computers obtained by the pssession to the wsus server in a variable within the script to use when I invoke-windowsupdate from the module. Since the pssession is where the query originated, how can I get the returned results into a variable within the script?
It is in early stages and a rough draft now, but I am pasting the relevant portion of the code below.
$wsuscred = Get-Credential new-pssession -ComputerName wsusserver.domain.com -Credential $wsuscred -Name wsusconnect $computers = @() [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("wsusserver.domain.com",$true, 8531) $Group1 = $wsus.GetComputerTargetGroups() | where {$_.Name -eq "Patch group 1"} $computers+= $Group1.getcomputertargets().fulldomainname $computers remove-pssession -session wsusconnect