Advertisement
martypete

O365 Powershell

Apr 3rd, 2019 (edited)
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set-ExecutionPolicy RemoteSigned
  2. Install-Module -Name PowerShellGet -Force -AllowClobber
  3.  
  4. #=================================
  5. #===   CONNECT TO SERVICES =======
  6. #=================================
  7.  
  8. Connect-MsolService
  9. Connect-ExchangeOnline
  10. Connect-MicrosoftTeams
  11.  
  12. Connect-Graph -Scopes "Directory.Read.All", "ChannelSettings.Read.All", "Group.Read.All"
  13. --Teams 👆
  14.  
  15. --Intune 👇
  16. Connect-Graph -Scopes "Directory.Read.All","User.Read.All", "Group.Read.All", "Device.Read.All","ChannelSettings.Read.All","DeviceManagementManagedDevices.Read.All"
  17.  
  18. #=======================================================
  19.  
  20. #Bulk create new users (export csv, fill in upn,displayname,password, then import)
  21. Get-User | select userprincipalname,displayname,password | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  22. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach { New-MsolUser -DisplayName $_.displayname -UserPrincipalName $_.userprincipalname -Password $_.password }
  23.  
  24. # Bulk set UsageLocation:
  25. Get-User | select userprincipalname,displayname,UsageLocation | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  26. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach { Set-MsolUser -UserPrincipalName $_.userprincipalname -UsageLocation $_.UsageLocation }
  27.  
  28. # check usage location
  29. get-msoluser | select userprincipalname,displayname,usagelocation | select-string *
  30.  
  31. # Bulk assign licenses
  32. Get-User | select userprincipalname,displayname,UsageLocation,AccountSkuId | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  33.  
  34. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach { Set-MsolUserLicense -UserPrincipalName $_.userprincipalname -AddLicenses $_.AccountSkuId }
  35.  
  36. Examples:
  37.  
  38. reseller-account:ENTERPRISEPACK
  39. reseller-account:FLOW_FREE
  40. reseller-account:O365_BUSINESS_PREMIUM
  41. reseller-account:POWER_BI_STANDARD
  42. reseller-account:O365_BUSINESS_ESSENTIALS
  43.  
  44. # add 1 license
  45. Set-MsolUserLicense -UserPrincipalName name@domain.onmicrosoft.com -AddLicenses reseller-account:O365_BUSINESS_ESSENTIALS
  46.  
  47. # check license usage:
  48. Get-MsolAccountSku
  49.  
  50. #See if a domain exists in office 365
  51.  
  52. function Test-DomainAvailability {
  53.       param(
  54.              [Parameter(mandatory=$true)]
  55.              [string]$DomainName
  56.        )
  57.        $descriptions = @{
  58.               Unknown   = 'Domain does not exist in Office 365/Azure AD'
  59.               Managed   = 'Domain is verified but not federated'
  60.               Federated  = 'Domain is verified and federated'
  61.        }
  62.       $response = Invoke-WebRequest -Uri "https://login.microsoftonline.com/getuserrealm.srf?login=user@$DomainName&xml=1" -UseBasicParsing
  63.      if($response -and $response.StatusCode -eq 200) {
  64.            $namespaceType = ([xml]($response.Content)).RealmInfo.NameSpaceType
  65.            New-Object PSObject -Property @{
  66.                     DomainName = $DomainName
  67.                     NamespaceType = $namespaceType
  68.                     Details = $descriptions[$namespaceType]
  69.            } | Select-Object DomainName, NamespaceType, Details
  70.     } else {
  71.         Write-Error -Message 'Domain could not be verified. Please check your connectivity to login.microsoftonline.com'
  72.     }
  73. }
  74.  
  75. #====================================
  76. #   Check Aliases on a Mailbox  =====
  77. #====================================
  78.  
  79. $FormatEnumerationLimit = -1 #otherwise will be truncated
  80. Get-Mailbox cwilson@domain.com | select primarysmtpaddress,emailaddresses |
  81. Out-Gridview #otherwise ps will still truncate it
  82.  
  83. #==========================================
  84. #====== CHECK FORWARDING ON A MAILBOX =====
  85. #==========================================
  86.  
  87. Get-Mailbox betsy.vega@domain.com  | ft ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward
  88.  
  89. #=======================================
  90. #===   SET FORWARDING ON MAILBOX =======
  91. #=======================================
  92.  
  93. Set-Mailbox -Identity mmessana@domain.com -ForwardingAddress $null -ForwardingSmtpAddress $null -DeliverToMailboxAndForward $False
  94.  
  95. #=======================================================
  96. #===   GIVE FULL ACCESS TO MAILBOX (WITH AUTOMAPPING) ==
  97. #=======================================================
  98.  
  99. $FormatEnumerationLimit = -1 #otherwise will be truncated
  100. Get-Mailbox mailbox@domain.com |
  101. Add-MailboxPermission -User user@domain.com -AccessRights FullAccess -InheritanceType All
  102.  
  103. ====== CHECK THAT FULL ACCESS ON MAILBOX WORKED
  104.  
  105. Get-MailboxPermission CBarrett@aquaguard.net | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false}
  106.  
  107. #====================================
  108. # CHECK OWNERSHIP INFO OF A GROUP (MANAGEDBY) ==
  109. #====================================
  110.  
  111. Import-csv ddd.csv | foreach { Get-UnifiedGroup $_.PrimarySmtpAddress | select displayname,PrimarySmtpAddress,ManagedBy }
  112.  
  113. #====================================
  114. # EXPORT LIST OF GROUPS YOU NEED ==
  115. #====================================
  116.  
  117. #get the list of groups
  118. Get-UnifiedGroup  -ResultSize Unlimited |
  119.  
  120. #filter the list
  121. Where-Object PrimarySmtpAddress -Match info@* |
  122.  
  123. #limit the information columns
  124. select displayname,PrimarySmtpAddress,ManagedBy |
  125.  
  126. #export the csv
  127. Export-Csv ddd.csv -NoTypeInformation
  128.  
  129. #====================================
  130. #   Bulk Add Group Owners       ==
  131. #====================================
  132.  
  133. Import-Csv ddd.csv |
  134. foreach { Add-UnifiedGroupLinks –Identity $_.PrimarySmtpAddress –LinkType "Owners" –Links "[email protected]" }
  135.  
  136. #====================================
  137. #   Bulk Remove Unified Group Owners==
  138. #====================================
  139.  
  140. Import-Csv ddd.csv |
  141. foreach { Remove-UnifiedGroupLinks –Identity $_.PrimarySmtpAddress –LinkType "Owners" –Links "[email protected]" -Confirm:$false }
  142.  
  143. Remove-UnifiedGroupLinks info@domain.com –LinkType "Owners" –Links "[email protected]" -Confirm:$false
  144.  
  145. #====================================
  146. #   Bulk Remove Unified Group MEMBERS==
  147. #====================================
  148.  
  149. Import-Csv ddd.csv |
  150. foreach { Remove-UnifiedGroupLinks –Identity $_.PrimarySmtpAddress –LinkType "Members" –Links "[email protected]" -Confirm:$false }
  151.  
  152. Remove-UnifiedGroupLinks info@domain.com –LinkType "Members" –Links "[email protected]" -Confirm:$false
  153.  
  154. #=======================================================
  155. #   Bulk Remove Distribution Group Owners (ManagedBy) ==
  156. #=======================================================
  157. Import-Csv ddd.csv |
  158. foreach { Set-DistributionGroup -Identity $_.PrimarySmtpAddress -ManagedBy user@domain.com }
  159.  
  160. #=======================================================
  161. #   Bulk ADD Shared Mailbox Owners ==
  162. #=======================================================
  163.  
  164. Import-Csv ddd.csv |
  165. foreach { Add-MailboxPermission -Identity $_.PrimarySmtpAddress -Owner user@domain.com }
  166.  
  167. Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited |
  168. Get-MailboxPermission | Select-Object Identity,User,AccessRights | Where-Object {($_.user -like '*@*')}|Export-Csv C:\Temp\sharedfolders.csv  -NoTypeInformation
  169.  
  170. ====== CHECK THAT IT WORKED
  171.  
  172. Import-Csv ddd.csv |
  173. foreach { Get-UnifiedGroupLinks -Identity $_.PrimarySmtpAddress -LinkType Members }
  174.  
  175. #=======================================================
  176. #   Add One user to Multiple Groups ==
  177. #=======================================================
  178.  
  179. Import-Csv ddd.csv |
  180. foreach { Add-UnifiedGroupLinks –Identity $_.PrimarySmtpAddress –LinkType "Members" –Links "[email protected]" }
  181.  
  182. #====================================
  183. #===   Bulk Add Group Members =======
  184. #====================================
  185.  
  186. Import-Csv ddd.csv |
  187. foreach { Add-UnifiedGroupLinks –Identity $_.PrimarySmtpAddress –LinkType "Members" –Links "[email protected]" }
  188.  
  189. ====== CHECK THAT IT WORKED
  190.  
  191. Import-Csv ddd.csv |
  192. foreach { Get-UnifiedGroupLinks -Identity $_.PrimarySmtpAddress -LinkType Members }
  193.  
  194. #=======================================================
  195. #===   FIND A TEAM BY EMAIL ADDRESSS =======
  196. #=======================================================
  197.  
  198. Get-Team | foreach { Get-MgTeamChannel -TeamId $_.groupid } | Where-Object email -Match "[email protected]" | ft CreatedDateTime,DisplayName,Email
  199.  
  200. #=======================================================
  201. #===   LIST ALL TEAMS WITH EMAIL ADDRESSS (SORTED BY CREATED DATE) =======
  202. #=======================================================
  203.  
  204. Get-Team | foreach { Get-MgTeamChannel -TeamId $_.groupid } | Where-Object email -Match "amer.teams.ms" | sort-object -CreatedDateTime
  205.  
  206. #=======================================================
  207. #===   ADD FULL ACCESS TO A MAILBOX ( TYPE .fa ) =======
  208. #=======================================================
  209.  
  210. Get-Mailbox lhenley@domain.com | Add-MailboxPermission -User martin.peterson@domain.com -Automapping:$False -AccessRights FullAccess -InheritanceType All
  211.  
  212. =================================
  213. =================================
  214.  
  215. Get-mgteamchannel -TeamId f8c0e620-220c-419a-a7f6-19f8ffacdc2e | ft Displayname,email
  216.  
  217. DisplayName        Email                                
  218. -----------        -----                                
  219. General            71edbf20.domain.co@amer.teams.ms
  220. Name of Channel 1  bf3b3d28.domain.co@amer.teams.ms
  221. Name of Channel 2  2c6cf3b5.domain.co@amer.teams.ms
  222.  
  223. ================================================
  224. ****Get Members of Office 365 (Unified) Group***
  225. ================================================
  226.  
  227. Get-UnifiedGroupLinks -Identity "GW Info" -LinkType Members | ft DisplayName,PrimarySmtpAddress
  228. Get-UnifiedGroupLinks -Identity "GW Info" -LinkType Members | ft DisplayName,PrimarySmtpAddress
  229.  
  230. Get-UnifiedGroup -ResultSize Unlimited | where-Object -Match "DryPro Service Techs"
  231.  
  232. Get-UnifiedGroupLinks -Identity b9907132-0024-46b4-91c6-b08ab81c55f6 -LinkType Members | ft DisplayName,PrimarySmtpAddress
  233.  
  234. ================================================
  235. ****Get Members of Distribution Group***
  236. ================================================
  237.  
  238. Get-DistributionGroupMember -Identity "Name of Group" | ft DisplayName,PrimarySmtpAddress
  239. Get-Distributiongroup -Identity b9907132-0024-46b4-91c6-b08ab81c55f6
  240. Get-Distributiongroup -Identity "Name of Group"
  241. Get-DistributionGroupMember -Identity user@domain.com
  242. Get-DistributionGroupMember -Identity user@domain.com
  243.  
  244. ================================================
  245. ****Get Members of Azure AD Group****
  246. ================================================
  247.  
  248. Get-AzureADGroupMember -ObjectId 138751c3-6b46-43ed-b2b5-aa070c3a5e5f | ft UserPrincipalName
  249.  
  250.  
  251.  
  252. *************************************
  253. ****** Find a Team or Channel **********
  254. *************************************
  255.  
  256. Get-Team | Where-Object DisplayName -Match "matchquery"| Export-csv C:\Users\redte\Documents\teamsquery.csv -NoTypeInformation
  257.  
  258. Import-csv C:\Users\redte\Documents\teamsquery.csv | foreach { Get-MgTeamChannel -TeamId $_.groupid } | Where-Object DisplayName -Match "sms" | Export-csv C:\Users\redte\Documents\channelquery.csv
  259.  
  260. *******************************************
  261. *** Find the Members of a Team by GroupId *****
  262. ******************************************
  263.  
  264. Get-TeamUser -GroupId 06e9acf0-38b9-494b-9936-23c136d5dfc3
  265.  
  266. *************************************
  267. ****** Teams Get- cmdlets  **********
  268. *************************************
  269.  
  270. Get-Team
  271. Get-TeamChannel
  272. Get-TeamFunSettings
  273. Get-TeamGuestSettings
  274. Get-TeamHelp
  275. Get-TeamMemberSettings
  276. Get-TeamMessagingSettings
  277. Get-TeamUser
  278. Add-TeamUser
  279. New-Team
  280. New-TeamChannel
  281. Remove-Team
  282. Remove-TeamChannel
  283. Remove-TeamUser
  284. Set-Team
  285. Set-TeamChannel
  286. Set-TeamFunSettings
  287. Set-TeamGuestSettings
  288. Set-TeamMemberSettings
  289. Set-TeamMessagingSettings
  290. Set-TeamPicture
  291.  
  292. ***********************************************************
  293. ***********************************************************
  294. **************Export Teams Report of Teams and Members*****
  295. ***********************************************************
  296. ***********************************************************
  297.  
  298. $AllTeamsInOrg = (Get-Team | Where-Object DisplayName -NotMatch "test").GroupID
  299. $TeamList = @()
  300.  
  301. Foreach ($Team in $AllTeamsInOrg)
  302. {      
  303.         $TeamGUID = $Team.ToString()
  304.         $TeamGroup = Get-UnifiedGroup -identity $Team.ToString()
  305.         $TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName
  306.         $TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).User
  307.         $TeamUserCount = ((Get-TeamUser -GroupId $Team).UserID).Count
  308.         $TeamGuest = (Get-UnifiedGroupLinks -LinkType Members -identity $Team | ?{$_.Name -match "#EXT#"}).Name
  309.             if ($TeamGuest -eq $null)
  310.             {
  311.                 $TeamGuest = "No Guests in Team"
  312.             }
  313.         $TeamChannels = (Get-TeamChannel -GroupId $Team).DisplayName
  314.     $ChannelCount = (Get-TeamChannel -GroupId $Team).ID.Count
  315.         $TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMemberCount = $TeamUserCount; NoOfChannels = $ChannelCount; ChannelNames = $TeamChannels -join ', '; SharePointSite = $TeamGroup.SharePointSiteURL; AccessType = $TeamGroup.AccessType; TeamGuests = $TeamGuest -join ','}
  316. }
  317.  
  318. #######
  319.  
  320. $TeamList | export-csv C:\Users\redte\Documents\teamsreportFINAL.csv -NoTypeInformation
  321.  
  322. ***********************************************************
  323. ***********************************************************
  324. ******** Find Email addresses on channels of a team *******
  325. ***********************************************************
  326. ***********************************************************
  327.  
  328. Get-MgTeamChannel -TeamId f8c0e620-220c-419a-a7f6-19f8ffacdc2e | ft DisplayName,Email
  329.  
  330. DisplayName        Email                                
  331. -----------        -----                                
  332. General            71edbf20.domain.co@amer.teams.ms
  333.  
  334. ************************************************
  335. ************************************************
  336. ************* EXCHANGE ONLINE POWERSHELL *******
  337. ************************************************
  338. ************************************************
  339.  
  340. ;;;;Disconnect Session
  341.  
  342. Get-PSSession | Where-Object {$_.ConfigurationName -eq “Microsoft.Exchange”} | Remove-PSSession
  343.  
  344. *****************************
  345. *******MAILBOX STATISTICS
  346.  
  347. Get-Mailbox  areddington@domain.com | Ge
  348. t-MailboxStatistics | Select-Object DisplayName, IsArchiveMailbox, TotalItemSize, ItemCount
  349.  
  350. *******************************
  351. *******365 APPLICATION IMPERSONATION
  352.  
  353. New-RoleGroup -Name AppImpGroup -Roles ApplicationImpersonation -Members user@domain.com
  354.  
  355.  
  356. *******************************
  357. *******Add a Full Access user to a mailbox
  358.  
  359. Get-Mailbox user@domain.com | Add-MailboxPermission -User martin.peterson@domain.com -Automapping:$False -AccessRights FullAccess -InheritanceType All
  360.  
  361.  
  362. *******************************
  363. *******See sizes of public folders
  364.  
  365. Get-PublicFolderStatistics | Select-Object Name,FolderPath, TotalItemSize | Out-Gridview
  366.  
  367.  
  368. *******************************
  369. *******See mailbox stats/info (size) for all users:
  370.  
  371. Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, IsArchiveMailbox, TotalItemSize, ItemCount
  372. ______________________________________________________
  373.  
  374. *******************************
  375. *******See who has full access on a mailbox:
  376.  
  377. Get-MailboxPermission <UserPrincipalName>
  378.  
  379. *******************************
  380. *******see all users who have full access to any mailboxes:
  381.  
  382. Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false}
  383. _______________________________________________________
  384.  
  385.  
  386.  
  387. *********Bulk edit users pw's (export, add the PW's in the column, save, then import)
  388.  
  389. Get-User | select UserPrincipalName,Displayname,password | Export-Csv -Path C:\Users\support\Documents\spreadsheet.csv -NoTypeInformation
  390.  
  391. Import-csv C:\Users\support\Documents\peach.csv | foreach {Set-MsolUserPassword -UserPrincipalName $_.userprincipalname -NewPassword $_.password -ForceChangePassword:$False }
  392.  
  393. _______________________________________________________
  394. ********* Bulk create new users (export csv, fill in upn,displayname,password, then import)
  395.  
  396. Get-User | select userprincipalname,displayname,password | Export-Csv -Path C:\Users\support\Documents\spreadsheet.csv -NoTypeInformation
  397.  
  398. Import-csv C:\Users\support\Documents\spreadsheet.csv | foreach { New-MsolUser -DisplayName $_.displayname -UserPrincipalName $_.userprincipalname -Password $_.password }
  399. _______________________________________________________
  400. ******** Bulk set UsageLocation:
  401.  
  402. Get-User | select userprincipalname,displayname,UsageLocation | Export-Csv -Path C:\Users\support\Documents\spreadsheet.csv -NoTypeInformation
  403.  
  404. Import-csv C:\Users\support\Documents\spreadsheet.csv | foreach { Set-MsolUser -UserPrincipalName $_.userprincipalname -UsageLocation $_.UsageLocation }
  405.  
  406. ******check usage location
  407.  
  408. get-user | select userprincipalname,displayname,usagelocation | select-string domain.onmicrosoft.com
  409.  
  410.  
  411.  
  412.  
  413. #See who has full access on a mailbox:
  414.  
  415. Get-MailboxPermission <UserPrincipalName>
  416.  
  417. #see all users who have full access to any mailboxes:
  418.  
  419. Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false}
  420. _______________________________________________________
  421.  
  422. #Bulk edit users pw's (export, add the PW's in the column, save, then import)
  423. Get-User | select UserPrincipalName,Displayname,password | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  424.  
  425. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach {Set-MsolUserPassword -UserPrincipalName $_.userprincipalname -NewPassword $_.password -ForceChangePassword:$False }
  426.  
  427. _______________________________________________________
  428.  
  429. _______________________________________________________
  430.  
  431. #Give a user full access to all mailboxes
  432.  
  433. Get-Mailbox | Add-Mailboxpermission -User user@domain.onmicrosoft.com -AutoMapping:$False -AccessRights FullAccess -InheritanceType All
  434.  
  435. #give a user sendAs to a mailbox
  436. Add-RecipientPermission -Identity <mailbox> -AccessRights SendAs -Trustee <SendAsUser>
  437. _______________________________________________________
  438.  
  439. #See All Global Admins on an account
  440. $role = Get-MsolRole -RoleName "Administrator";Get-MsolRoleMember -RoleObjectId $role.ObjectId | sort rolemembertype | select rolemembertype,displayname,emailaddress
  441.  
  442. _______________________________________________________
  443.  
  444.  
  445. Get-ManagementRoleAssignment -GetEffectiveUsers | Where-Object {$_.EffectiveUserName -eq "[email protected]"} | select-object Role
  446.  
  447.  
  448. #give a single user application impersonation
  449.  
  450. New-RoleGroup -Name AppImpGroup -Roles ApplicationImpersonation -Members martin.peterson@domain.com
  451.  
  452. Add-RoleGroupMember "impersonation for migration" -Member martin.peterson@domain.com
  453. _______________________________________________________
  454.  
  455. # Bulk edit users pw's (export, add the PW's in the column, save, then import)
  456. Get-User | select UserPrincipalName,Displayname,password | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  457.  
  458. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach {Set-MsolUserPassword -UserPrincipalName $_.userprincipalname -NewPassword $_.password -ForceChangePassword:$False }
  459. _______________________________________________________
  460. ########## Bulk create new users (export csv, fill in upn,displayname,password, then import)
  461.  
  462. Get-User | select userprincipalname,displayname,password | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  463.  
  464. Import-csv D:\Users\mpeterson\Documents\spreadsheet.csv | foreach { New-MsolUser -DisplayName $_.displayname -UserPrincipalName $_.userprincipalname -Password $_.password }
  465.  
  466. _______________________________________________________
  467. #### see public folders
  468.  
  469. Get-PublicFolder -Identity \NON_IPM_SUBTREE -Recurse | Format-List Name
  470.  
  471. #### Add aliases for multiple users
  472.  
  473. Get-User | select UserPrincipalName,Displayname,NewEmailAlias | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  474.  
  475. ---Then fill in column "newemailalias"
  476. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Set-Mailbox $_.UserPrincipalName -EmailAddresses @{add=$_.NewEmailAlias}}
  477.  
  478. ----Then check if it worked
  479. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Get-Mailbox $_.UserPrincipalName | Format-List Name,EmailAddresses}
  480. _______________________________________________________
  481.  
  482. ###add aliases for groups
  483.  
  484. Get-UnifiedGroup | select PrimarySmtpAddress,Displayname,NewEmailAlias | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  485.  
  486. ---Then fill in column "newemailalias"
  487. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Set-UnifiedGroup $_.PrimarySmtpAddress -EmailAddresses @{add=$_.NewEmailAlias}}
  488.  
  489. ----Then check if it worked
  490. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Get-UnifiedGroup $_.UserPrincipalName | Format-List Name,EmailAddresses}
  491.  
  492. ### add aliases for distribution groups
  493.  
  494. Get-DistributionGroup | select PrimarySmtpAddress,Displayname,NewEmailAlias | Export-Csv -Path D:\Users\mpeterson\Documents\spreadsheet.csv -NoTypeInformation
  495.  
  496. ---Then fill in column "newemailalias"
  497. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Set-DistributionGroup $_.PrimarySmtpAddress -EmailAddresses @{add=$_.NewEmailAlias}}
  498.  
  499. ----Then check if it worked
  500. Import-CSV D:\Users\mpeterson\Documents\spreadsheet.csv | ForEach {Get-DistributionGroup $_.UserPrincipalName | Format-List Name,EmailAddresses}
  501.  
  502. _______________________________________________________
  503. #Disconnect Session
  504.  
  505. Get-PSSession | Where-Object {$_.ConfigurationName -eq “Microsoft.Exchange”} | Remove-PSSession
  506. _______________________________________________________
  507.  
  508. #get sizes of public folders
  509.  
  510. Get-PublicFolderStatistics | Select-Object Name,FolderPath, TotalItemSize | Out-Gridview
  511. _______________________________________________________
  512. #See mailbox stats/info (size) for all users:
  513.  
  514. Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, IsArchiveMailbox, TotalItemSize, ItemCount
  515. ______________________________________________________
  516.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement