Cant connect to server using v2.1.1 unless I first connect with v1

May 1, 2013 at 7:29 PM
I can't establish a connection with PoshWSUS 2.1.1 to my WSUS server unless I first connect with Posh v1. I'd like to avoid the need to have to import the v1 module and connection with v1 each time. Do you have any idea why this might be happening? Any dependancy on WSUS 3.0 SP2, as this WSUS server is still on SP1 (ya I know, unsupported by MS).

You'll see below that I import the v2 module, fail to connect, then import v1 module, fail to connect from the v2 folder, go back to v1 folder, connect sucessfully, then go back to v2 folder and connect successfully.

PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> import-module .\PoshWSUS.psm1
            PoshWSUS 2.1.1

Make initial connection to WSUS Server: Connect-PoshWSUSServer
Disconnect from WSUS Server: Disconnect-PoshWSUSServer
List all available commands: Get-PoshWSUSCommand


PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> Connect-PoshWSUSServer -WsusServer WSUSSERVER1
WARNING: Unable to connect to WSUSSERVER1!
PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> cd C:\PoshWSUS\PoshWSUS-v-1
PS C:\PoshWSUS\PoshWSUS-v-1> Import-Module .\poshWSUS.psm1
            PoshWSUS 1.1

Make initial connection to WSUS Server: Connect-WSUSServer
Disconnect from WSUS Server: Disconnect-WSUSServer
List all available commands: Get-WSUSCommands


PS C:\PoshWSUS\PoshWSUS-v-1> cd C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1
PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> Connect-PoshWSUSServer -WsusServer WSUSSERVER1
WARNING: Unable to connect to WSUSSERVER1!
PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> cd C:\PoshWSUS\PoshWSUS-v-1
PS C:\PoshWSUS\PoshWSUS-v-1> Connect-WSUSServer -WsusServer WSUSSERVER1
Attempting connection to WSUS Server: WSUSSERVER1

Name Version PortNumber

WSUSSERVER1 3.1.6001.65 80


PS C:\PoshWSUS\PoshWSUS-v-1> cd C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1
PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1> Connect-PoshWSUSServer -WsusServer WSUSSERVER1


WebServiceUrl : http://WSUSSERVER1:80/ApiRemoting30/WebService.asmx
BypassApiRemoting : False
IsServerLocal : False
Name : WSUSSERVER1
Version : 3.1.6001.65
IsConnectionSecureForApiRemoting : False
PortNumber : 80
PreferredCulture : en
ServerName : WSUSSERVER1
ServerProtocolVersion : 1.6



PS C:\PoshWSUS\PoshWSUS_2_1_1\PoshWSUS_2_1_1>
May 3, 2013 at 3:29 AM
The author appears to have left out loading the UpdateServices assemblies in PoshWSUS 2.1.1 .

You can add the below line to the PoshWSUS.psm1 file, and that should take care of your problem.

[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
May 3, 2013 at 6:34 AM
Launch :
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -ImportSystemModules
Coordinator
May 3, 2013 at 12:41 PM
I see the issue. You are importing the module using the .psm1 file instead of the maniest file (.psd1). I am using a manifest file (recommended practice for modules) which auto-loads the assemblies required as well as the existing .psm1 file. If you put the PoshWSUS folder on your user module path C:\users\<username>\documents\WindowsPowerShell\Modules, it then becomes available to import using Import-Module PoshWSUS and it will then use the .psd1 file to find and load all of the required pieces to use the module. You can also verify that it is visible by using Get-Module -ListAvailable

The reason I took out the loading of all of the assemblies from the .psm1 file is because it will attempt to load the assemblies twice, resulting in an error being reported that the files were already loaded.

If you have any more questions, please let me know!

Hope this helps...

Boe
May 3, 2013 at 11:32 PM
Edited May 3, 2013 at 11:32 PM
All is good now!

I copied the "PoshWSUS" folder to c:\documents and settings\<MyUserID>\My Documents\WindowsPowerShell\Modules
then:

PS C:\Temp> get-module -ListAvailable

ModuleType Name ExportedCommands

Manifest PoshWSUS {}
Manifest BitsTransfer {}

PS C:\Temp> import-module PoshWSUS
            PoshWSUS 2.1.1
Make initial connection to WSUS Server: Connect-PoshWSUSServer
Disconnect from WSUS Server: Disconnect-PoshWSUSServer
List all available commands: Get-PoshWSUSCommand

PS C:\Temp> Connect-PoshWSUSServer WSUSSERVER1

Name Version PortNumber ServerProtocolVersion

WSUSSERVER1 3.1.6001.65 80 1.6

PS C:\Temp>

Thanks again for your help!
Jun 5, 2013 at 2:38 PM
Hi, I tried to use PoshWSUS but I have the same pb : unable to connect
I imported the .psm1 correctly (I think) but impossible to connect to my WSUS server.
Could you help me ?
THX in advance