Office 365 Export proxy addresses from a file of users - powershell

Hello I have a csv file that looks like this:
user1#domain.com
user2#domain.com
user3#domain.com
I have been trying to export aliases for each of these users like this:
Import-CSV -Path .\users.txt | ForEach-Object {Get-Mailbox | Select-Object DisplayName,#{Name=“EmailAddresses”;Expression={$_.EmailAddresses | Where-Object {$_ -LIKE “SMTP:*”}}} | Sort | Format-List}
However it appears this script is exporting user info for all users for each line of users. Seems like a simple thing I'm trying to do however I'm not understanding where I've gone wrong here. Any assistance greatly appreciated.
Thanks!

Related

How to get the get-ADPrincipalGroupMembership for all users in a txt or csv file and put into a txt file for each user?

I am trying to get a file with the group-memberships for every user that is specified in a txt/csv file.
so this is what i had before:
Get-ADPrincipalGroupMembership -Identity $user -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "C:\temp\$user.txt"
this work fine for getting the groups from 1 singel user, but now i have to do this for 100+ users.
And instead of doing it one by one i am looking for a way to automate it.
so i got myself a .csv export of all the users i want this done for.
and started trying.
what i came up with so far:
$users = Get-Content "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $users -Server $DC | Select name | Where-Object name -like GUSR_* | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$users.txt"}
This cleary doesnt work.
I have tried a couple of other things with the foreach command but nothing did the trick.
I have the feeling i am not on the right path to get my result.
Maby somebody has done this before and can help me get on the right path.
i'm not new to powershell but i'm far from an expert, most of the time i use it for basic singel commands or edit some great scripts i find.
sadly for this i haven't found any yet.
with kind regards
Roland
Don't assign back to a variable
Import the CSV
No filter after select
Pretiffy your -like
Use $_ as pipeline variable
Use subexpression operator for string+variable concatenation
Import-Csv "C:\temp\test.csv" |ForEach-Object {Get-ADPrincipalGroupMembership -Identity $_.users -Server $_.DC | Where-Object {$_.name -like 'GUSR_*'} | Select -Expand Name | Out-String | Out-File "\\ads.net\ADS\SDL\Temp\_ROLAND\RSD\test2\$($_.users).txt"}

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.

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 exports csv file containing active directory security group data

I have a bat file that starts up a PS1 script, the PS1 script is supposed to go to AD and export the names listed in a Security Group. It runs fine and exports fine, however the data is incorrect, almost as if it is exporting some unknown data that I'm not sure where from. Here is my powershell script:
$uni = Read-host 'Your username'
$SG = Read-host 'Security Group'
start-sleep -s 3
powershell.exe get-adgroupmember "$SG" | export-csv -path "C:\users\$uni\desktop\members.csv"
When opening the CSV, it shows similar:
TYPE System.String
Length
79
79
63
17
34
79
26
54
1
Am I needing to declare or import a pssession? if so, what is the configurationname for active directory?
Most likely you're getting a collection of objects in your data. You have to expand or join the data before passing to Export-CSV
See the following articles for some idea:
1) http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/
2) http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2010/Powershell/WhydoIgetSystem.StringwhenusingGet-MessageTrackingLogandexportingtoaCSV.html
The articles give the following examples:
1) change the following
Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno#letsexchange.com | Select * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType
to
Get-TransportServer | Get-MessageTrackingLog -ResultSize -Start "11/28/2011" -Sender nuno#letsexchange.com | Select {$_.Recipients}, {$_.RecipientStatus}, * | Export-Csv D:\Reports\Sent_Nuno.csv -NoType
2) change the following
Get-QADUser seth -IncludeAllProperties | select name, proxyaddresses | Export-Csv .seth-nojoin.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf
to
Get-QADUser seth -IncludeAllProperties | select name, #{Name=’proxyAddresses';Expression={[string]::join(“;”, ($_.proxyAddresses))}} | Export-Csv .seth-all_proxyaddresses.csv - See more at: http://blog.millersystems.com/powershell-exporting-multi-valued-attributes-via-export-csv-cmdlet/#sthash.JCccKLui.dpuf
You'll need to import the ActiveDirectory module for the get-ADGroupMember cmdlet, but I assume you've already gotten past that part as you have output instead of errors. I don't have the ability to test currently as I can't import the module (need RSAT or AD Management Gateway Service installed), but I think you would need to insert a select command in your pipeline (to enumerate the problematic data fields) that looks something like this:
powershell.exe get-adgroupmember "$SG" | Select {$_.nameOfVariableReturningSystemString}, * | export-csv -path "C:\users\$uni\desktop\members.csv
Alexander Obersht answered my question through comments, although duct_tape_coder you are also correct. Thanks for the help guys, appreciated.

Trying to determine managedby attribute for specific distributionlist

I've a text file with a list of distribution groups that I'm trying to get managedby attribute. I tried running different commands but seems to be a syntax issue ( fairly new to PowerShell) because I'm able to retrieve the attribute managedby for single distribution group. When I'm formatting and exporting the result to csv file all I get is a bunch of numbers. I'm on powershell exchange server 2008.
Starting with a flat text file named groups.txt:
Employees#company.com
Executives#company.com
Suggested Solution:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
$grouplist | Export-Csv -Path results.csv -NoTypeInformation
Gives results like:
"PrimarySmtpAddress","ManagedBy"
"Employees#company.com","admin"
"Executives#company.com","admin"
Reproducing the "bunch of numbers" issue:
$grouplist = Get-Content groups.txt | foreach {Get-DistributionGroup -Identity $_ | Select-Object PrimarySMTPaddress, ManagedBy}
Export-Csv -InputObject $grouplist -Path results2.csv -NoTypeInformation
Resulted in:
"Count","Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized"
"2","2","2","1","System.Object[]","False","True","False"
Environment: Exchange 2013, Powershell 5.0, Windows 10 Tech Preview 3