i have troubles with running valid powershell script (tested from cmd). I want the script to test if user exists on office 365 but authentication just wont pass via php while it executes normal in cmd.
Server is windows 2008 R2, IIS 7.5, PHP 5.4 NTS.
I'm in general linux user and I have troubles getting this MS thing to work big time so any suggestion is really appreciated.
here is my powershell script:
$username = "adminuser@my_domain"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Import-Module MSOnline -force
Connect-Msolservice -Credential $cred
Get-MsolUser -UserPrincipalName student@my_domain
and php part:
exec("powershell -Command C:/inetpub/wwwroot/office365/test.ps1 < NUL", $output);
echo '<pre>';
print_r ($output);
echo '</pre>';
output result:
Array
(
[0] => Connect-MsolService : Exception of type 'Microsoft.Online.Administration.Automa
[1] => tion.MicrosoftOnlineException' was thrown.
[2] => At C:\inetpub\wwwroot\office365\test.ps1:8 char:20
[3] => + Connect-Msolservice <<<< -Credential $cred
[4] => + CategoryInfo : OperationStopped: (:) [Connect-MsolService], Mic
[5] => rosoftOnlineException
[6] => + FullyQualifiedErrorId : 0x80070002,Microsoft.Online.Administration.Autom
[7] => ation.ConnectMsolService
[8] =>
)