Office 365 PowerShell Jeremy Sublett
Agenda Azure AD Cmdlets Users, licenses and other objects SharePoint Patterns and Practices (PnP) Cmdlets Lists, list items, fields and provisioning
Azure AD Cmdlets Cmdlets for accessing and interacting with Azure AD objects
Azure AD PowerShell for Graph User/Groups Certificates AD Apps Domains Auth (OAuth2) Install-Module AzureAD Connect-AzureAD Different than MSOnline cmdlets (referred to as "Older")
Users and Groups Get-AzureADUser Get-AzureADUserMembership Get-AzureADGroup Get-AzureADGroupMember
Adding a User New-AzureADUser -UserPrincipalName "joe.smith@contoso.com" -AccountEnabled $true -DisplayName "Joe Smith" -GivenName "Joe" -Surname "Smith" -MailNickName "Joe.Smith" -Department "Corporate Accounts Payable" -JobTitle "Accountant" -PasswordProfile $PasswordProfile
Adding a User $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $PasswordProfile.Password = "mynewpassword"
Adding a Group New-AzureADGroup -DisplayName "Dev Team" -MailEnabled $false -SecurityEnabled $true -MailNickName "NotSet" Add-AzureADGroupMember -ObjectId… -RefObjectId… Group ID User ID
Licenses Get-AzureADSubscribedSku Set-AzureADUserLicense
Licenses # Create the objects we'll need to add and remove licenses $license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses # Find the SkuID of the license we want to add - in this example we'll use the O365_BUSINESS_PREMIUM license $license.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "O365_BUSINESS_PREMIUM" -EQ).SkuID # Set the Office license as the license we want to add in the $licenses object $licenses.AddLicenses = $license # Call the Set-AzureADUserLicense cmdlet to set the license. Set-AzureADUserLicense -ObjectId "joe.smith@contoso.com" -AssignedLicenses $licenses
AzureAD verses MSOnline AzureAD: allows user to manage Active Directory objects only, [where directory is hosted in Azure] https://docs.microsoft.com/en-us/powershell/module/azuread/connect- azuread?view=azureadps-2.0 MSOnline: apart from managing Active Directory allows more administrative tasks such as Domain management, configure single sign- on etc. https://docs.microsoft.com/en-us/powershell/azure/active-directory/install- msonlinev1?view=azureadps-1.0
SharePoint PnP Cmdlets PowerShell cmdlets for enhanced SharePoint management
SharePoint Patterns and Practices Community-Driven https://github.com/SharePoint/PnP-PowerShell Different from "SPO" cmdlets provided by Microsoft Excellent capabilities to manipulate lists, views and items Installation: Install-Module SharePointPnPPowerShellOnline
* PnP originally used "SPO" in command names Multiple Cmdlets SharePoint Patterns and Practices ("PnP" naming in commands)* Connect-PnPOnline -Url https://contoso.sharepoint.com Connect-PnPOnline -Url https://contoso.sharepoint.com/web1 * PnP originally used "SPO" in command names SharePoint Online Management Shell ("SPO" naming in commands) Connect-SPOService -Url https://contoso-admin.sharepoint.com https://www.microsoft.com/en-us/download/details.aspx?id=35588
Connecting via PnP Cmdlets Site Collection Root Connect-PnPOnline -Url http://tenantxyz.sharepoint.com Subsite (Subweb) Connect-PnPOnline -Url http://tenantxyz.sharepoint.com/web1 Authenticating $creds = Get-Credentials Connect-PnPOnline -Url … -Credentials $creds Connect-PnPOnline -Url … -UseWebLogin
Basic SharePoint Concepts "Site" – a container for webs Site Collection / Root Web "Web" – a location for containing document libraries and lists (sometimes called sites) /web1 /web1/childweb1 Sub Web or Child Web
Webs Get-PnPWebTemplates New-PnPWeb -Title "Customers Web" -Url "CustMgmt" -Description "Simple team site" -Template "STS#3" Connect-PnPOnline -Url https://contoso.sharepoint.com/CustMgmt Get-PnPSubWebs Remove-PnPWeb -Identity 81c90c36-d2e4-4e68-bc38-5af5d96303d1 Remove-PnPWeb –Url web1
Lists New-PnPList -Title "Customers" -Template Contacts Get-PnpList Remove-PnpList –Title "Customers"
Lists $x = Import-Csv -Path .\Desktop\CustList50.csv $x | ForEach-Object { Add-PnPListItem -List Customers -Values @{"Title" = $_.last_name; "First Name = $_.first_name} }
Fields Add-PnPField -List "Customers" -DisplayName "Size" -InternalName "Size" -Type MultiChoice -AddToDefaultView -Choices "Small","Medium","Large"
Create View Add-PnPView -List "Customers" -Title "Simple" - Fields "Title","Company","Size"
Documents Add-PnpFile, Get-PnpFile, Move-PnpFile, Copy-PnpFile Add-PnpFile -Path "c:\temp\MyDoc.txt" -Folder "Shared Documents" -Values @{Modified="1/1/2016"} Get-ChildItem -Path .\Desktop\TestFolder\ | ForEach-Object { Add-PnPFile -Path $_.FullName -Folder "Shared Documents" } Get-PnPFolderItem -FolderSiteRelativeUrl "SitePages" -ItemType File Get-PnPListItem -List "Site Pages"
Other Interesting PnP Commands Submit-PnpSearchQuery –Query "*Test*" Add-PnPNavigationNode -Title "Contoso" -Url "http://microsoft.com" -Location "QuickLaunch" Get-PnPProvisioningTemplate -Out C:\temp\prov.xml
Links Azure AD Reference https://docs.microsoft.com/en-us/powershell/azure/active- directory/overview?view=azureadps-2.0 https://docs.microsoft.com/en-us/powershell/azure/active- directory/importing-data?view=azureadps-2.0 PnP Reference https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add- pnpapp?view=sharepoint-ps