Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
@David: does the computer you are running the command on have the webadministration module installed and imported? –  MattB Mar 30 '10 at 14:34
    
@MattB: You do not have to have the module loaded locally. As per the ScriptBlock parameter details it, this will be run on the remote computer. –  Marco Shaw Mar 31 '10 at 18:50
    
@Marco Shaw: where I was going with that is - I'm wondering if the remote call is passing back a property with a type from the webadministration module that the calling machine can't parse properly, but since he isn't using that property it doesn't affect his output. (I haven't been able to test this theory yet...) –  MattB Mar 31 '10 at 19:10
add comment

1 Answer

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)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.