我試圖使用PowerShell錯誤的嘗試與PHP和PowerShell
$username = "[email protected]"
$password = "password"
$secure_password = $password | ConvertTo-SecureString -AsPlainText -Force
$credencial = New-Object System.Management.Automation.PSCredential ($username, $secure_password)
Import-Module MSOnline
Connect-MsolService -Credential $credencial
Get-MSolGroup -GroupType DistributionList -SearchString "groupname" | Select DisplayName, EmailAddress, ObjectId | Out-String
和PHP連接到MSOL服務:
$command = 'powershell -File "'.dirname(__DIR__).'\\ps\\run.ps1"';
exec($command, $output);
print_r($output);
從本地PC PowerShell腳本運行不任何錯誤,但與PHP它會拋出一個錯誤:
Array
(
[0] => Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineEx
[1] => ception' was thrown.
[2] => + CategoryInfo : OperationStopped: (:) [Connect-MsolService], Mic
[3] => rosoftOnlineException
[4] => + FullyQualifiedErrorId : 0x80090345,Microsoft.Online.Administration.Autom
[5] => ation.ConnectMsolService
[6] => + PSComputerName : s021
[7] =>
[8] => You must call the Connect-MsolService cmdlet before calling any other cmdlets.
[9] => + CategoryInfo : OperationStopped: (:) [Get-MsolGroup], Microsoft
[10] => OnlineException
[11] => + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.Micro
[12] => softOnlineException,Microsoft.Online.Administration.Automation.GetGroup
[13] => + PSComputerName : s021
[14] =>
[15] =>
)
但在PowerShell腳本存在命令連接,MsolService。此異常由另一個命令「Get-MsolGroup」引發。 「Connect-MsolService」只拋出未知的異常,沒有任何詳細信息,出現了什麼問題:引發了Microsoft.Online.Administration.Automation.MicrosoftOnlineException類型的異常。 – VaidasV
@VaidasV是在同一個powershell會話中執行的這兩個命令嗎? – Matt
這些命令在相同的powershell腳本中執行,所以我認爲在同一個會話中。 – VaidasV