Last active
April 16, 2024 23:29
-
-
Save ekky1328/146513b852cef21a917cb1d9ecb25d9a to your computer and use it in GitHub Desktop.
Configure Storage Sense Settings, including Locally available cloud content preferences
This file contains hidden or 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
<# | |
.SYNOPSIS | |
Configures Storage Sense Settings, including locally availabel cloud content preferences for Windows 10 / Windows Server 2019 | |
.EXAMPLE | |
.\storage-sense-configuration-via-registry.ps1 | |
.LINK | |
Email: Christopher Talke <[email protected]> | |
Github Gist: https://gist.github.com/christopher-talke/146513b852cef21a917cb1d9ecb25d9a | |
#> | |
$storagePolicy = "HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy" | |
# Enabling Storange Sense: | |
# 0x00000000 = Disabled | |
# 0x00000001 = Enabled | |
Set-ItemProperty $storagePolicy -Name "01" -Value 0x00000001; | |
# Delete temporary files that my apps aren’t using: | |
# 0x00000000 = Disabled | |
# 0x00000001 = Enabled | |
Set-ItemProperty $storagePolicy -Name "04" -Value 0x00000001; | |
# Delete files in my recycle bin if they have been there for over | |
# 0x00000000 = Never | |
# 0x00000001 = 1 Day | |
# Please note: 0x00000001 needs to be set if you want to utilise more than 1 Day with value "256" | |
Set-ItemProperty $storagePolicy -Name "08" -Value 0x00000001; | |
# Delete files in my recycle bin if they have been there for over | |
# 0x00000000 = Never | |
# 0x00000001 = 1 Day | |
# 0x0000000E = 14 Days | |
# 0x0000001E = 30 Days | |
# 0x0000003C = 60 Days | |
# Please Note: Value "04" needs to be set as a REG_DWORD with a data value of 0x00000001 in order for this to work for 1 Day or More, likewise for Never being 0x00000000 | |
Set-ItemProperty $storagePolicy -Name "256" -Value 0x00000001; | |
# Delete files in my Downloads folder if they have been there for over | |
# 0x00000000 = Never | |
# 0x00000001 = 1 Day | |
# Please note: 0x00000001 needs to be set if you want to utilise more than 1 Day with value "512" | |
Set-ItemProperty $storagePolicy -Name "32" -Value 0x00000001; | |
# Delete files in my Downloads folder if they have been there for over | |
# 0x00000000 = Never | |
# 0x00000001 = 1 Day | |
# 0x0000000E = 14 Days | |
# 0x0000001E = 30 Days | |
# 0x0000003C = 60 Days | |
# Please Note: Value "32" needs to be set as a REG_DWORD with a data value of 0x00000001 in order for this to work for 1 Day or More, likewise for Never being 0x00000000 | |
Set-ItemProperty $storagePolicy -Name "512" -Value 0x0000000E; | |
# Run Storage Sense | |
# 0x00000001 = Everyday | |
# 0x00000007 = Every 7 Days | |
# 0x0000001E = Every Month | |
# 0x00000000 = During Low Disk Space | |
Set-ItemProperty $storagePolicy -Name "2048" -Value 0x00000001; | |
# Find the current logged-in user, and locate the associated Security Identifier | |
$userSID = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value.Trim() | |
# Find all the mapped OneDrive Account ID's, and ensure the StoragePolicy Registry Keys and Values are set | |
$oneDriveAccounts = Get-ChildItem "HKCU:\software\Microsoft\OneDrive\Accounts" | Where-Object {$_.Name -Match "Business" -or $_.Name -Match "Personal"} | Select-Object PSPath | |
forEach ($accounts in $oneDriveAccounts) { | |
$accountPath = $accounts.PSPath.Split('HKEY_CURRENT_USER')[-1] | |
$accountKey = ($accounts.PSPath -split '\\')[-1] | |
$scopeIDPath = "HKCU:$accountPath\ScopeIdToMountPointPathCache" | |
if (Test-Path $scopeIDPath) { | |
(Get-ItemProperty $scopeIDPath).PSObject.Properties | ForEach-Object { | |
if ($_.Name -NotMatch "PS") { | |
$OneDriveID = "OneDrive!$($userSID)!$accountKey|$($_.Name)" | |
$BuiltPath = "$storagePolicy\$OneDriveID" | |
if ($OneDriveID -eq "OneDrive!!$accountKey|") { | |
Write-Error 'There was a problem consolidating the OneDrive Account ID' | |
} | |
if ((Test-Path $BuiltPath) -eq $false) { | |
New-Item -Path $storagePolicy -Name $OneDriveID -Force | |
} | |
# Content will becme online-only if not opened for more than: | |
# 0x00000000 = Disabled | |
# 0x00000001 = Enabled | |
Set-ItemProperty $BuiltPath -Name "02" -Value 0x00000001; | |
# Content will becme online-only if not opened for more than: | |
# 0x00000001 = 1 Day | |
# 0x0000000E = 14 Days | |
# 0x0000001E = 30 Days | |
# 0x0000003C = 60 Days | |
Set-ItemProperty $BuiltPath -Name "128" -Value 0x00000001; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment