Forum Discussion
Connect Office365 PowerShell using Service Account
ArjanCornelissen Thank you for your response and sorry for the late reply. Thanks for pointing me in the right direction. I tried to find documentation to accomplish this task and could not find anything fulfil this task. If you can give a few simple steps to achieve this would be highly appreciated.
Thanks
Don
donnuwanto use the command "Set-AzureADUser -ObjectID <sign-in name of the user account> -AccountEnabled $false"
You should first use the command "Connect-AzureAD -Credential $O365Creds"
So if you use Azure Automation you can create a new "Automation Account". In there you can go to Credentials under Shared Resources.
The name you give the credential you can use in a runbook by calling
$O365Cred = Get-AutomationPSCredential -Name "<your credentials name>"
So the complete script can be something like this
param(
[Parameter(Mandatory=$true)]
[guid]
$UserObjectId
)
$O365Cred = Get-AutomationPSCredential -Name "AzureADAdminCred"
Connect-AzureAD -Credential $O365Creds
Set-AzureADUser -ObjectID $UserObjectId -AccountEnabled $false
Then you can run this runbook and then you are asked to give the ObjectId of the user to run it.
Hope this helps.