Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Office 365 Powershell Administration
- #Copy & paste required commands and press f8 to run selection with PS-ISE (In Administrator Mode)
- #Connect to Office365 Online Services First, then SharePoint/Skype optional
- #Office 365 Prerequisites
- #Step 1 - https://www.microsoft.com/en-us/download/details.aspx?id=41950
- #Step 2 - https://msdn.microsoft.com/en-us/library/azure/jj151815.aspx
- #SharePoint Online Prerequisites
- #https://www.microsoft.com/en-gb/download/details.aspx?id=35588
- #https://github.com/officedev/pnp-powershell/releases
- #https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/readme.md
- #Skype for Business Prerequisities
- #http://www.microsoft.com/en-us/download/details.aspx?id=39366
- #Connecting & Authenticating with Office 365 Online - select and run entire block
- Import-Module MSOnline
- $O365Cred = Get-Credential
- $O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
- Import-PSSession $O365Session
- Connect-MsolService –Credential $O365Cred
- Get-MsolUser #Test connectivity
- #Connecting & Authenticating with SharePoint Online (after connecting to Exchange Online)
- Set-ExecutionPolicy RemoteSigned #First Run Only
- Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
- Install-Module SharePointPnPPowerShellOnline -AllowClobber
- Connect-SPOService -Url https://examplecompany-admin.sharepoint.com -Credential $O365Cred
- Connect-SPOnline -Url https://examplecompany.sharepoint.com -Credentials $O365Cred
- Get-SPOSite #Test connectivity
- #Connecting & Authenticating with Skype For Business Online
- Import-Module SkypeOnlineConnector
- $CSSession = New-CsOnlineSession -Credential $O365Cred
- Import-PSSession $CSSession -AllowClobber
- Get-CsUserActivitiesReport #Test connectivity
- #Change password & set to never expire
- Set-MsolUserPassword -UserPrincipalName "" -NewPassword "" -ForceChangePassword $false
- Set-MsolUser -UserPrincipalName "" -PasswordNeverExpires $true
- #Add and license a new user
- 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
- #Adds a new user with the above parameters, assigns a small business essentials license
- Get-MsolAccountSku #Checks available licenses
- #Remove a users license - deletes all mail content and settings
- Set-MsolUserLicense -UserPrincipalName userA@company.co.uk -RemoveLicenses syndication-account:O365_BUSINESS_ESSENTIALS
- #Assigning and revoking mailbox permissions
- 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
- Add-MailboxPermission "userA@company.co.uk" -User "userB@company.co.uk" -AccessRights FullAccess -AutoMapping $true #Enable automapping of mailbox
- Get-MailboxFolderPermission "userA@company.co.uk:\Inbox\Contracts" #Check permissions on “Inbox\Awaiting” subfolder
- 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
- Remove-MailboxFolderPermission userA@company.co.uk:\Inbox -User userB@company.co.uk #Remove existing permissions to provide a clean slate tgeto add new permissions
- #Display detail information about a 365 user
- Get-MsolUser -UserPrincipalName "userA@company.co.uk" | fl *
- #Export a detail CSV of 365 users to a specified file path including license type
- Get-MsolUser | Select-Object FirstName, LastName, UserPrincipalName -ExpandProperty Licenses | Export-Csv C:\Users\Admin\Desktop\Userlicenselist.csv
- #Change user details using -FirstName -LastName -DisplayName etc
- Set-MsolUser -UserPrincipalName "user@company.co.uk" -DisplayName "User One"
- #Convert Mailbox from User->Shared to safely remove a license
- Set-Mailbox user@company.co.uk -Type Shared
- #Check if mailbox converted correctly to shared
- Get-Mailbox -Identity user@company.co.uk | Format-List RecipientTypeDetails
- #Create a distribution group | -RequireSenderAuthenticationEnabled $false ($false allows external users to send)
- New-DistributionGroup -DisplayName DistributionGroupExample -Name DistGroup -PrimarySmtpAddress test@company.com -Members usera@company.com, userb@company.com, userc@company.com -RequireSenderAuthenticationEnabled $false
- #Check SMTP Forwarding on a mailbox
- Get-Mailbox -Identity user@domain.com | FL ForwardingSMTPAddress
- #Setup a new SMTP Forward
- 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)
- #Sort and export information to CSV
- Get-MsolUser | Sort Name | Select-Object UserPrincipalName, Licenses -ExpandProperty Licenses
- ######################
- #Generic Commands
- #Lists every item under current directory including items in subfolders
- Get-ChildItem -Force -Recurse
- #Finds basic information on current system and exports to csv (optional)
- Get-WmiObject -Class Win32_ComputerSystem -Recurse | Export-Csv C:\Users\Admin\Desktop\test.csv
- #Find the five processes using the most memory
- ps | sort –p ws | select –last 5
- Start-Sleep 60; Restart-Computer –Force –ComputerName USER-PC
- ######################
- #Jamie Hutchinson 2017
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement