collab365: powershell for office 365

40
WWW.COLLAB365.EVENTS PowerShell for Office 365

Upload: vlad-catrinescu-sharepoint-mvp

Post on 12-Jan-2017

511 views

Category:

Technology


1 download

TRANSCRIPT

WWW.COLLAB365.EVENTS

PowerShell for Office 365

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

Tips and TricksLet’s learn the basics!

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

7

Including Other Files

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."}

Users and LicensingLet’s learn how to manage our users, grant and

remove their licenses.

11

Connecting to Office 365

Requirements• Office 365 Administrator rights• 64-bit Machine• Windows 7 SP1 +• Windows Server 2008R2 +

12

Connecting to Office 365

Software:

13

Connecting to Office 365

Import Module

Get Credential

Establish Connection

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>

SharePoint OnlineLet’s learn how to manage Site Collections,

Tenants and Users

18

Connecting to SharePoint Online

Requirements:

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=

Exchange OnlineLet’s Learn how to manage Exchange Online

Mailboxes & Distribution lists

25

Connecting to SharePoint Online

Requirements:

26

Connecting to Exchange Online

Get Credential

Establish connection

Import remote session

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

Advanced ScriptingLet’s take it to the next level!

30

Advanced Scripting

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

Questions?

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

40

Questions?

Vlad Catrinescu@vladcatrinescu

www.absolute-sharepoint.comhttp://www.pluralsight.com/author/vlad-catrinescu