Powershell script "completed" but not doing anything

Copper Contributor

Hi,

I am trying to run Powershell scripts from Flow, using this guide: https://practical365.com/microsoft-365/how-to-run-powershell-scripts-to-automate-manual-processes-in...

 

During testing, I run the runbook from the automation account (that is, I do not run the Flow, but just the Powershell commands)

 

I have run into some issues:

  • The runbook is "completed" but the actions are not performed - nothing simply happens.
  • The runbook is completed no matter what credentials I enter, and even if I delete the credentials completely, and even if I use a fake user ID for the Employee parameter. 

The Powershell commands I want to run are these (with the actual e-mail addresses, of course)). Are there errors?

 

Param (
[string] $Employee = ""
)
$credObject = Get-AutomationPSCredential -Name "ScriptServiceAccount"
Connect-AzureAD -Credential $credObject
$User = Get-AzureADUser -ObjectId $Employee
Set-AzureADUser -ObjectId
Add-MailboxPermission <shared mailbox e-mail address> -User $Employee -AccessRights FullAccess -InheritanceType all

 and

Param (
[string] $Employee = ""
)
$credObject = Get-AutomationPSCredential -Name "ScriptServiceAccount"
Connect-AzureAD -Credential $credObject
$User = Get-AzureADUser -ObjectId $Employee
Set-AzureADUser -ObjectId
Add-UnifiedGroupLinks -Identity <O365 group e-mail address or id> -LinkType Members -Links $Employee
Add-UnifiedGroupLinks -Identity <O365 group e-mail address or id> -LinkType Owners -Links $Employee

 

The runbook is completed, but the employee is not added as a member/owner of the group and does not get access to the shared mailbox.

 

dfgdsfgdsf.pngNamnlös.png

4 Replies

No one got an idea? 

I could really need some help.

@MrMrkn 

 

I was having same issue because I created the runbook as Powershell type but using a workflow block, so it just ignores the code. Creating the runbook again with type Powershell Workflow worked.

@kengp Oh, nice, thanks! I haven't given this any more thought since öast post, but now I think I'll give it another try!

@MrMrkn Glad to help. I used this tutorial and was successful setting up my automation: https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual

 

It is now recommended to use user assigned identities for logging in to Azure, rather than credentials.