I have a cmdlet that returns members of groups based on filter. I have blocked out AD structure of the snippet that is not relevant. The code returns the group name, the user (member),SAMACCOUNT, Group Manager, and Department. I would like to add email. Here is the code. I have tried several things, to no avail. Any help is appreciated.
To make your code look better you should try to avoid using backticks and aliasses and you should try to write your code as explicit as possible. For example: it makes your code easier to read and to understand when you explicitly write the parameter names.
That does look alot better and easier to read (especially for someone green like me). The filter was pulling in many unneeded groups, so I created a text file to limit the groups to. I also added users’ email. Also, I added a ‘where’ statement to limit the Get-GroupMember to just users (was getting errors if a group member was a group (with the Get-AdUser calls on AD_Group_Manager, Department, and Email).
I was also getting errors on those same parameters if it was null. The comonality is the Get-ADUser call (on parameters AD_Group_Manager, Department, and Email). For instance, AD_Group_Notes could be blank and no error.
Anyhow, the output in ISE looks good. I am wanting to export this to a CSV file, so I thought I would add the pipe at the end, however, I am getting an “Empty pipe error,” so I moved it just inside the last bracket. The CSV get created, but no data. I have attached the new code and changes. Where might I be going wrong.
That worked awesome. One last thing and I am done. With the parameters, how can I test for null/blank? If they are blank, how can I set the value to “No Value” (for sorting and reporting)?