Forum Discussion

MrMrkn's avatar
MrMrkn
Copper Contributor
Mar 26, 2020

Powershell script "completed" but not doing anything

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.

 

  • MrMrkn's avatar
    MrMrkn
    Copper Contributor

    No one got an idea? 

    I could really need some help.

    • kengp's avatar
      kengp
      Icon for Microsoft rankMicrosoft

      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.

      • MrMrkn's avatar
        MrMrkn
        Copper Contributor

        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!

Resources