Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
2,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Office 365 Powershell Administration
  2.  
  3. #Copy & paste required commands and press f8 to run selection with PS-ISE (In Administrator Mode)
  4.  
  5. #Connect to Office365 Online Services First, then SharePoint/Skype optional
  6.  
  7. #Office 365 Prerequisites
  8. #Step 1 - https://www.microsoft.com/en-us/download/details.aspx?id=41950
  9. #Step 2 - https://msdn.microsoft.com/en-us/library/azure/jj151815.aspx
  10.  
  11. #SharePoint Online Prerequisites
  12. #https://www.microsoft.com/en-gb/download/details.aspx?id=35588
  13. #https://github.com/officedev/pnp-powershell/releases
  14. #https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/readme.md
  15.  
  16. #Skype for Business Prerequisities
  17. #http://www.microsoft.com/en-us/download/details.aspx?id=39366
  18.  
  19. #Connecting & Authenticating with Office 365 Online - select and run entire block
  20. Import-Module MSOnline
  21. $O365Cred = Get-Credential
  22. $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
  23. Import-PSSession $O365Session
  24. Connect-MsolService –Credential $O365Cred
  25.  
  26. Get-MsolUser #Test connectivity
  27.  
  28. #Connecting & Authenticating with SharePoint Online (after connecting to Exchange Online)
  29. Set-ExecutionPolicy RemoteSigned #First Run Only
  30. Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  31. Install-Module SharePointPnPPowerShellOnline -AllowClobber
  32. Connect-SPOService -Url https://examplecompany-admin.sharepoint.com -Credential $O365Cred
  33. Connect-SPOnline -Url https://examplecompany.sharepoint.com -Credentials $O365Cred
  34.  
  35. Get-SPOSite #Test connectivity
  36.  
  37. #Connecting & Authenticating with Skype For Business Online
  38. Import-Module SkypeOnlineConnector
  39. $CSSession = New-CsOnlineSession -Credential $O365Cred
  40. Import-PSSession $CSSession -AllowClobber
  41.  
  42. Get-CsUserActivitiesReport #Test connectivity
  43.  
  44. #Change password & set to never expire
  45. Set-MsolUserPassword -UserPrincipalName "" -NewPassword "" -ForceChangePassword $false
  46. Set-MsolUser -UserPrincipalName "" -PasswordNeverExpires $true
  47.  
  48. #Add and license a new user
  49. New-MsolUser -DisplayName "Will Smith" -FirstName Will -LastName Smith -UserPrincipalName will@company.co.uk -UsageLocation GB -LicenseAssignment syndication-account:O365_BUSINESS_ESSENTIALS -Password Cheese123! -ForceChangePassword $false -PasswordNeverExpires $true
  50. #Adds a new user with the above parameters, assigns a small business essentials license
  51. Get-MsolAccountSku #Checks available licenses
  52. #Remove a users license - deletes all mail content and settings
  53. Set-MsolUserLicense -UserPrincipalName userA@company.co.uk -RemoveLicenses syndication-account:O365_BUSINESS_ESSENTIALS
  54.  
  55. #Assigning and revoking mailbox permissions
  56. Add-MailboxFolderPermission -Identity userA@company.co.uk -User userB@company.co.uk -AccessRights Owner #Adds ownership rights for User B on User A’s mailbox folder
  57. Add-MailboxPermission "userA@company.co.uk" -User "userB@company.co.uk" -AccessRights FullAccess -AutoMapping $true #Enable automapping of mailbox
  58. Get-MailboxFolderPermission "userA@company.co.uk:\Inbox\Contracts" #Check permissions on “Inbox\Awaiting” subfolder
  59. Add-RecipientPermission userA@company.co.uk -AccessRights SendAs -Trustee userB@company.co.uk #SendAs - after running this command, use the "From" option in new mail, options menu
  60. Remove-MailboxFolderPermission userA@company.co.uk:\Inbox -User userB@company.co.uk #Remove existing permissions to provide a clean slate tgeto add new permissions
  61.  
  62. #Display detail information about a 365 user
  63. Get-MsolUser -UserPrincipalName "userA@company.co.uk" | fl *
  64.  
  65. #Export a detail CSV of 365 users to a specified file path including license type
  66. Get-MsolUser | Select-Object FirstName, LastName, UserPrincipalName -ExpandProperty Licenses | Export-Csv C:\Users\Admin\Desktop\Userlicenselist.csv
  67.  
  68. #Change user details using -FirstName -LastName -DisplayName etc
  69. Set-MsolUser -UserPrincipalName "user@company.co.uk" -DisplayName "User One"
  70.  
  71. #Convert Mailbox from User->Shared to safely remove a license
  72. Set-Mailbox user@company.co.uk -Type Shared
  73. #Check if mailbox converted correctly to shared
  74. Get-Mailbox -Identity user@company.co.uk | Format-List RecipientTypeDetails
  75.  
  76. #Create a distribution group | -RequireSenderAuthenticationEnabled $false ($false allows external users to send)
  77. New-DistributionGroup -DisplayName DistributionGroupExample -Name DistGroup -PrimarySmtpAddress test@company.com -Members usera@company.com, userb@company.com, userc@company.com -RequireSenderAuthenticationEnabled $false
  78.  
  79. #Check SMTP Forwarding on a mailbox
  80. Get-Mailbox -Identity user@domain.com | FL ForwardingSMTPAddress
  81.  
  82. #Setup a new SMTP Forward
  83. Set-Mailbox -Identity usera@company.co.uk -ForwardingSmtpAddress userb@company.co.uk -DeliverToMailboxAndForward $true #true/false - (True keep a copy in the first mailbox as well as forwarding)
  84.  
  85. #Sort and export information to CSV
  86. Get-MsolUser | Sort Name | Select-Object UserPrincipalName, Licenses -ExpandProperty Licenses
  87.  
  88. ######################
  89.  
  90. #Generic Commands
  91.  
  92. #Lists every item under current directory including items in subfolders
  93. Get-ChildItem -Force -Recurse
  94.  
  95. #Finds basic information on current system and exports to csv (optional)
  96. Get-WmiObject -Class Win32_ComputerSystem -Recurse | Export-Csv C:\Users\Admin\Desktop\test.csv
  97.  
  98. #Find the five processes using the most memory
  99. ps | sort –p ws | select –last 5
  100.  
  101. Start-Sleep 60; Restart-Computer –Force –ComputerName USER-PC
  102.  
  103. ######################
  104.  
  105. #Jamie Hutchinson 2017
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement