collab365: powershell for office 365
TRANSCRIPT
WWW.COLLAB365.EVENTS
Vlad Catrinescu
vNext Solutions
Email : [email protected]
Twitter : @vladcatrinescu
LinkedIn :
http://spvlad.com/VladLnkd
• Montreal, Canada
• SharePoint-Community.net Co-Founder
• Pluralsight Author
Contact Details:
3
Agenda
PowerShell for Office 365
PowerShell Tips & Tricks Users and Licensing SharePoint Online
Exchange Online Advanced Scripting Questions
5
Getting Help
Get-CommandC Gets All the commandlets
installed on your computer.
Get-HelpH Displays Additional information
about a commandlet
Get-MemberM View all the properties
.CHM
6
Keyboard Shortcuts
• Ctrl+Left arrow / Ctrl+Rightarrow Move to the next word
• F7 Displays a pop-up window
with your command history
• F9 Runs a specific number
command
• Tab Autocomplete command
8
Text File
$servers = get-Content C:\Scripts\input.txtforeach ($server in $servers) {
Write-Host $line}
9
CSV File
$users = import-csv C:\Scripts\Users.csv
foreach ($user in $users) {
$UserName = $user.Name
$UserDept = $user.Department
$UserTitle = $user.Title
Write-host "$UserName is a $UserTitle in the $UserDeptdepartment."}
11
Connecting to Office 365
Requirements• Office 365 Administrator rights• 64-bit Machine• Windows 7 SP1 +• Windows Server 2008R2 +
14
Connecting to Office 365
#Import Module into PowerShell SessionImport-Module MSOnline
#Get Connection Credential$cred = get-credential
#Establish ConnectionConnect-MsolService -Credential $cred
15
Get-MsolUserNew-MsolUserSet-MsolUser
Users
PowerShell Commandlets
Get-MsolSubscriptionNew-MsolLicenseOptions
Set-MsolUserLicense
LicensesGet-MsolGroupNew-MsolGroupSet-MsolGroup
Groups and Roles
16
PowerShell Commandlets
Get-MsolUserNew-MsolUserSet-MsolUserGet-MsolSubscriptionNew-MsolLicenseOptionsSet-MsolUserLicenseGet-MsolGroupNew-MsolGroupSet-MsolGroup
<Verb> - Msol<noun>
19
Connecting to SharePoint Online
Open SharePoint Management Shell
Get Credential
Establish Connection
20
Connecting to SharePoint Online
#Get connection credential$cred = get-credential
#Establish connectionConnect-SPOService
-Url https://<SP Admin Center>.sharepoint.com -credential $cred
21
PowerShell Commandlets
905
300
200
400
600
800
1000
SharePoint 2013 SharePoint Online
Number of PowerShell Cmdlets
Number of Cmdlets
22
PowerShell Commandlets
• Install• Configure• Update• Web Application• Site Collection• SPWeb• SPList• SPItem
SharePoint On Premises• Tenant• Site Collection• SPWeb (very limited)
SharePoint Online
23
PowerShell CommandletsGet-SPOAppErrors Remove-SPOExternalUser Repair-SPOSite
Get-SPOAppInfo Connect-SPOService Set-SPOSite
Get-SPODeletedSite Disconnect-SPOService Test-SPOSite
Remove-SPODeletedSite Get-SPOSite Upgrade-SPOSite
Restore-SPODeletedSite New-SPOSite Get-SPOSiteGroup
Get-SPOExternalUser Remove-SPOSite New-SPOSiteGroup
Remove-SPOUser Set-SPOUser Remove-SPOTenantSyncClientRestriction
Add-SPOUser Get-SPOUser Get-SPOTenantSyncClientRestriction
Get-SPOWebTemplate Get-SPOTenant Request-SPOUpgradeEvaluationSite
Remove-SPOSiteGroup Set-SPOTenant Set-SPOTenantSyncClientRestriction
Set-SPOSiteGroup Get-SPOTenantLogEntry Get-SPOTenantLogLastAvailableTimeInUtc
SPO=
27
Connecting to Exchange Online#Get Connection Credential$cred = get-credential
#Establish Connection$Session = New-PSSession-ConfigurationName Microsoft.Exchange-ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred-Authentication Basic -AllowRedirection
#Add Remote Session into current sessionImport-PSSession $Session
28
PowerShell CommandletsDisable-Mailbox Get-InboundConnector Get-DistributionGroupEnable-Mailbox New-InboundConnector New-DistributionGroupGet-Mailbox Remove-InboundConnector Remove-DistributionGroupNew-Mailbox Set-InboundConnector Set-DistributionGroupRemove-Mailbox Get-OutboundConnector Add-DistributionGroupMemberSearch-Mailbox Get-MailContact Get-UnifiedGroupSet-Mailbox New-MailContact New-UnifiedGroupAdd-RecipientPermission Remove-MailContact Remove-UnifiedGroupGet-RecipientPermission Set-MailContact Set-UnifiedGroupDisable-Mailbox Get-Contact Add-UnifiedGroupLinks
31
Connecting to all Services
Steps:1. Get Connection Credential 2. Import Modules3. Create Sessions4. Connect to Services5. Import Sessions
32
Connecting to all the services#Get Connection Credential$cred = get-credential#Import ModulesImport-Module MsOnline, Microsoft.Online.SharePoint.PowerShell#Create Sessions$exchange = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri
"https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication "Basic" –AllowRedirection
#Connect to SevicesConnect-MsolService -Credential $credConnect-SPOService -Url https://tenant.sharepoint.com -credential $cred#Import SessionsImport-PSSession $exchange
33
CSOM For SharePoint Online
• Client Side Object Model
• Used to develop code that runs outside of the SharePoint server
34
CSOM For SharePoint Online
1. Get Client Context• Class that manages the interaction between
our script and the SharePoint server.2. Do the required action
35
Get All Lists in a Websitefunction Get-ClientContext($UserPrincipalName,$SecurePassword,$Url){
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($Url)$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserPrincipalName, $SecurePassword) $clientContext.Credentials = $credentialsreturn $clientContext }
#Initial Variables$User = "[email protected]"$File = "C:\Scripts\Password.txt"$Site = "https://globomanticsorg.sharepoint.com"$Password = Get-Content $File | ConvertTo-SecureString#Get Context$Context = Get-ClientContext $User $Password $Site$lists = $Context.Web.Lists$context.Load($lists)$context.ExecuteQuery()#Loop trough listsforeach ($list in $lists) {
Write-Host $list.Title }
36
Community Extensions
https://github.com/OfficeDev/PnP-PowerShell Download
• Program ran mostly by Microsoft• 134 Cmdlets
OfficeDev PnP-PowerShell
https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/readme.md
Documentation
37
Get All Lists in a Website
$User = "[email protected]"$File = "C:\Scripts\Password.txt"$cred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
Connect-SPOnline-Url https://globomanticsorg.sharepoint.com -Credentials $cred
Get-SPOList
39
01
02
03
04
Resources
Course coming soon! 2+ hours of PowerShell for Office 365 Awesomeness!
Pluralsight
http://powershell.office.com/PowerShell for Office 365 Portal
http://blogs.technet.com/b/heyscriptingguy/ Hey, Scripting Guy! Blog
https://github.com/OfficeDev/PnP-powershellPnP-PowerShell