The data is invalid Error using Powershell Remoting and Get-WebSite (WebAdministration Module)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im using Win 7 64 bits, Windows PowerShell 2.0, and VS 2010 , .NET 4.0 and Unit Test project.<br/>
<br/>
C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEdevenv.exe <br/>
(32 bits)<br/>
<br/>
I use PS Console like this:<br/>
<br/>
PS C:Usersuser1> (gwmi win32_process | ? { $_.processname -eq "powershell.exe" }) | select commandline<br/>
<br/>
commandline<br/>
-----------<br/>
"C:WINDOWSsystem32WindowsPowerShellv1.0powershell.exe"<br/>
<br/>
Now, I connect to remote machine, Win2008 R2 64 bits:<br/>
<br/>
PS C:Usersuser1> Enter-PSSession descasiisw01 -Credential:desiisw01instalador<br/>
[descasiisw01]: PS C:UsersinstaladorDocuments> import-module WebAdministration<br/>
[descasiisw01]: PS C:UsersinstaladorDocuments> Get-WebSite<br/>
<br/>
Name ID State Physical Path Bindings<br/>
---- -- ----- ------------- --------<br/>
Default Web Site 1 Started C:inetpubwwwroot http *:80:<br/>
net.tcp 808:*<br/>
net.pipe *<br/>
net.msmq localhost<br/>
msmq.formatname localhost<br/>
http *:80:descasiis<br/>
--- OMITED ---<br/>
<br/>
<br/>
I test using too PowerShell ISE and works fine.<br/>
<br/>
Now, I using C# to call PowerShell scripts:<br/>
<br/>
<br/>
<br/>
var cmdPS = string.Format("-File "{0}" {1} {2} {3} {4} {5} ", PSTestRemoteDeploy, DeployEnvironment, server, group, firstServer, lastServer);<br/>
//cmdPowerShell = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Syswow64WindowsPowerShellV1.0powershell.exe");<br/>
cmdPowerShell = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"system32WindowsPowerShellv1.0powershell.exe");<br/>
<br/>
var argumentsPS = "-ExecutionPolicy Unrestricted ";<br/>
argumentsPS += "-WindowStyle Hidden -NonInteractive -NoLogo ";<br/>
<br/>
var startInfo = new ProcessStartInfo();<br/>
startInfo.FileName = cmdPowerShell;<br/>
startInfo.Arguments = argumentsPS + cmdPS;<br/>
startInfo.RedirectStandardOutput = true;<br/>
startInfo.RedirectStandardError = true;<br/>
startInfo.UseShellExecute = false;<br/>
startInfo.CreateNoWindow = true;<br/>
using (var process = new Process())<br/>
{<br/>
process.StartInfo = startInfo;<br/>
process.Start();<br/>
<br/>
output = process.StandardOutput.ReadToEnd();<br/>
errors = process.StandardError.ReadToEnd();<br/>
}<br/>
<br/>
I have those ps1 files:<br/>
<br/>
=== testRemote1.ps1 ===<br/>
<br/>
$serverName = "desiisw01"<br/>
$username = "desiisw01installer"<br/>
$password = "xxx" <br/>
<br/>
$adjPwd = $password | ConvertTo-SecureString -asPlainText -Force<br/>
$testCred = (New-Object System.Management.Automation.PSCredential($username,$adjPwd)) <br/>
<br/>
Invoke-Command -credential $testCred -computer $serverName -scriptblock { Import-Module WebAdministration; Get-Website }<br/>
<br/>
and<br/>
<br/>
=== testRemote2.ps1 ===<br/>
$serverName = "desiisw01"<br/>
$username = "desiisw01installer"<br/>
$password = "xxx" <br/>
<br/>
$adjPwd = $password | ConvertTo-SecureString -asPlainText -Force<br/>
$testCred = (New-Object System.Management.Automation.PSCredential($username,$adjPwd)) <br/>
<br/>
Invoke-Command -credential $testCred -computer $serverName -scriptblock { <br/>
import-module -Name webadministration<br/>
foreach ($site in get-website) {<br/>
write-host $site.physicalpath<br/>
}<br/>
<br/>
foreach ($site in Get-Website) {<br/>
<span style="white-space:pre #PS Values<br/>
<span style="white-space:pre write-host "#PS Values"<br/>
<span style="white-space:pre write-host $site.PSPath<br/>
<span style="white-space:pre write-host $site.PSParentPath<br/>
<span style="white-space:pre write-host $site.PSChildName<br/>
<span style="white-space:pre write-host $site.PSDrive<br/>
<span style="white-space:pre write-host $site.PSProvider<br/>
<span style="white-space:pre write-host $site.PSIsContainer<br/>
<br/>
<span style="white-space:pre #Attributes<br/>
<span style="white-space:pre write-host "#Attributes"<br/>
<span style="white-space:pre write-host $site.name<br/>
<span style="white-space:pre write-host $site.id<br/>
<span style="white-space:pre write-host $site.serverAutoStart<br/>
<span style="white-space:pre write-host $site.state<br/>
<br/>
<span style="white-space:pre #Child Elements<br/>
<span style="white-space:pre write-host "#Child Elements"<br/>
<span style="white-space:pre write-host $site.bindings<br/>
<span style="white-space:pre write-host $site.limits<br/>
<span style="white-space:pre write-host $site.logFile<br/>
<span style="white-space:pre write-host $site.traceFailedRequestsLogging<br/>
<span style="white-space:pre write-host $site.applicationDefaults<br/>
<span style="white-space:pre write-host $site.virtualDirectoryDefaults<br/>
<span style="white-space:pre write-host $site.ftpServer<br/>
<br/>
<span style="white-space:pre #Other<br/>
<span style="white-space:pre write-host "#Other"<br/>
<span style="white-space:pre write-host $site.applicationPool<br/>
<span style="white-space:pre write-host $site.enabledProtocols<br/>
<span style="white-space:pre write-host $site.physicalPath<br/>
<span style="white-space:pre write-host $site.userName<br/>
<span style="white-space:pre write-host $site.password<br/>
<span style="white-space:pre write-host $site.ItemXPath<br/>
<br/>
<span style="white-space:pre }<br/>
}<br/>
<br/>
I get this error using testRemote1.ps1:<br/>
<br/>
The data is invalid. (Exception from HRESULT: 0x8007000D)<br/>
+ CategoryInfo : NotSpecified: (:) [Get-Website], COMException<br/>
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Micr <br/>
osoft.IIs.PowerShell.Provider.GetWebsiteCommand<br/>
<br/>
and using testRemote2.ps1 doesnt fail. All works fine!!.<br/>
<br/>
How can I avoid "The data is invalid" error ? may be any problem using any property of an website ?<br/>
<br/>
PD: Before I get error, in another tests, I dont know I cannot get it:<br/>
<br/>
<br/>
Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154. <br/>
En D:TFSTestResultsuser_machine 2012-05-30 16_15_28OutTests.Script1.ps1: 50 Car cter: 12 <br/>
+ Get-WebSite <<<< <br/>
+ CategoryInfo : NotSpecified: (:) [Get-Website], COMException<br/>
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Micr osoft.IIs.PowerShell.Provider.GetWebsiteCommand<br/>
<br/>
<br/>
<br/>
I test using <br/>
<br/>
64-bit PowerShell: C:WindowsSystem32WindowsPowerShellv1.0powershell.exe <br/>
32-bit PowerShell: C:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe<br/>
<br/>
**References** <br/>
http://learningpcs.blogspot.com.es/2011/08/powershell-x86x64-iis-provider-error.html<br/>
<br/>
Can’t use WebAdministration module when using powershell from c# <br/>
http://lintaonz.wordpress.com/2011/01/19/cant-use-iis-module-when-using-powershell-from-csharp/<br/>
<br/>
http://www.eighty-twenty.net/weblog/article/149/powershell-x86-fail <br/>
http://www.techblogistech.com/2012/05/errors-with-powershell-webadministration-module/#more-857 <br/>
http://stackoverflow.com/questions/3501001/windows-powershell-snap-in-for-iis-fails-on-32-bit
<h1 style="border:none; font-weight:100; font-family:Segoe UI Light,Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline:0px; padding:0px; font-size:36px; line-height:46px; clear:both; list-style-type:none; color:#707070; height:auto; text-align:left
<br/>
</h1><hr class="sig www.kiquenet.com/profesional

View the full article
 
Back
Top