What happens with data that exists only locally on a Device? When users manually create a folder on their device, within the root directory of the SharePoint Synced OneDrive, it remains un-synced and lacks a backup.

I did some research, but was unable to prevent users being able to create folders. However, I was able to create a detection script. It’s a simple script, but can prevent users from losing important company data.

$onedrives = Get-ChildItem "C:\Users\*\OneDrive -*"
$alert = $false

$DIAG =@()

foreach ($onedrive in $onedrives) {
    $companyname = $onedrive.Name.TrimStart("OneDrive - ")
    Write-Output "Looping $($onedrive)"
    
    $children = get-childitem "$($onedrive.PSParentPath)\$companyname"

    foreach ($child in $children) {
        if (!($child.Mode.Contains("l"))) {
            $DIAG += "Unlinked folder detected: $($child.FullName)"
            $alert = $true
        }
    }
}

if ($alert -eq $true) {
    write-output $DIAG
    write-output "SharePoint unlinked folders detected"

    #Add some alert action here
    exit 1
}
  

When executed, it loops through the OneDrive folders for all users, grabs the company name, and checks if the folders are linked. If it detects an unlinked folder, it exits with code 1.

“C:\Users\JeremyPot\OneDrive – Prof-IT.Services”
Is translated to:
“C:\Users\JeremyPot\Prof-IT.Services”

Of course, you do want to change the script to suit your environment, either with a webhook or RMM alert.

.

.

Secure your data today, safeguarding against potential losses tomorrow.

.

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *