Disable OneDrive Sync for SharePoint Online Site Libraries


https://gallery.technet.microsoft.com/Disable-OneDrive-Sync-for-71f99ceb

Write-Host “Please Enter SharePoint Online Service Administrator Credentials!”
$Creds = Get-Credential

$SuperAdmin = “SCAadmin@tenant.onmicrosoft.com”

$AdminUrl = ‘https://admin.sharepoint.com’

Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll”

Connect-SPOService -Url $AdminUrl -Credential $Creds
$spocredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Creds.UserName , $Creds.Password)

$Sites = Get-SPOSite -Limit All | Select-Object Url
Write-Host “Total Sites are ” $Sites.Count -ForegroundColor Green

foreach($Site in $Sites)
{
    try
    {
        Set-SPOUser -Site $Site.Url -LoginName $SuperAdmin -IsSiteCollectionAdmin $true -Verbose
        $SiteUrl = $Site.Url
        Write-Host $SiteUrl

        #Get the Client Context and Bind the Site Collection
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
        $ctx.Credentials = $spocredentials
        #Authenticate
        $Rootweb = $ctx.Site.RootWeb
        $ctx.Load($Rootweb)
        $ctx.Load($Rootweb.Webs)
        $ctx.ExecuteQuery()

        Write-Host $Rootweb.Title
        write-host $Rootweb.ExcludeFromOfflineClient

        $Rootweb.ExcludeFromOfflineClient = $true
        $Rootweb.Update()
        $ctx.ExecuteQuery()

        #Fetch the users in Site Collection
        foreach($web in $Rootweb.Webs)
        {
            try
            {
                $ctx.Load($Web)
                $ctx.ExecuteQuery()
                Write-Host $web.Title
                write-host $web.ExcludeFromOfflineClient
                $web.ExcludeFromOfflineClient = $true
                $web.Update()
                $ctx.ExecuteQuery()
            }
            catch
            {
                Write-Host “Exception at Sub Web. Script will continue” -ForegroundColor Red
            }
        }

    }
    catch
    {
        Write-Host “Exception at Root Web. Script will continue” -ForegroundColor Red
    }
}

Export Office 365 User Roles and Members to Text or CSV file


$Creds = Get-Credential -Message “Please enter SharePoint Online Administrator User and password.”
Connect-MsolService -Credential $Creds

$Roles = Get-MsolRole | ? Name -Like “*”
foreach($Role in $Roles)
{
    $RoleName = $Role.Name
    $Members = Get-MsolRoleMember -RoleObjectId $Role.ObjectId
    if($Members)
    {
        $Role.Name | Out-File -FilePath C:\Scripts\Admins.txt -Append -Encoding default -Force
        $Members | Out-File -FilePath C:\Scripts\Admins.txt -Append -Encoding default -Force
    }
    else
    {
        $Role.Name | Out-File -FilePath C:\Scripts\Admins.txt -Append -Encoding default -Force
        “No Members” | Out-File -FilePath C:\Scripts\Admins.txt -Append -Encoding default -Force
    }

}

# You can also create a better CSV

$UserRoles = @()
$Roles = Get-MsolRole | ? Name -Like “*”
foreach($Role in $Roles)
{
    $RoleName = $Role.Name
    $Members = Get-MsolRoleMember -RoleObjectId $Role.ObjectId
    if($Members)
    {
        foreach($Member in $Members)
        {
            $Role = New-Object PSObject
            Add-Member -input $Role noteproperty ‘RoleName’ $RoleName
            Add-Member -input $Role noteproperty ‘RoleMemberType’ $Member.RoleMemberType
            Add-Member -input $Role noteproperty ‘EmailAddress’ $Member.EmailAddress
            Add-Member -input $Role noteproperty ‘DisplayName’ $Member.DisplayName
            Add-Member -input $Role noteproperty ‘isLicensed’ $Member.isLicensed
            $UserRoles += $Role
        }
    }
    else
    {
        $Role = New-Object PSObject
        Add-Member -input $Role noteproperty ‘RoleName’ $RoleName
        Add-Member -input $Role noteproperty ‘RoleMemberType’ “”
        Add-Member -input $Role noteproperty ‘EmailAddress’ “”
        Add-Member -input $Role noteproperty ‘DisplayName’ “”
        Add-Member -input $Role noteproperty ‘isLicensed’ “”
        $UserRoles += $Role
    }
}
$UserRoles | Out-GridView

Export Office365 User Roles to CSV


$User = “user@tenant.onmicrosoft.com”
#$User = Read-host “Please enter Office365 Admin User name username@domain.onmicrosoft.com. “
$Creds = Get-Credential

#Connect-SPOService -Url https://tenant-admin.sharepoint.com -Credential $Creds
Connect-MsolService -Credential $Creds

$AllUserRoles = @()

$Users = Get-MsolUser -All
foreach($user in $Users)
{
    $UserRoles = Get-MsolUserRole -UserPrincipalName $User.UserPrincipalName
    foreach($role in $UserRoles)
    {
        $aRole = New-Object PSObject
        $UserName = $User.UserPrincipalName
        $RoleName = $role.Name.ToString()

        Add-Member -input $aRole noteproperty ‘UserName’ $UserName
        Add-Member -input $aRole noteproperty ‘RoleName’ $RoleName
        $AllUserRoles += $aRole
    }
}

$AllUserRoles | export-csv -Path C:\Scripts\SPOUserRoles.csv -NoTypeInformation -Force

Export All SharePoint Online Term Group, Term Sets and Terms to CSV


param (
    [Parameter(Mandatory=$true)]
        [string]$RootSiteCollectionUrl
)

# Paths to SDK. Please verify location on your computer.
Add-Type -Path “c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
Add-Type -Path “c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll”

$Credentials = Get-Credential -Message “Please enter SPO Admin User Name and Password”
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($RootSiteCollectionUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credentials.UserName, $Credentials.Password)
$ctx.ExecuteQuery() 

$session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx)
$ctx.Load($session)
$ctx.ExecuteQuery()

$termstore = $session.GetDefaultSiteCollectionTermStore();
$ctx.Load($termstore)
$ctx.ExecuteQuery()

  $groups=$termstore.Groups
  $ctx.Load($groups)

  $ctx.ExecuteQuery()

  $Termstring = “”
  $Header=”TermGroup,TermSet,Term`r`n”
  $Termstring = $Header
  foreach($group in $groups)
  {
    $ctx.Load($group)
    $ctx.Load($group.TermSets)
    $ctx.ExecuteQuery()
    Write-Output $group.Name
    $Termstring +=”$($group.Name)`r`n”
    foreach($termset in $group.TermSets)
    {
        Write-Output ”    $($termset.Name)”
        $Termstring +=”,$($termset.Name)`r`n”
        $ctx.Load($termset)
        $ctx.Load($termset.Terms)
        $ctx.ExecuteQuery()
        foreach($term in $termset.Terms)
        {
            Write-Output ”        $($term.Name)”
            $Termstring +=”,,$($term.Name)`r`n”
        }
    }
  }

Out-File -InputObject $Termstring C:\Scripts\Terms.csv -Encoding ascii -Force
C:\Scripts\Terms.csv

List and Export External Users to CSV


This windows application allows SharePoint Online Administrators to list and export all external users to CSV.  You can run the script to iterate all site collections or against the list provided as CSV.  You can double click on a row to open external user management in internet explorer.  Next steps for me would be to allow you to remove the user without going to the site.

I have tested this tool with tenants of 4K and 10K sites without any issue.

Note: The Root Site Collection URL must be SharePoint Admin Url. Not the root site collection url as asked

#To Generate the Input CSV

$SitesToAudit

= Get-SPOSite -Limit All | Where-Object {$_.SharingCapability –ne “Disabled”}

$SitesToAudit

| Select Url | Export-Csv -Path C:\Scripts\InputCSV.csv -NoTypeInformation -Verbose -Force

image

https://gallery.technet.microsoft.com/office/List-and-Export-SharePoint-d670dc40

Enable Auditing – SharePoint Online Site Collection


Auditing is normally a required feature for most organization which wants to track user actions on a SharePoint site.  The functionality can be enabled at site collection level.  But most organizations try to enable it when they already have large number of of site collections.  Doing it manually by going to Site settings – Site collection audit settings would be a tough job if you have large number of site collections.  I wrote the script which may help someone.

The script uses both Client Side Object Model and SharePoint Online Management Shell cmdlets.  Make sure you change the location of SharePoint Client OM dlls.  I have set it as C:\CSOM.  You do not need to specify the Admin Url as I am creating it from User name.

function Enable-SPOAuditing
{
    <#
        .SYNOPSIS
        Enables or disables Auditing on SharePoint ONline Sites
        .DESCRIPTION
        Enables or disables Auditing on SharePoint ONline Sites
        .EXAMPLE
        Enable-SPOAuditing
        explains how to use the command
        can be multiple lines
        .EXAMPLE
        Enable-SPOAuditing
        another example
        can have as many examples as you like
    #>
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [System.String]
        $SPOSiteUrl,
        [Parameter(Mandatory=$true)]
        [System.String]
        $UserName,
        [Parameter(Mandatory=$true)]
        [System.Security.SecureString]
        $Password
    )
    $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOSiteUrl)
    $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password)
    #SPO Client Object Model Context
    $spoCtx.Credentials = $spoCredentials
    $spoSite = $spoCtx.Site
    $spoCtx.Load($spoSite)
    $Audit = $spoSite.Audit
    $spoCtx.Load($Audit)
    $spoCtx.ExecuteQuery
    $All = [Microsoft.SharePoint.Client.AuditMaskType]::All;
    $None = [Microsoft.SharePoint.Client.AuditMaskType]::None;
    $CheckIn = [Microsoft.SharePoint.Client.AuditMaskType]::CheckIn;
    $CheckOut = [Microsoft.SharePoint.Client.AuditMaskType]::CheckOut;
    $ChildDelete = [Microsoft.SharePoint.Client.AuditMaskType]::ChildDelete;
    $CheckIn = [Microsoft.SharePoint.Client.AuditMaskType]::CopyCheckIn;
    $Move = [Microsoft.SharePoint.Client.AuditMaskType]::Move;
    $ObjectDelete = [Microsoft.SharePoint.Client.AuditMaskType]::ObjectDelete;
    $ProfileChange = [Microsoft.SharePoint.Client.AuditMaskType]::ProfileChange;
    $SchemaChange = [Microsoft.SharePoint.Client.AuditMaskType]::SchemaChange;
    $Search = [Microsoft.SharePoint.Client.AuditMaskType]::Search;
    $SecurityChange = [Microsoft.SharePoint.Client.AuditMaskType]::SecurityChange;
    $Undelete = [Microsoft.SharePoint.Client.AuditMaskType]::Undelete;
    $Update = [Microsoft.SharePoint.Client.AuditMaskType]::Update;
    $View = [Microsoft.SharePoint.Client.AuditMaskType]::View;
    $Workflow = [Microsoft.SharePoint.Client.AuditMaskType]::Workflow;
    $Audit.AuditFlags = $Search, $Update, $Undelete, $Workflow, $SecurityChange
    $Audit.Update()
    $spoSite.AuditLogTrimmingRetention = 60
    $spoSite.TrimAuditLog = $true
    #Enable All Options Auditing
    $Audit.AuditFlags = $All
    $Audit.Update()
    #Disable Auditing
    $Audit.AuditFlags = $None
    $Audit.Update()
    $spoCtx.ExecuteQuery()
}

$User = “firstnane.lastname@domain.onmicrosoft.com”
$Password = ConvertTo-SecureString “pass@word1” -AsPlainText –Force

#Or Use Get-Credentials to create the object.
$Creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Password

$CSOMAssembliesPath=”C:\CSOM”

$ClientDllPath         = $CSOMAssembliesPath +  “\Microsoft.SharePoint.Client.dll”
$ClientRunTimeDllPath  = $CSOMAssembliesPath +  “\Microsoft.SharePoint.Client.Runtime.dll”       
Add-Type -Path $ClientDllPath -ErrorAction SilentlyContinue
Add-Type -Path $ClientRunTimeDllPath -ErrorAction SilentlyContinue

$AdminUrl = $User
$AtSepPostion = $AdminUrl.IndexOf(‘@’) + 1
$DotPostion = $AdminUrl.LastIndexOf(“.onmicrosoft”)
$DomainName = $AdminUrl.Substring($AtSepPostion, $DotPostion – $AtSepPostion)
$FinalAdminUrl = “https://$DomainName-admin.sharepoint.com”

Connect-SPOService -Url $FinalAdminUrl -Credential $Creds
#To Test

#$Sites = Get-SPOSite -Limit 1

$Sites = Get-SPOSite -Limit All | Select Title, Url, Owner

foreach($Site in $Sites)
{
    Enable-SPOAuditing -SPOSiteUrl $Site.Url -UserName $User -Password $Password
}

Microsoft Office Developer Tools Preview 2 for Visual Studio 2015


https://www.microsoft.com/en-us/download/details.aspx?id=51683

This preview ships with new templates that support SharePoint 2016 for SharePoint solutions and add-ins.

Microsoft Office Developer Tools Preview 2 for Visual Studio 2015 enables you to develop SharePoint solutions and add-ins for SharePoint 2016.
This preview also includes the latest features in Microsoft Office Developer Tools Update 2 for Visual Studio 2015–you can create new Office add-in projects using templates specific to an Office application (Word, Excel, Outlook, and PowerPoint). These new templates support new Office features such as add-in commands, Fabric UI, and new functionalities in Office.js.
This preview must be installed on top of an earlier version of the Microsoft Office Developer Tools for Visual Studio 2015. Before installing this preview, go to aka.ms/officedevtoolsforvs2015 to get the tools.