2013-09-23 64 views
8

我需要幫助,解決一直在試圖解決一週的問題。PowerShell腳本在IIS執行中不會返回任何內容

我有一個PowerShell腳本,從Office365環境返回一個列表os用戶。

如果我從我的PowerShell控制檯(我的機器)運行腳本,該腳本將返回預期的數據。 如果我從服務器(W2008 R2 SP1)PowerShell控制檯運行腳本,該腳本將返回預期的數據。 如果我在我的機器上調試我的C#WebService代碼(從腳本執行位置),則srcipt將返回預期的數據。

問題:如果我調用託管到服務器中的WebService,腳本將返回NOTHING。

代碼:

RunspaceConfiguration runspcConfig = RunspaceConfiguration.Create(); 
Runspace run = RunspaceFactory.CreateRunspace(runspcConfig); 
run.ApartmentState = System.Threading.ApartmentState.STA; 
run.ThreadOptions = PSThreadOptions.UseCurrentThread; 
run.Open(); 
Pipeline pipeline = run.CreatePipeline(); 
Command cmd = new Command("PathScript.ps1"); 
cmd.Parameters.Add(new CommandParameter("DOMAIN", "domain.onmicrosoft.com")); 
cmd.Parameters.Add(new CommandParameter("PRODUCT", "productReference")); 
pipeline.Commands.Add(cmd); 
Collection<PSObject> users=pipeline.Invoke(); 

終於找到了錯誤: 爲 'Microsoft.Online.Administration.Automation.ConnectMsolService' 的類型初始值引發異常。

用戶和密碼正確,IUSR和「ApplicationPool用戶」包含在Administrator組中。

任何想法?

+2

如果你想與你的代碼,你首先需要證明你的代碼幫助。 –

+0

這裏是代碼: – user2806842

+0

@ user2806842回答你自己的問題是可以的。 –

回答

1

通過OP,

Problem solved: "Load User Profile" to true in IIS application pool advanced settings

相關問題