-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SharePoint and Office 365 Scripts added
Added additional SharePoint & Office 365 Scripts
- Loading branch information
Juan Carlos González
committed
May 30, 2015
1 parent
4fcf000
commit 56b7559
Showing
12 changed files
with
553 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
############################################################################################################################################ | ||
#Script that allows to asynchronously provision OneDrive For Business for a set of users | ||
# Required Parameters: | ||
# -> $sCSOMPath: Path for the Client Side Object Model for SPO. | ||
# -> $sUserName: User Name to connect to the SharePoint Online Site Collection. | ||
# -> $sPassword: Password for the user. | ||
# -> $sSiteUrl: SharePoint Online Administration Url. | ||
# -> $ODFBUser: Office 365 user . | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that allows to provision ODFB for a set of users | ||
function Create-ODFBSite | ||
{ | ||
param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$sODFBUsers) | ||
try | ||
{ | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
Write-Host "Getting the User Profile Information for current user" -foregroundcolor Green | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
|
||
#Adding the Client OM Assemblies | ||
$sCSOMRuntimePath=$sCSOMPath + "\Microsoft.SharePoint.Client.Runtime.dll" | ||
$sCSOMUserProfilesPath=$sCSOMPath + "\Microsoft.SharePoint.Client.UserProfiles.dll" | ||
$sCSOMPath=$sCSOMPath + "\Microsoft.SharePoint.Client.dll" | ||
Add-Type -Path $sCSOMPath | ||
Add-Type -Path $sCSOMRuntimePath | ||
Add-Type -Path $sCSOMUserProfilesPath | ||
|
||
#SPO Client Object Model Context | ||
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) | ||
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword) | ||
$spoCtx.Credentials = $spoCredentials | ||
$spoUserProfilesLoader=[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($spoCtx) | ||
$spoUserProfilesLoader.CreatePersonalSiteEnqueueBulk($sODFBUsers) | ||
$spoUserProfilesLoader.Context.ExecuteQuery() | ||
$spoCtx.Dispose() | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Required Parameters | ||
$sSiteUrl = "https://<SPO_Site_Url>/" | ||
$sUserName = "<SPOUser>@<SPO_Domain>.onmicrosoft.com" | ||
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString | ||
$sCSOMPath="<CSOM_Path>" | ||
$sODFBUsers="<SPOUser1>@<SPO_Domain>.onmicrosoft.com","<SPOUser2>@<SPO_Domain>.onmicrosoft.com" | ||
|
||
Create-ODFBSite -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sODFBUsers $sODFBUsers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
############################################################################################################################################ | ||
# Script that allows to get all the App Security Principals for an Office 365 tenant | ||
# Required Parameters: | ||
# -> $sUserName: User Name to connect to the SharePoint Online Site Collection. | ||
# -> $sPassword: Password for the user. | ||
# -> $sMessage: Message to be shown when prompting for user credentials. | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that allows to get all the App Security Principals for an Office 365 tenant | ||
function Get-SPOAppPrincipals | ||
{ | ||
param ($sUserName,$sPassword,$sMessage) | ||
try | ||
{ | ||
$msolcred = Get-Credential -UserName $sUserName -Message $sMessage | ||
Connect-MsolService -Credential $msolcred | ||
Get-MsolServicePrincipal | Select DisplayName,AppPrincipalId,AccountEnabled | Format-Table | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
$sUserName="<O365User>@<O365Domain>.onmicrosoft.com" | ||
$sMessage="Introduce your O365 Credentials" | ||
Get-SPOAppPrincipals -sSPOSiteUrl $sSPOSiteCollection -sUserName $sUserName -sMessage $sMessage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
############################################################################################################################################ | ||
# Script that allows to get changes available in the Changes Log for a SharePoint Online Site Collection | ||
# Required Parameters: | ||
# -> $sCSOMPath: Path for the CSOM assemblies. | ||
# -> $sUserName: User Name to connect to the SharePoint Online Site Collection. | ||
# -> $sPassword: Password for the user. | ||
# -> $sSiteCollectionUrl: Site Collection Url | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that gets changes available in the Changes Log for a SharePoint Online Site Collection | ||
function Get-SPOChangesLogForSC | ||
{ | ||
param ($sCSOMPath,$sSiteColUrl,$sUserName,$sPassword) | ||
try | ||
{ | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
Write-Host "Getting all changes in a SharePoint Online Site Collection" -foregroundcolor Green | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
|
||
#Adding the Client OM Assemblies | ||
#Adding the Client OM Assemblies | ||
$sCSOMRuntimePath=$sCSOMPath + "\Microsoft.SharePoint.Client.Runtime.dll" | ||
$sCSOMPath=$sCSOMPath + "\Microsoft.SharePoint.Client.dll" | ||
Add-Type -Path $sCSOMPath | ||
Add-Type -Path $sCSOMRuntimePath | ||
|
||
#SPO Client Object Model Context | ||
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl) | ||
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword) | ||
$spoCtx.Credentials = $spoCredentials | ||
|
||
#Root Web Site | ||
$spoRootWebSite = $spoCtx.Web | ||
$spoCtx.Load($spoRootWebSite) | ||
$spoCtx.ExecuteQuery() | ||
Write-Host "Accessing the Change Log for " $spoRootWebSite.Title " - " $spoRootWebSite.Url | ||
|
||
#Getting changes in the Change Log | ||
$spocChangeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery($true,$true) | ||
$spocChangesCollection=$spoCtx.Site.GetChanges($spocChangeQuery) | ||
$spoCtx.Load($spocChangesCollection) | ||
$spoCtx.ExecuteQuery() | ||
|
||
#We need to iterate through the $spcChangesCollection Object in order to get the Changes from the Change Log | ||
Write-Host "# of Changes found in the first batch " $spocChangesCollection.Count | ||
|
||
foreach($spocChange in $spocChangesCollection){ | ||
Write-Host "Change Type: " $spocChange.ChangeType " - Object Type: " $spocChange.TypedObject " - Change Date: " $spocChange.Time -Foregroundcolor White | ||
} | ||
|
||
$spoCtx.Dispose() | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Required Parameters | ||
$sSiteColUrl = "https://<O365Domain>.sharepoint.com/sites/<SiteCollection>" | ||
$sUserName = "<O365User>@<O365Domain>.onmicrosoft.com" | ||
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString | ||
$sCSOMPath="<CSOM_Path>" | ||
|
||
Get-SPOChangesLogForSC -sCSOMPath $sCSOMPath -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
############################################################################################################################################ | ||
# Script that allows to get all the external users in a SharePoint Online Tenant. | ||
# Required Parameters: | ||
# -> $sUserName: User Name to connect to the SharePoint Admin Center. | ||
# -> $sMessage: Message to show in the user credentials prompt. | ||
# -> $sSPOAdminCenterUrl: SharePoint Admin Center Url | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that gets all the external users in a SharePoint Online Tenant. | ||
function Get-SPOExternalUsers | ||
{ | ||
param ($sUserName,$sMessage,$sSPOAdminCenterUrl) | ||
try | ||
{ | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
Write-Host "Getting all the external users in a SharePoint Online Tenant" -foregroundcolor Green | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
$msolcred = Get-Credential -UserName $sUserName -Message $sMessage | ||
Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolcred | ||
Get-SPOExternalUser -Position 0 -PageSize 30 | Select DisplayName,EMail | Format-Table | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Connection to Office 365 | ||
$sUserName="[email protected]" | ||
$sMessage="Introduce your SPO Credentials" | ||
$sSPOAdminCenterUrl="https://nuberosnet-admin.sharepoint.com/" | ||
|
||
Get-SPOExternalUsers -sUserName $sUserName -sMessage $sMessage -sSPOAdminCenterUrl $sSPOAdminCenterUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
############################################################################################################################################ | ||
# Script that allows to get the members for each Office 365 Group defined in an Office 365 tenant. | ||
# Required Parameters: N/A. | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that allows to add to Office 365 the list of users contained in the CSV file. | ||
function Get-O365Members | ||
{ | ||
param ($sInputFile) | ||
try | ||
{ | ||
#Getting all the Groups in the tenant | ||
Write-Host "Getting all the members for each O365 Group in the tenant ..." -foregroundcolor Green | ||
$O365Groups=Get-UnifiedGroup | ||
# Deleting the users | ||
Write-Host "Adding the Office 365 users ..." -ForegroundColor Green | ||
foreach ($O365Group in $O365Groups) | ||
{ | ||
Write-Host "Members of Group: " $O365Group.DisplayName -ForegroundColor Green | ||
Get-UnifiedGroupLinks –Identity $O365Group.Identity –LinkType Members | ||
Write-Host | ||
} | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Connection to Office 365 | ||
$sUserName="<Your_Office365_Admin_Account>" | ||
$sMessage="Introduce your Office 365 Credentials" | ||
#Connection to Office 365 | ||
$msolCred = Get-Credential -UserName $sUserName -Message $sMessage | ||
Connect-MsolService -credential $msolCred | ||
|
||
#Getting Groups Information | ||
Get-O365Members | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
############################################################################################################################################ | ||
#Script that allows to get user profile information | ||
# Required Parameters: | ||
# -> $sCSOMPath: Path for the Client Side Object Model for SPO. | ||
# -> $sUserName: User Name to connect to the SharePoint Online Site Collection. | ||
# -> $sPassword: Password for the user. | ||
# -> $sSiteUrl: SharePoint Online Administration Url. | ||
############################################################################################################################################ | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that gets user profile information | ||
function Get-UserProfileInfo | ||
{ | ||
param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword) | ||
try | ||
{ | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
Write-Host "Getting the User Profile Information for current user" -foregroundcolor Green | ||
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green | ||
|
||
#Adding the Client OM Assemblies | ||
$sCSOMRuntimePath=$sCSOMPath + "\Microsoft.SharePoint.Client.Runtime.dll" | ||
$sCSOMUserProfilesPath=$sCSOMPath + "\Microsoft.SharePoint.Client.UserProfiles.dll" | ||
$sCSOMPath=$sCSOMPath + "\Microsoft.SharePoint.Client.dll" | ||
Add-Type -Path $sCSOMPath | ||
Add-Type -Path $sCSOMRuntimePath | ||
Add-Type -Path $sCSOMUserProfilesPath | ||
|
||
#SPO Client Object Model Context | ||
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) | ||
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword) | ||
$spoCtx.Credentials = $spoCredentials | ||
$spoUserProfilesLoader=[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($spoCtx) | ||
$spoProfile=$spoUserProfilesLoader.GetUserProfile() | ||
$spoCtx.Load($spoProfile) | ||
$spoCtx.ExecuteQuery() | ||
$spoProfile | ||
$spoCtx.Dispose() | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Required Parameters | ||
$sSiteUrl = "<https://<SPO_Site_Url> | ||
$sUserName = "<SPOUser>@<SPODomain>.onmicrosoft.com" | ||
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString | ||
$sCSOMPath="<CSOM_Path>" | ||
Get-UserProfileInfo -sCSOMPath $sCSOMPath -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ function ReadSPO-PropertyBags | |
try | ||
{ | ||
#Adding the Client OM Assemblies | ||
Add-Type -Path "E:\03 Docs\10 MVP\03 MVP Work\11 PS Scripts\Office 365\Microsoft.SharePoint.Client.dll" | ||
Add-Type -Path "E:\03 Docs\10 MVP\03 MVP Work\11 PS Scripts\Office 365\Microsoft.SharePoint.Client.Runtime.dll" | ||
Add-Type -Path "G:\03 Docs\10 MVP\03 MVP Work\11 PS Scripts\Office 365\Microsoft.SharePoint.Client.dll" | ||
Add-Type -Path "G:\03 Docs\10 MVP\03 MVP Work\11 PS Scripts\Office 365\Microsoft.SharePoint.Client.Runtime.dll" | ||
|
||
#SPO Client Object Model Context | ||
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) | ||
|
@@ -48,10 +48,10 @@ function ReadSPO-PropertyBags | |
} | ||
|
||
#Required Parameters | ||
$sSiteUrl = "https://<Office365Domain>.sharepoint.com/sites/CloudShare/" | ||
$sUserName = "<[email protected]>" | ||
$sSiteUrl = "https://fiveshareit.sharepoint.com/sites/mvpcluster/" | ||
$sUserName = "[email protected]" | ||
#$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString | ||
$sPassword=convertto-securestring "<Office365_Password>" -asplaintext -force | ||
$sPassword=convertto-securestring "647391&jc" -asplaintext -force | ||
|
||
ReadSPO-PropertyBags -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
############################################################################################################################################ | ||
# Script that allows to do work with Office 365 Groups using standard cmdlets for Groups | ||
# Required Parameters: N/A | ||
############################################################################################################################################ | ||
|
||
#Connection to Office 365 | ||
$msolCred = Get-Credential | ||
Connect-MsolService -Credential $msolCred | ||
|
||
#Definition of the function tthat allows to do work with Office 365 Groups using standard cmdlets for Groups | ||
function WorkWith-Office365Groups | ||
{ | ||
param ($sOperationType,$sGroupName,$sNewGroupName) | ||
try | ||
{ | ||
switch ($sOperationType) | ||
{ | ||
"Read" { | ||
Write-Host "Get all the Office 365 Groups in a tenant" -ForegroundColor Green | ||
Get-UnifiedGroup | ||
} | ||
"Create" { | ||
Write-Host "Creating a new Office 365 Group" -ForegroundColor Green | ||
New-UnifiedGroup –DisplayName $sGroupName | ||
} | ||
"Update" { | ||
Write-Host "Updating an Office 365 Group" -ForegroundColor Green | ||
#The change in the name can be seen in the O365 Admin Portal | ||
Set-UnifiedGroup -Identity $sGroupName -DisplayName $sNewGroupName | ||
} | ||
"Remove" { | ||
Write-Host "Removing an Office 365 Group" -ForegroundColor Green | ||
Remove-UnifiedGroup -Identity $sGroupName | ||
} | ||
default { | ||
Write-Host "Requested Operation not valid!!" -ForegroundColor DarkBlue | ||
} | ||
} | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Write-Host "-----------------------------------------------------------" -foregroundcolor Green | ||
Write-Host "Working with Groups through PowerShell." -foregroundcolor Green | ||
Write-Host "-----------------------------------------------------------" -foregroundcolor Green | ||
|
||
$sOperationType="Read" | ||
$sGroupName="O365 PowerShell Group" | ||
WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName | ||
$sOperationType="Create" | ||
WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName | ||
$sOperationType="Update" | ||
$sNewGroupName="Test PS" | ||
WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName -sNewGroupName $sNewGroupName | ||
$sOperationType="Remove" | ||
$sNewGroupName="Test PS" | ||
WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sNewGroupName |
Oops, something went wrong.