Azure AD: Out-Null isn't working

Dale Peterson 61 Reputation points
2022-02-10T16:48:03.427+00:00

Hello.

I hope I found the right place to put this thread. I'm not used to the new forums setup yet.

I am running this command to add a user to an AAD group:
Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID

It adds the user just fine. No issues there. But I have this in a script and I don't want the output from adding the user. I just want the cmd to run and not give me the details (I'm pulling the information later in the script and the output from this just clogs up the screen).

I've tried:

  1. Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID | Out-Null
  2. $Null = Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID
  3. Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID > $null
  4. and even: [void] Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID

It still outputs the information.

Is there a way to make it not dump the info to the screen?

Thanks!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,465 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 96,361 Reputation points MVP
    2022-02-10T17:53:22.34+00:00

    Hi @Dale Peterson ,

    there are 2 options you can try:

    # option 1:  
    (Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID) > $null  
      
    # option2:  
    Add-AzureADGroupMember -ObjectID $RetGroup.ObjectID -RefObjectID $RetUser.ObjectID | Out-Null  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

  2. Rich Matheisen 44,776 Reputation points
    2022-02-10T19:22:10.677+00:00

    Given the different methods you've tried leads me to believe that the output you see isn't sent to the "Success" stream (a.k.a. STDOUT).

    Check the value of these variables:
    $ErrorPreference
    $WarningPreference
    $VerbosePreference
    $DebugPreference
    $InformationPreference

    You can experiment to discover the stream that's sending the information to the screen by redirecting each stream (one at a time) to the Success stream and piping the output to "Out-Null".

    Add-AzureADGroupMember . . .  2>&1 | Out-Null    # Error
    Add-AzureADGroupMember . . .  3>&1 | Out-Null    # Warning
    Add-AzureADGroupMember . . .  4>&1 | Out-Null    # Verbose
    Add-AzureADGroupMember . . .  5>&1 | Out-Null    # Debug
    Add-AzureADGroupMember . . .  6>&1 | Out-Null    # Information
    Add-AzureADGroupMember . . .  *>&1 | Out-Null    # All streams
    
    0 comments No comments