Export Distribution Group Members, include forwardingsmtpaddress - powershell

Is there a way I can export Distribution group members but also get the forwardingsmtpaddress included?
Right now I'm using two exports and having to setup vlookup in order to get forwarding addresses.
Here is the command I'm using to export the members I want.
Get-DistributionGroupMember -Identity "groupname#domain.com" | Sort -Property EmailAddress | Export-Csv –Path C:\admin\groupname.csv
Here's the command I use to export the forwarding addresses:
get-mailbox | select UserPrincipalName,ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward | Export-Csv –Path C:\admin\Forwardingemails.csv
The "get-distributiongroupmember" command pulls in a ton of info but nothing on my members forwarding addresses.

Related

List out enabled users who are members of certain security groups

I'm trying to get a list of all enabled users in a particular Security group. Seems simple but i cannot manage to get the correct output.
Thanks
If you are using Active Directory:
Get-ADGroupMember "PUT_HERE_ADGROUP_NAME" -Recursive | Get-ADUser | Where-Object {$_.Enabled -eq $True} | Select-Object -ExpandProperty Name
If you want to see local users use Get-LocalGroupMember and Get-LocalUser with same filter

Find AD security groups on network folders

I am not a programmer, I must of taken a wrong turn! So that's out of the way, how on earth is there not an easy way to take a set of network folders and pipe out a list of AD security groups that are applied to it? I have googled my butt off but there are a million similar questions and i have tested a few scripts but cant get exactly what i want or a lot of errors. We have a top level directory of about 7 folders and security is about 3 levels deep. We want to cleanup unused or orphaned security groups out of AD TOOLS, and try to get a feel of what is used and what is not. Attempting a "Network drive cleanup" at my Organization.
What is the best way to accomplish this? I tried this in PS
Get-ChildItem "\\wfs.company.ca\adv\workgroups\adv services" -recurse | ForEach-Object {Get-Acl $_.FullName} | Export-CSV C:\"adv services".csv
It worked but gave me too much info and not specific Group names.
and i also tried something like this which just produced errors.
# Scope options are Universal, DomainLocal,Global
# Get-GroupMember -Scope DomainLocal
Function Get-GroupMember{
Param(
[parameter(Mandatory=$true)]
[string]
$scope
)
$Groups = Get-ADGroup -Filter {GroupScope -eq $scope -and Members -ne "NULL"} -Properties Name |
Select-Object Name, #{Name="GroupMembers";Expression={(Get-ADGroupMember -Identity "$_" |
Select-Object -ExpandProperty SamAccountName) -join "`n"}}
}
$Groups | Format-Table -AutoSize -Wrap
$Groups | Out-GridView
$Groups | Export-Csv C:\groups.csv -NoTypeInformation
I dont mind putting in the work and research i just dont know where to start.
Any pointers much appreciated.
Thanks!
You could use this to get a unique list of applied identities (groups and users):
(Get-ChildItem "\\wfs.company.ca\adv\workgroups\adv services" -Recurse | Get-Acl).Access.IdentityReference | select -Unique
Furthermore, you could use Get-ADGroup or other ways to check if it's a group or user.

How do i Filter the DHCP Lease information that i export

I just wrote a powershell script that will export dhcp lease information but i want to export specific information like export only IP and mac addresses in the dhcp. Instead of exporting every lease information. The one line of code i have written that exports everything is bellow.
Get-DhcpServerv4Lease -ComputerName "HW2009-11" | Export-Csv -Path ("C:\log\new.csv")
To adress only certain properties of an object, you can use Select-Object. This way you can only choose the ipand mac-address like this:
Get-DhcpServerv4Lease -ComputerName "HW2009-11" | Select-Object -Property IP, mac-address
You can then pipe this to Export-Csv and it will create a .csv file with only those properties:
Get-DhcpServerv4Lease -ComputerName "HW2009-11" | Select-Object -Property IP, mac-address | Export-Csv -Path "C:\log\new.csv"
If you don't know the specific properties of an object, you can just pipe the command to Get-Member:
Get-DhcpServerv4Lease | Get-Member

Export all users NOT in AAD security group with PowerShell?

I need to export all users who are not a member of a certain security group to a CSV file, using PowerShell.
Pretty straight forward, I know, but I can only find methods of exporting users who do meet certain criteria, not methods of exporting users who don't. I found one method that works but only with Active Directory.
I'm currently using this to pull all users:
Get-MSOLUser -all | Where-Object { $_.isLicensed -eq "True"} | Select-Object UserPrincipalName | Export-Csv C:\365\users.csv
And am aiming to get something like this:
Get-MSOLUser -all | Where-Object { $_.isLicensed -eq "True", isNotMemberofGroup ""} | Select-Object UserPrincipalName | Export-Csv C:\365\users.csv
I am unsure how to add an additional condition that only pulls members that are not in a certain security group, using the following logic - dump upn to csv if user is licensed, and if user is not member of group xxx.

powershell script Ad script group

I have the below ps script to Import users details from a domain/ forest from a domain local group, everything is working, but i need to include two more details, user mail is and user domain in the excel. How can I do this?
Get-ADGroupMember "test" | Select-Object samaccountname, name, distinguishedname | Export-CSV -path "c:\test.csv" -notypeinformation
Some properties are not included in the default property set of a user object. In that case you need to query the user with the additional (or all) properties, e.g.:
Get-ADGroupMember "test" `
| Get-ADUser -Properties * `
| select samaccountname, name, distinguishedname, mail `
| Export-CSV "C:\test.csv" -NoTypeInformation
AFAIK the (DNS) domain name is not an AD attribute, but you could derive it from the distinguished name:
(Get-ADUser "name").distinguishedName -replace '^.*?,dc=' -replace ',dc=', '.'
so you could add another property in the select statement like this:
#{n="domain";e={$_.distinguishedName -replace '^.*?,dc=' -replace ',dc=', '.'}}
As for the referral error: the group seems to be containing members from another domain. AFAIK all of the following requirements must be met to be able to run AD PowerShell cmdlets against other domains in the same forest:
The Active Directory Web Services must be running on at least one of the DCs of the remote domain, and the port must be accessible from the local domain.
Your account must have admin privileges on the remote DCs (e.g. by being a member of the Enterprise Admins group).