Extract the dynamic rule for my dynamic O365 groups - powershell

I want to extract the dynamic rule from my O365 unified groups with powershell and export it to CSV. I looked and did not find anything. In my file I would also like ID,Display Name, Primary SMTP. I know i have no code to post, just stuck.
Thanks
something like:
Get-UnifiedGroup -Identity "group1" -????dynamicrule??? | Export-CSV "C:\Temp\GroupMembers.csv" -NoTypeInformation

Related

Powershell: Pulling from a list (CSV) running a command and outputting to a different CSV

very new to heavier powershell and I've been hacking at this all day and can't figure it out.
I need to get a list of UPNs from office 365 accounts. I have the names in a CSV file. It has one column, with a long list of names. Heading is "name"
I want to run the get-user command against every name with the pipe format-list name, universalprincipalname and then output it to a new file.
I tried this:
get-content "m:\filename.csv" |
foreach {get-user '$_.user' -identity -resultsize unlimited} |
format-list name, userprincipalname |
out-file -FilePath m:\newfilename.csv
But it did not work (I also tried it with import-csv). It seemed to instead of pulling from my list, pull right from the office365 exchange server and when it finally finished had way more names in it than I have in my list.
My overall goal is to generate a list of upns of all the people who do not have mobile devices with their account so I can use a powershell command to disable active sync and OWA for mobile devices. Unfortunately, the command I used to generate my list of users produced the list in first name, last name format...and we have so many users I can't just concatenate the thing in excel, because there would be a ton of mistakes.
CSV is laid out like this:
Column1
name
first last
first last
first last
first last
Assuming the CSV's header is Name, the code should look like this:
Import-Csv "m:\filename.csv" | ForEach-Object {
Get-User -Identity $_.Name.Trim() -ResultSize Unlimited
} | Select-Object Name, UserPrincipalName |
Export-Csv "m:\newfilename.csv" -NoTypeInformation
Note that I'm using Select-Object instead of Format-Table. You should only use Format-Table to display your output to the PowerShell host, objects passed through the pipeline to this cmdlet will be recreated into a new object of the type FormatEntryData which you do not want if your intent is to export the data.

How to change ManagedBy owner from one user to another one for 150+ groups using power shell

I would like to change the Active Directory Group tab ManagedBy user to another one. With PowerShell script, I exported the groups with the old owner (>150) to a csv file. Now I need to change the owner of those groups using the csv file as input.
I don`t have much experience with scripting, I appreciate any help.
Thanks!
The task is very easy with PowerShell. You didn't show an example of the CSV data you exported so an example may not be exact. However, I assume you exported the default output of Get-ADGroup it might look something like this
(Import-Csv C:\temp\managedBy.csv).DistinguishedName| Set-ADGroup -ManagedBy <NewManager's DN>
Note: I like to use the DistinguishedName for these things but samAccountName should also work.
(Import-Csv C:\temp\managedBy.csv).samAccountName | Set-ADGroup -ManagedBy <NewsamAccountName>
Note: Again with the assumption that your Csv data is a direct export Get-ADGroups's output. You cannot pipe Import-Csv directly to Get/Set-ADGroup as the latter will have trouble determining which property to bind to the -Identity parameter.
However, I would point out you really don't need the intermediate Csv file. You can query AD directly for groups managed by the old manager and pipe that to a command to change the owner.
Get-ADGroup -Filter "ManagedBy -eq '<OldOwner'sDN>'" |
Set-ADGroup -ManagedBy "<NewOwner'sDN"
Note: Again you may be able to get away with using the samAccountName instead of the DN.
Note: You can add the WhatIf parameter to the Set-ADGroup` command to preview what will happen before actually running it.

Getting All Calendar SubFolders from CSV List of Users

I am trying to get a list of all the subfolders for a list of users from importing a CSV. Here is the code I have:
Import-Csv "C:\Users\177626\Desktop\Calendar.csv" | foreach {Get-MailboxFolder -identity "$($_.CalendarUsers):\Calendar" -GetChildren}
$_.CalendarUsers is what I am using as the column in the CSV for the user email addresses.
The issue is whenever I run the script, it reads the first users but then tell me any user after that, that the mailbox does not exist. See attached:
Any help would be much appreciated to figure this out...also, is it possible to also list the User's Name and PrimarySMTP from the output of this script?
Thanks!
Please check if all the mailboxes and the calendars in the .csv file are provisioned.
Import-Csv "C:\Users\177626\Desktop\Calendar.csv" | foreach {Get-Mailbox -identity $_.CalendarUsers}
Import-Csv "C:\Users\177626\Desktop\Calendar.csv" | foreach {Get-MailboxCalendarFolder -Identity "$($_.CalendarUsers):\Calendar"}
ref: https://learn.microsoft.com/en-us/powershell/module/exchange/get-mailboxcalendarfolder?view=exchange-ps

Adding multiple users to multiple OU's using a single line powershell command

I am very new to PowerShell and I have a .csv file that contains 100 different users with the fields Name,Surname,Section and depending on the section the user has to be created in that specific OU. Ex:Joe,Heart,Accounts - When I execute the command I the user has to be created in the Accounts Organizational Unit.
The biggest challenge is that I have to use only a 1 line command to create the 100 users in their respective OU. I tried multiple commands and watched numerous videos but none seem to work. I am working on Windows Server 2012.
Currently, I am trying to make use of this command
Import-Csv C:\Users\Administrator\Desktop\HomeList.csv
| ForEach-Object { Set-ADOrganizationalUnit -Identity $_.Section -Member $_.Name }
And I am getting the error
A parameter cannot be found that matches parameter name 'Member'
Since this is a school exercise I don't think it would be a good thing to give you a working piece of code to simply copy/paste.
I can however give you tips on where to look..
The CSV file has these fields as you say: Name, Surname, Section where
'Name' seems to be the users first name
'SurName' is the users last name
'Section' is the (display)name of the OU
Each user in the CSV must be moved to the specified OU and for that purpose the ActiveDirectory module has the cmdlet Move-ADObject, so you iterate through the data with a Foreach-Object {...}
There are several issues to deal with here.
The first one is that the Move-ADObject cmdlet takes an -Identity parameter that can either be a DistinghuishedName or a GUID. You can also pipe an ADUser object to it.
In your CSV you have the users first name (AD property GivenName) and the users last name (property SurName) and so you will need to get the user object from AD first in order to be able to use Move-ADObject.
For that, there are several answers to be found on the internet, both using the -Filter aswell as the -LDAPFilter parameters of Get-ADUser.
The second issue is that Move-ADObject needs a -TargetPath parameter in the form of a DistinghuishedName and since your CSV file only contains the (Display)Name of the target OU, you need to get that first too.
The cmdlet for that is Get-ADOrganizationalUnit where you can use the -Filter parameter, something like this: -Filter "Name -eq '$($_.Section)'"
Note: you can also use Get-ADObject and filter on "ObjectClass -eq 'organizationalunit'" as an alternative for Get-ADOrganizationalUnit, but that is a bit more difficult.
Once you have both AD objects, you're all set to use the Move-ADObject cmdlet to move the user to the target OU, but always add the -WhatIf switch to the command when trying out your code. Only if you are satisfied with the results shown in the console, you can take that switch off.
Please do not attempt to put all this in a single line. Write it out and add comments to the code. If you got it working you may want to look at speeding things up a little by organising the data from the CSV using Group-Object
Hope this helps

Import .csv AzureADUser script only returns 100 entries

I have exported a list of 270 user accounts from O365, all my shared mailboxes, what I want to do is pull the department field of each of those accounts.
But the output from cmdlet Get-Mailbox which I used to get my sharedlist.csv doesn't include the department information.
I know AzureADUser does, so, I am trying to loop through the sharedlist.csv and pull the displayname, UPN, and Department for each addresses listed in the sharedlist.csv
What I'm trying to figure out is how to have Get-AzureADUser pull only the information on the users I have listed in my CSV file.
Here is the command that I have so far:
Import-Csv 'C:\PowerShell Scripts\sharedlist.csv' | ForEach {Get-AzureADUser -All $True | Select-Object DisplayName,UserPrincipalName,Department}
This is obviously not working for what I'm trying to do. It outputs in the format I want and shows the data, but it is pulling every Azure Ad User and then looping over and over. If someone can point me to the proper syntax needed to get this job done I'd appreciate it.
TIA
As Lee_Daily already explained in his comment, you are using the Get-AzureADUser cmdlet without any parameter, so it returns info about any user, not only the ones you have defined in the CSV file.
If your file (I peeked in the original question) looks like this:
"UserPrincipalName"
"user1#domain.com"
"user2#domain.com"
"user270#domain.com"
Then this should work for you:
$data = Import-Csv 'C:\PowerShell Scripts\sharedlist.csv'
$data | ForEach-Object {
Get-AzureADUser -ObjectId $_.UserPrincipalName | Select-Object DisplayName,UserPrincipalName,Department
}