1

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] => 
)

1 Answer 1

1

I found the fix.

try:

Copy the folders called MSOnline and MSOnline Extended from the source

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\

to the folder

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\

And then in PS run the Import-Module MSOnline, and it will automatically get the module :D

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.