December 4, 2012

WebAdministration CmdLets in remote session error ‘The data is invalid. (Exception from HRESULT: 0x8007000D)’

If you tried to use the WebAdministration Powershell CmdLets in a remote session like this :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site'}

You probably received this error :

The data is invalid. (Exception from HRESULT: 0x8007000D)
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.GetWebsiteCommand
    + PSComputerName        : **********

From what I could found, Powershell encounter an error trying to serialize some members (properties) of the object it’s trying to send you back from the remote session.  There is two workaround.

#1 : Select only the properties you need :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site' | select name,id,state,PhysicalPath}

#2 : Exclude the properties that cause an error :

Invoke-Command -Session $rs -ScriptBlock {get-website 'Default Web Site' | select * -ExcludeProperty Bindings,limits,logfile,tracefailedrequestslogging,applicationdefaults,virtualDirectoryDefaults,ftpserver}

Of course you’ll have to try every property to find the ones that generate an error.

If you want to read a property that generate an error you should get that property in a separate call :

Invoke-Command -Session $rs -ScriptBlock {(get-website 'Default Web Site').limits }

If the property you want  is a collection also try getting it separately with the Collection property :

Invoke-Command -Session $rs -ScriptBlock {(get-website 'Default Web Site').bindings.collection | select * -ExcludeProperty certificateHash,certificateStoreName,isDsMapperEnabled}


Francesco Campanella said...

Thanks for sharing this

sivasankararao bacha said...

Nice information

Anonymous said...

Very nice information, thanks!

Post a Comment