1

Is there anyway an admin can hide 'Shared with Everyone' folder in Office 365 One Drive?

0

Found this post

<#
Remove a specified folder from OneDrive for Business Sites.

Authors:  Aaron Guilmette <aaron.guilmette@microsoft.com>
          Vaibhav Upadhyay <vaibhavu@microsoft.com>

The most recent update will always be at https://gallery.technet.microsoft.com/Remove-a-OneDrive-for-c6fd3c30.

- Changelog

v3  - Updated logging output.
v2  - Updated Client Components build link.
    - Deprecated -Username and -Password parameters in favor of a standard
      System.Management.Automation.PSCredential type.
#>

<#       
    .DESCRIPTION
    Removes folder from OneDrive for Business sites.

    .PARAMETER Credential
    Specify SharePoint or Global Administrator credential.

    .PARAMETER Tenant
    Specify Office 365 tenant name.  For example, if the Sharepoint
    Online site is 'contoso.onmicrosoft.com', 'contoso' is the tenant
    name.

    .PARAMETER InputFile
    Supply a CSV with the header 'userprincipalname' to process a subset
    of users. If a CSV is not supplied, all OneDrive sites are enumerated
    and processed.

    .PARAMETER GrantPermission
    Grants Site Collection Administrator permission to the administrator
    account specified in the -Username parameter. Recommended to set
    this switch if it is unknown if the admin user already has Site
    Collection Administrator permissions. If granted, it must be removed
    separately at this time.

    .PARAMETER FolderToDelete
    Specify name of folder in OneDrive for Business site to delete.

    .PARAMETER Confirm
    Confirm deletion of folder specified in -FolderToDelete parameter.

    .EXAMPLE
    $SpoAdmin = Get-Credential
    .\Remove-OneDriveForBusinessFolder.ps1 -Credential $SpoAdmin -Tenant contoso -FolderToDelete 'Shared with Everyone' -GrantPermission -LogFile contoso_od4b.log

    Enumerate all OneDrive for Business folders for tenant Contoso and save output to contoso_od4b.log.

    .LINK
    https://gallery.technet.microsoft.com/Remove-a-OneDrive-for-c6fd3c30
    #>
[Cmdletbinding()]
    Param (
        [Parameter(Mandatory=$true)]
            [System.Management.Automation.PSCredential]$Credential,

        [Parameter(mandatory=$true)]
            [String]$Tenant,

        [Parameter(mandatory=$false)]
        [ValidateScript({Test-Path $_;if (!((gc $_ | Select-Object -First 1) -like "*UserPrincipalName*")) 
            { Write-Host -Fore Red "Please make sure input CSV only contains header UserPrincipalName.";Break }})]
            [String]$InputFile,

        [Parameter(mandatory=$false)]
        [Switch]$GrantPermissions,

        [Parameter(mandatory=$false)]
        [String]$LogFile,

        [Parameter(Mandatory=$true,HelpMessage='Folder to delete')]
        [string]$FolderToDelete,

        [Parameter(Mandatory=$false,HelpMessage='Confirm removal of the folders')]
        [switch]$Confirm
        )

    begin 
        {        
        }
    process 
        {
        # Locating Sharepoint Server Client Components and loading
        Write-Host -Fore Yellow "Locating SharePoint Server Client Components installation..."
        If (Test-Path 'c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll')
            {
                Write-Host -ForegroundColor Green "Found SharePoint Server Client Components installation."
                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"
                Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
            }
        ElseIf
            ( $filename = Get-ChildItem 'C:\Program Files' -Recurse -ea silentlycontinue | where { $_.name -eq 'Microsoft.SharePoint.Client.DocumentManagement.dll' })
            {
                $Directory = $filename.DirectoryName
                Write-Host -ForegroundColor Green "Found SharePoint Server Client Components at $Directory."
                Add-Type -Path "$Directory\Microsoft.SharePoint.Client.dll" 
                Add-Type -Path "$Directory\Microsoft.SharePoint.Client.Runtime.dll" 
                Add-Type -Path "$Directory\Microsoft.SharePoint.Client.Taxonomy.dll"
                Add-Type -Path "$Directory\Microsoft.SharePoint.Client.UserProfiles.dll"
            }
        ElseIf
            (!(Test-Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'))
            {
                Write-Host -ForegroundColor Yellow "This script requires the SharePoint Server Client Components. Attempting to download and install."
                wget 'https://download.microsoft.com/download/E/1/9/E1987F6C-4D0A-4918-AEFE-12105B59FF6A/sharepointclientcomponents_15-4711-1001_x64_en-us.msi' -OutFile ./SharePointClientComponents_15.msi
                wget 'https://download.microsoft.com/download/B/3/D/B3DA6839-B852-41B3-A9DF-0AFA926242F2/sharepointclientcomponents_16-4002-1211_x64-en-us.msi' -OutFile ./SharePointClientComponents_16.msi
                msiexec /i SharePointClientComponents_15.msi /qb
                msiexec /i SharePointClientComponents_16.msi /qb
                Sleep 60
                If (Test-Path 'c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll')
                {
                    Write-Host -ForegroundColor Green "Found SharePoint Server Client Components."
                    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"
                    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
                }
                Else
                    { 
                        Write-Host -NoNewLine -ForegroundColor Red "Please download the SharePoint Server Client Components from "
                        Write-Host -ForegroundColor Yellow "https://download.microsoft.com/download/B/3/D/B3DA6839-B852-41B3-A9DF-0AFA926242F2/sharepointclientcomponents_16-4002-1211_x64-en-us.msi "
                        Write-Host -ForegroundColor Red "and try again."
                        Break
                    }
            }

        If 
            (!(Get-Module -ListAvailable "*online.sharepoint*")) 
                {
                Write-Host -ForegroundColor Yellow "This script requires the SharePoint Online Management Shell.  Attempting to download and install."
                wget 'https://download.microsoft.com/download/0/2/E/02E7E5BA-2190-44A8-B407-BC73CA0D6B87/sharepointonlinemanagementshell_4630-1200_x64_en-us.msi' -OutFile ./SharePointOnlineManagementShell.msi
                msiexec /i SharePointOnlineManagementShell.msi /qb
                Write-Host -ForegroundColor Yellow "Please close and reopen the Windows Azure PowerShell module and re-run this script."
                }

        # Create Log File
        If (!(Test-Path $LogFile))
            {
            Write-Host -ForegroundColor Yellow "Log file not found. Creating."
            $LogFileHeader = """" + "Folder" + """" + "," + """" + "User" + """" + "," + """" + "Path" + """" + "," + """" + "Action Taken" + """"
            $LogFileHeader | Out-File $LogFile
            }
        Else
            {
            Write-Host -ForegroundColor Yellow "Existing log file found. Appending."
            }

        # Define URLs
        $MySiteURL = "https://$tenant-my.sharepoint.com"
        $AdminURL = "https://$tenant-admin.sharepoint.com"

        # Define Contexts
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($MySiteURL)

        # Define Credentials
        $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.Username,$Credential.Password)
        $Context.Credentials = $Creds

        # Connect to SPO Service for granting permissions if necessary
        $SPOServiceCreds = $Credential
        Connect-SPOService -url $AdminURL -credential $SPOServiceCreds

        # Get OD4B WebSite Users
        $Users = $Context.Web.SiteUsers
        $Context.Load($Users)
        $Context.ExecuteQuery()
        $peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)

        # Check to see if there is an input file specified
        If ($InputFile)
            {
            $UserList = Import-Csv $InputFile -Header UserPrincipalName
            $i = 0
            foreach ($User in $Users)
                    {
                        $userProfile = $peopleManager.GetPropertiesFor($user.LoginName)
                        $Context.Load($userProfile)
                        $Context.ExecuteQuery()
                        if ($userList.UserPrincipalname -contains $userProfile.Email -and $userProfile.UserProfileProperties.PersonalSpace -ne "" )
                            {
                            $i++
                            $OD4BPath = $MySiteURL+$userProfile.UserProfileProperties.PersonalSpace
                            Write-Host $OD4BPath # $userProfile.UserProfileProperties.PersonalSpace
                            If ($GrantPermissions) 
                                {
                                Write-Host -ForegroundColor Green "Granting permissions on $OD4BPath"
                                Set-SPOUser -Site $OD4BPath -LoginName $Credential.Username -IsSiteCollectionAdmin $true | Out-Null
                                }

                            # If OD4BPath is present, enumerate folders
                            if ($OD4BPath) 
                                {
                                #Write-Host -ForegroundColor Cyan "User $($userprofile.Email) has a OneDrive for Business Site."
                                $ClientContextSource = New-Object Microsoft.SharePoint.Client.ClientContext($OD4BPath);
                                Write-Host "     URL is $OD4BPath";

                                $ClientContextSource.Credentials = $Creds
                                $ClientContextSource.ExecuteQuery()

                                $personalWeb = $ClientContextSource.Web
                                $ClientContextSource.Load($personalWeb)
                                $ClientContextSource.ExecuteQuery()

                                $docList = $personalWeb.Lists.GetByTitle("Documents")
                                $ClientContextSource.Load($docList)
                                $ClientContextSource.Load($personalWeb.Folders)
                                $ClientContextSource.ExecuteQuery()

                                $allFolders = $docList.RootFolder.Folders
                                $ClientContextSource.Load($allFolders)
                                $ClientContextSource.ExecuteQuery()

                                # Delete Specified Folder
                                foreach ($toBeDeleted in $allFolders)
                                            {
                                                #Write-Host "Examining Folder" $toBeDeleted.Name
                                                if ($toBeDeleted.Name -eq $FolderToDelete)
                                                {
                                                    Write-Host -Fore Green "     $($FolderToDelete) present in $OD4BPath"
                                                    If ($Confirm)
                                                        { 
                                                        Write-Host -ForegroundColor Cyan "     ** Confirm enabled. Deleting Folder " $toBeDeleted.Name
                                                        $toBeDeleted.DeleteObject()
                                                        $personalWeb.Update()
                                                        $ClientContextSource.ExecuteQuery()
                                                        If ($LogFile)
                                                            {
                                                            $logEntry = """" + $FolderToDelete + """" + "," + """" + $userprofile.email + """" + "," + """" + $OD4BPath + """" + "," + """" + "Folder Deleted." + """"
                                                            $logEntry | Out-File $LogFile -Append -Force
                                                            $logEntry = $null
                                                            }
                                                        }
                                                    Else
                                                        { 
                                                        Write-Host -ForegroundColor Yellow "No action taken."
                                                        $logEntry = """" + $FolderToDelete + """" + "," + """" + $userprofile.email + """" + "," + """" + $OD4BPath + """" + "," + """" + "No action taken." + """"
                                                        $logEntry | Out-File $LogFile -Append -Force
                                                        $logEntry = $null
                                                        }
                                                }
                                            }
                                }
                            }
                    }
        Write-Host "Matching Onedrive for Business sites:"$i
            }
        Else
            {
            $i = 0

            foreach ($User in $Users)
                    {
                        $userProfile = $peopleManager.GetPropertiesFor($user.LoginName)
                        $Context.Load($userProfile)
                        $Context.ExecuteQuery()
                        if ($userProfile.Email -ne $null -and $userProfile.UserProfileProperties.PersonalSpace -ne "" )
                            {
                            $i++
                            $OD4BPath = $MySiteURL+$userProfile.UserProfileProperties.PersonalSpace
                            Write-Host $OD4BPath # $userProfile.UserProfileProperties.PersonalSpace
                            If ($GrantPermissions) 
                                {
                                Write-Host -ForegroundColor Green "Granting permissions on $OD4BPath"
                                Set-SPOUser -Site $OD4BPath -LoginName $Credential.Username -IsSiteCollectionAdmin $true | Out-Null
                                }

                            # If OD4BPath is present, enumerate folders
                            if ($OD4BPath) 
                                {
                                #Write-Host -ForegroundColor Cyan "User $($userprofile.Email) has a OneDrive for Business Site."
                                $ClientContextSource = New-Object Microsoft.SharePoint.Client.ClientContext($OD4BPath);
                                Write-Host "     URL is $OD4BPath";

                                $ClientContextSource.Credentials = $Creds
                                $ClientContextSource.ExecuteQuery()

                                $personalWeb = $ClientContextSource.Web
                                $ClientContextSource.Load($personalWeb)
                                $ClientContextSource.ExecuteQuery()

                                $docList = $personalWeb.Lists.GetByTitle("Documents")
                                $ClientContextSource.Load($docList)
                                $ClientContextSource.Load($personalWeb.Folders)
                                $ClientContextSource.ExecuteQuery()

                                $allFolders = $docList.RootFolder.Folders
                                $ClientContextSource.Load($allFolders)
                                $ClientContextSource.ExecuteQuery()

                                # Delete Specified Folder
                                foreach ($toBeDeleted in $allFolders)
                                            {
                                                #Write-Host "Examining Folder" $toBeDeleted.Name
                                                if ($toBeDeleted.Name -eq $FolderToDelete)
                                                {
                                                    Write-Host -Fore Green "     $($FolderToDelete) present in $OD4BPath"
                                                    If ($Confirm)
                                                        { 
                                                        Write-Host -ForegroundColor Cyan "     ** Confirm enabled. Deleting Folder " $toBeDeleted.Name
                                                        $toBeDeleted.DeleteObject()
                                                        $personalWeb.Update()
                                                        $ClientContextSource.ExecuteQuery()
                                                        If ($LogFile)
                                                            {
                                                            $logEntry = """" + $FolderToDelete + """" + "," + """" + $userprofile.email. + """" + "," + """" + $OD4BPath + """" + "," + """" + "Folder Deleted." + """"
                                                            $logEntry | Out-File $LogFile -Append -Force
                                                            $logEntry = $null
                                                            }
                                                        }
                                                    Else
                                                        { 
                                                        Write-Host -ForegroundColor Yellow "No action taken."
                                                        $logEntry = """" + $FolderToDelete + """" + "," + """" + $userprofile.email + """" + "," + """" + $OD4BPath + """" + "," + """" + "No action taken." + """"
                                                        $logEntry | Out-File $LogFile -Append -Force
                                                        $logEntry = $null
                                                        }
                                                }
                                            }
                                }
        #####
        #Write-Host "Matching Onedrive for Business sites:"$i
                }
            }

        }
    }

https://gallery.technet.microsoft.com/Remove-a-OneDrive-for-c6fd3c30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.