Forum Discussion
Connect Office365 PowerShell using Service Account
If you use Set-AzureADUser, then you need to connect to AzureAD not Exchange.
Then you can use Azure Automation, here you have a credential manager to store the account you use to connect.
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
- ArjanCornelissenMar 24, 2019Brass Contributor
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.
- donnuwanApr 05, 2019Copper Contributor
ArjanCornelissen Thanks for pointing me in the right direction. I started reading on this avenue and will try to implement this.
- ArjanCornelissenApr 05, 2019Brass Contributor
donnuwanIf you need any help, contact me privately and I might help you 1 on 1