SimpleHelp Community

Toolbox powershell adding RegKeys


#1

(To Support and anyone else)

This tool would be for turning on Storage Sense and forcing onedrive to keep files in the cloud after 30days

Here is the power shell script tool that uses Set-ItemProperty (we know the command works) when manually run in powershell direct on the device - its just 8 different keys being created keys (without var)

when running via Toolbox - One gets added others are missed, yet i can copy and paste the all commands manually to onto the computer in powershell - it work fine.

At the moment we just grabbed a Reg fragment to do the same thing, but would like powershell as its cleaner

as you can see we tried adding the full key halfway down, nothing gets added, (rebooted computer, nothing in the key,

anyone shed some light please?

***********************************************************

* Enable Windows 10/11 Storage Sense *

* 1 Delete temporary files that my apps aren’t using *

* 2 Delete files in recycle bin *

* 3 Delete files in Downloads folder *

***********************************************************

Enable Storage Sense

Ensure the StorageSense key exists

$key = “HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense”
If (!(Test-Path “$key”)) {
New-Item -Path “$key” | Out-Null
}
If (!(Test-Path “$key\Parameters”)) {
New-Item -Path “$key\Parameters” | Out-Null
}
If (!(Test-Path “$key\Parameters\StoragePolicy”)) {
New-Item -Path “$key\Parameters\StoragePolicy” | Out-Null
}

Set Storage Sense settings

Enable Storage Sense

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “01” -Type DWord -Value 1

Set ‘Run Storage Sense’ to Every Week

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “2048” -Type DWord -Value 30

Enable ‘Delete temporary files that apps aren’t using’

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “04” -Type DWord -Value 1

Set ‘Delete files in recycle bin if they have been there for over’ to 14 days

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “08” -Type DWord -Value 1
Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “256” -Type DWord -Value 14

Set ‘Delete files in my Downloads folder if they have been there for over’ to 60 days

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “32” -Type DWord -Value 1
Set-ItemProperty -Path “HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy” -Name “512” -Type DWord -Value 60

Set value that Storage Sense has already notified the user

Set-ItemProperty -Path “$key\Parameters\StoragePolicy” -Name “StoragePoliciesNotified” -Type DWord -Value 1

END


#2

bump? I’d love to use this once it’s working


#3

Thanks for the Bump

if we open powershell as admin and paste all the command in one go that works - but using it as a toolbox commands are skipped even running it as admin or service user


#4

You have to replace the fancy quote to regular quotes "


#5

As a troubleshooting tip, enable powershell debug.

Set this at the start of your script:
Set-PSDebug -Trace 1
or
Set-PSDebug -Trace 2

That will enable powershell debug and then output it to the console. So now instead of just getting Tool finished with 0. You will see what is happening.


#6

Forgot to add.
Since your script is using registry key HKCU, you will want to run as the currently logged in user.


Other wise you will need to modify your script.