Logging script execution

Welcome Forums General PowerShell Q&A Logging script execution

This topic contains 2 replies, has 3 voices, and was last updated by

Jon
 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #101924

    Participant
    Points: 1
    Rank: Member

    Greetings.

    I'm trying to log the results of the following script.
    The script runs successfully & the Out-File is created, however it is blank. What am I doing wrong?

    #first, let's get the DistinguishedName of the group
    $grp = get-ADGroup "MI_Exchange_O365"
    $grpDN = $grp.DistinguishedName
    
    #Now let's read in the list of users display names.
    $list = get-content "C:\AD group remove\userlist.txt"
    
    #Now we can read through the list, find each user's DistinguishedName
    foreach ($item in $list)
    {
    	add-ADGroupMember -identity $grpDN -Members $item -Confirm:$false | Out-File "C:\AD group remove\Add_log.txt" -Append	
    }
  • #101927

    Participant
    Points: 264
    Helping Hand
    Rank: Contributor

    When you carefully study the help for the cmdlet Add-ADGroupMember you will see that it does not output anything by default. You have to provide the parameter -PassThru.

  • #101932
    Jon

    Participant
    Points: 37
    Rank: Member

The topic ‘Logging script execution’ is closed to new replies.