I'm using Win 7 64 bits, Windows PowerShell 2.0, and VS 2010 , .NET 4.0 and Unit Test project. C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe (32 bits) I use PS Console like this: PS C:\Users\user1> (gwmi win32_process | ? { $_.processname
-eq "powershell.exe" }) | select commandline commandline ----------- "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" Now, I connect to remote machine, Win2008 R2 64 bits: PS C:\Users\user1> Enter-PSSession 'descasiisw01' -Credential:'desiisw01\instalador'
[descasiisw01]: PS C:\Users\instalador\Documents> import-module WebAdministration [descasiisw01]: PS C:\Users\instalador\Documents> Get-WebSite Name ID State Physical Path Bindings ---- -- ----- ------------- -------- Default Web Site 1 Started C:\inetpub\wwwroot
http *:80: net.tcp 808:* net.pipe * net.msmq localhost msmq.formatname localhost http *:80:descasiis --- OMITED --- I test using too PowerShell ISE and works fine. Now, I using C# to call PowerShell scripts: var cmdPS = string.Format("-File \"{0}\" {1} {2}
{3} {4} {5} ", PSTestRemoteDeploy, DeployEnvironment, server, group, firstServer, lastServer); //cmdPowerShell = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Syswow64\WindowsPowerShell\V1.0\powershell.exe"); cmdPowerShell = Path.Combine(Environment.GetEnvironmentVariable("windir"),
@"system32\WindowsPowerShell\v1.0\powershell.exe"); var argumentsPS = "-ExecutionPolicy Unrestricted "; argumentsPS += "-WindowStyle Hidden -NonInteractive -NoLogo "; var startInfo = new ProcessStartInfo(); startInfo.FileName = cmdPowerShell; startInfo.Arguments
= argumentsPS + cmdPS; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; using (var process = new Process()) { process.StartInfo = startInfo; process.Start();
output = process.StandardOutput.ReadToEnd(); errors = process.StandardError.ReadToEnd(); } I have those ps1 files: === testRemote1.ps1 === $serverName = "desiisw01" $username = "desiisw01\installer" $password = "xxx" $adjPwd = $password | ConvertTo-SecureString
-asPlainText -Force $testCred = (New-Object System.Management.Automation.PSCredential($username,$adjPwd)) Invoke-Command -credential $testCred -computer $serverName -scriptblock { Import-Module WebAdministration; Get-Website } # The same error for those: #
dir "IIS:\Sites" # Get-ChildItem IIS:\Sites # the error "Remoting data is missing errorCategory_Category property. # Get-Website | select name,state,ID,physicalpath,bindings and === testRemote2.ps1 === $serverName = "desiisw01" $username = "desiisw01\installer"$password = "xxx" $adjPwd = $password | ConvertTo-SecureString -asPlainText -Force $testCred = (New-Object System.Management.Automation.PSCredential($username,$adjPwd)) Invoke-Command -credential $testCred -computer $serverName -scriptblock { import-module
-Name webadministration foreach ($site in get-website) { write-host $site.physicalpath } foreach ($site in Get-Website) { #PS Values write-host "#PS Values" write-host $site.PSPath write-host $site.PSParentPath write-host $site.PSChildName write-host $site.PSDrive
write-host $site.PSProvider write-host $site.PSIsContainer #Attributes write-host "#Attributes" write-host $site.name write-host $site.id write-host $site.serverAutoStart write-host $site.state #Child Elements write-host "#Child Elements" write-host $site.bindings
write-host $site.limits write-host $site.logFile write-host $site.traceFailedRequestsLogging write-host $site.applicationDefaults write-host $site.virtualDirectoryDefaults write-host $site.ftpServer #Other write-host "#Other" write-host $site.applicationPool
write-host $site.enabledProtocols write-host $site.physicalPath write-host $site.userName write-host $site.password write-host $site.ItemXPath } } I get this error using testRemote1.ps1: The data is invalid. (Exception from HRESULT: 0x8007000D) + CategoryInfo
: NotSpecified: (:) [Get-Website], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Micr osoft.IIs.PowerShell.Provider.GetWebsiteCommand and using testRemote2.ps1 doesn't fail. All works fine!!. How can I avoid "The data is
invalid" error ? may be any problem using any property of an website ? PD: Before I get error, in another tests, I don't know I cannot get it: Get-Website : Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed
due to the following error: 80040154. En D:\TFS\TestResults\user_machine 2012-05-30 16_15_28\Out\Tests.Script1.ps1: 50 Car cter: 12 + Get-WebSite <<<< + CategoryInfo : NotSpecified: (:) [Get-Website], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Micr
osoft.IIs.PowerShell.Provider.GetWebsiteCommand I test using 64-bit PowerShell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 32-bit PowerShell: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe **References** http://learningpcs.blogspot.com.es/2011/08/powershell-x86x64-iis-provider-error.html
Can’t use WebAdministration module when using powershell from c# http://lintaonz.wordpress.com/2011/01/19/cant-use-iis-module-when-using-powershell-from-csharp/ http://www.eighty-twenty.net/weblog/article/149/powershell-x86-fail http://www.techblogistech.com/2012/05/errors-with-powershell-webadministration-module/#more-857
http://stackoverflow.com/questions/3501001/windows-powershell-snap-in-for-iis-fails-on-32-bit