Powershell import-module webadministration

6

Every time I execute this command

invoke-command -computername REMOTEPC -scriptblock { import-module WebAdministration; new-item "$env:systemdrive\inetpub\testsite" -type directory; New-WebSite -Name TestSite -Port 81 -PhysicalPath "$env:systemdrive\inetpub\testsite" }

I get the following error

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCommand

The website is created successfully as far as I can see.

The following command gives the same error when enumerating the testsite

Invoke-Command -computername REMOTEPC { import-module webadministration; dir -path IIS:\Sites\ }

Name             ID   State     Physical Path     Bindings      PSComputerName
Default Web Site 1    Started                     http *:80:    REMOTEPC

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCo
   mmand

Any suggestions would be appreciated

iis
web-server
powershell
asked on Server Fault Mar 30, 2010 by (unknown user) • edited Mar 30, 2010 by Sam Cogan

2 Answers

4

This is a serialization problem. New-WebSite and top-level WebSite information from the IIS:\Sites\{sitename} protocol both return objects of type Microsoft.IIs.PowerShell.Framework.Configuration. That object contains a property ftpServer; and ftpServer isn't serializable.

New-WebApplication and Sub-WebApplication information from the IIS:\Sites\{siteName}\{subappname} protocol do not have an ftpServer property. They won't have the same serialization error.

@cad's solution is great, because it prevents the remote script from returning any objects.

But, if you want to return the website information from the remote machine, you can use:

$scriptBlock = {
    Import-Module WebAdministration

    $site = Get-Item IIS:\Sites\www.sitename.com

    $site.ftpServer = $null   # this won't affect the real server value

    return $site
}

Invoke-Command -ComputerName REMOTEPC -ScriptBlock $scriptBlock
answered on Server Fault Oct 2, 2014 by smaglio81
3

I had same problem as you. I was in an iteration trying to create 16 sites. First one was being created and had same exception... exiting from iteration and leaving me with only one site created. I didn't fix it, but as a workaround I added

| out-null

at the end of the line. This suppresed output so exception was ignored and my iteration was happily continuing.

Something like:

invoke-command -computername REMOTEPC -scriptblock { import-module WebAdministration; new-item "$env:systemdrive\inetpub\testsite" -type directory; New-WebSite -Name TestSite -Port 81 -PhysicalPath "$env:systemdrive\inetpub\testsite" | out-null}

(Notice that | out-null at the end of the code snippet)

answered on Server Fault Mar 28, 2012 by Oscar Foley

User contributions licensed under CC BY-SA 3.0