views:

46

answers:

1

I am getting the same error described here:

http://forums.iis.net/p/1033115/1700749.aspx

I have a PowerShell cmdlet that tries to control our web application running on Windows Server 2008 SP2 and IIS 7. One of the first things it tries to do is try to connect to the remote machine using WMI. It does this using code like this:

ConnectionOptions connection = new ConnectionOptions();
connection.Authentication = AuthenticationLevel.PacketPrivacy;
this.iisScope = new ManagementScope(@"\\" + this.Name + @"\root\WebAdministration", connection);
this.iisScope.Connect();

this.Name is the server name. This code always works (does not throw an exception), but on the remote machine I get this error in the Windows Event Logs:

Access to the root\WebAdministration namespace was denied because the namespace is marked with RequiresEncryption but the script or application attempted to connect to this namespace with an authentication level below Pkt_Privacy. Change the authentication level to Pkt_Privacy and run the script or application again.

But as the cmdlet goes on, it does some queries using this.iisScope and they all succeed, and that error is never seen again. I have a guess as to what is going on, but I’m not sure how to prove it. I think that it is trying to connect without the Packet Privacy, failing, and then trying to use Packet Privacy. I tried to sniff the packets with Wireshark, but that didn’t tell me anything useful.

A: 

See code in this article: http://learn.iis.net/page.aspx/160/writing-powershell-commandlets-for-iis-70/. You could also install PowerShell v2 and use get-wmiobject etc. -- they fixed those cmdlets in this release and now you could connect to providers that require encrypted connection, like IIS WMI provider.

Sergei Antonov