1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
######## #ODFB Rights Administration #Copyright: Free to use, please leave this header intact #Author: Jos Lieben (OGD) #Company: OGD (http://www.ogd.nl) #Script help: http://www.lieben.nu #Purpose: Give an administrator rights on all Onedrive for Business accounts ######## #Requirements: ######## <# Powershell 4 .NET 4.5 Sharepoint Online Management Shell (X64) http://www.microsoft.com/en-us/download/details.aspx?id=35588 Sharepoint Server 2013 Client Components http://www.microsoft.com/en-us/download/details.aspx?id=35585 run “Set-Executionpolicy Unrestricted” in an elevated powershell window Windows 7+ or Windows Server 2008+ #> $o365login = "admin@ogdemo1.onmicrosoft.com" #Username of O365 Admin $o365pw = "" #Password of O365 Admin $spAdminURL = "https://ogdemo1-admin.sharepoint.com" #URL to your SP Admin site $spMyURL = "https://ogdemo1-my.sharepoint.com" #URL to your SP MySites $logfile = "$($(get-location).path)\LogFile.txt" #Logfile in case of errors #Start script ac $logfile "-----$(Get-Date) ODFB_RA v0.1 $($env:COMPUTERNAME) Session log-----`n" #build Credential Object $secpasswd = ConvertTo-SecureString $o365pw -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential ($o365login, $secpasswd) #Load sharepoint module try { [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles") | Out-Null } catch { $errorstring = "ERROR: Failed to load Sharepoint Libraries, exiting" ac $logfile $errorstring Write-Host $errorstring Pause Exit } #load SPOnline module $env:PSModulePath += ";C:\Program Files\SharePoint Online Management Shell\" try { Import-Module Microsoft.Online.SharePoint.PowerShell } catch { $errorstring = "ERROR: Failed to load Sharepoint Online module, exiting" ac $logfile $errorstring ac $logfile $error[0] Write-Host $errorstring Pause Exit } #Build sP credential object $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($o365login,$secpasswd) #build proxy $proxyaddr = "$spAdminURL/_vti_bin/UserProfileService.asmx?wsdl" $UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False $UserProfileService.Credentials = $creds $strAuthCookie = $creds.GetAuthenticationCookie($spAdminURL) $uri = New-Object System.Uri($spAdminURL) $container = New-Object System.Net.CookieContainer $container.SetCookies($uri, $strAuthCookie) $UserProfileService.CookieContainer = $container try { $UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1) } catch { $errorstring = "Critical error, unable to get profiles" ac $logfile $errorstring ac $logfile $error[0] Write-Host $errorstring $error[0] Pause Exit } $NumProfiles = $UserProfileService.GetUserProfileCount() $i = 1 $ProfileURLs = @() Write-Host "Begin discovery of $NumProfiles profiles" While ($UserProfileResult.NextValue -ne -1) { Write-Host "Checking profile $i of $NumProfiles" $Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" } $Url= $Prop.Values[0].Value if ($Url) { Write-Host "Adding $Url to the list" $ProfileURLs += $Url } $UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue) $i++ } Write-Host "Finished discovery of profiles" Write-Host "Connecting to Sharepoint Online" try { Connect-SPOService -Url $spAdminURL -Credential $Credentials } catch { $errorstring = "Critical error, unable to Connect to Sharepoint Online" ac $logfile $errorstring ac $logfile $error[0] Write-Host $errorstring $error[0] Pause Exit } Write-Host "Start processing profiles" foreach ($profileURL in $ProfileURLs) { $fullPath = "$spMyURL$profileURL".TrimEnd("/") Write-Host "Processing $fullPath" try { Set-SPOUser -Site $fullPath -LoginName $o365login -IsSiteCollectionAdmin $true Write-Host "$o365login permissions added to $fullPath" } catch { $errorstring = "Failed adding $o365login permissions to $fullPath" ac $logfile $errorstring ac $logfile $error[0] Write-Host $errorstring $error[0] } } ac $logfile "Script finished" Write-Host "Job Finished" Pause Exit |
02_All_OneDrive_Private_Links.ps1
1 2 3 4 5 6 7 8 9 10 |
#Requires -RunAsAdministrator #Requires -Version 5.1.0 #Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | select Name,Version #Install-Module -Name Microsoft.Online.SharePoint.PowerShell Import-Module -Name Microsoft.Online.SharePoint.PowerShell $TenantUrl = Read-Host "Enter the SharePoint admin center URL" $LogFile = [Environment]::GetFolderPath("Desktop") + "\Source.log" Connect-SPOService -Url $TenantUrl Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" | Select -ExpandProperty Url | Out-File $LogFile -Force Write-Host "Done! File saved as $($LogFile)." |