2017-01-26 20:59:18 +01:00
function Set-StorageSense {
<#
. SYNOPSIS
Configures the Storage Sense options in Windows 10
. DESCRIPTION
This function can configure Storage Sense options in Windows 10 . It allows to enable / disable this feature
2017-01-26 21:14:55 +01:00
. PARAMETER EnableStorageSense
Enables storage sense setting , automatically cleaning up space on your system
2017-01-26 20:59:18 +01:00
2017-01-26 21:14:55 +01:00
. PARAMETER DisableStorageSense
Disables storage sense setting , not automatically cleaning up space on your system
2017-01-26 20:59:18 +01:00
2017-01-26 21:14:55 +01:00
. PARAMETER RemoveAppFiles
Configures the 'Delete temporary files that my apps aren' t using ' to either true or false
2017-01-26 20:59:18 +01:00
2017-01-26 21:14:55 +01:00
. PARAMETER ClearRecycleBin
Configures the 'Delete files that have been in the recycle bin for over 30 days' to either true or false
2017-01-26 20:59:18 +01:00
. NOTES
Name : Set-StorageSense
Author : Jaap Brasser
DateCreated : 2017 - 01 - 26
DateUpdated : 2017 - 01 - 26
Version : 1.0 . 0
Blog : http : / / www . jaapbrasser . com
. LINK
http : / / www . jaapbrasser . com
. EXAMPLE
2017-01-26 21:14:55 +01:00
Set-StorageSense -DisableStorageSense
2017-01-26 20:59:18 +01:00
Description
- - - - - - - - - - -
2017-01-26 21:14:55 +01:00
Disables Storage Sense on the system
2017-01-26 20:59:18 +01:00
. EXAMPLE
2017-01-26 21:14:55 +01:00
Set-StorageSense -EnableStorageSense -RemoveAppFiles $true
2017-01-26 20:59:18 +01:00
Description
- - - - - - - - - - -
2017-01-26 21:14:55 +01:00
Enables Storage Sense on the system and sets the 'Delete temporary files that my apps aren' t using ' to enabled
2017-01-26 20:59:18 +01:00
. EXAMPLE
2017-01-26 21:14:55 +01:00
Set-StorageSense -DisableStorageSense -RemoveAppFiles $true -ClearRecycleBin $true -Verbose
2017-01-26 20:59:18 +01:00
Description
- - - - - - - - - - -
2017-01-26 21:14:55 +01:00
Disables Storage Sense on the system and sets both the 'Delete temporary files that my apps aren' t using ' and the ' Delete files that have been in the recycle bin for over 30 days ' to enabled
2017-01-26 20:59:18 +01:00
#>
[ cmdletbinding ( SupportsShouldProcess = $true ) ]
param (
[ Parameter (
Mandatory = $true ,
ParameterSetName = 'StorageSense On'
) ]
[ switch ] $EnableStorageSense ,
[ Parameter (
Mandatory = $true ,
ParameterSetName = 'StorageSense Off'
) ]
2017-01-26 21:14:55 +01:00
[ switch ] $DisableStorageSense ,
2017-01-26 20:59:18 +01:00
[ Parameter (
Mandatory = $false ,
ParameterSetName = 'StorageSense On'
) ]
[ Parameter (
Mandatory = $false ,
ParameterSetName = 'StorageSense Off'
) ]
[ Parameter (
Mandatory = $false ,
2017-01-26 21:14:55 +01:00
ParameterSetName = 'Configure StorageSense'
2017-01-26 20:59:18 +01:00
) ]
2017-01-26 21:14:55 +01:00
[ bool ] $RemoveAppFiles ,
2017-01-26 20:59:18 +01:00
[ Parameter (
Mandatory = $false ,
ParameterSetName = 'StorageSense On'
) ]
[ Parameter (
Mandatory = $false ,
2017-01-26 21:14:55 +01:00
ParameterSetName = 'StorageSense Off'
2017-01-26 20:59:18 +01:00
) ]
[ Parameter (
Mandatory = $false ,
2017-01-26 21:14:55 +01:00
ParameterSetName = 'Configure StorageSense'
2017-01-26 20:59:18 +01:00
) ]
2017-01-26 21:14:55 +01:00
[ bool ] $ClearRecycleBin
2017-01-26 20:59:18 +01:00
)
begin {
$RegPath = @ {
2017-01-26 21:14:55 +01:00
StorageSense = '01'
TemporaryApp = '04'
RecycleBin = '08'
2017-01-26 20:59:18 +01:00
}
$SetRegistrySplat = @ {
Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy\'
Name = $null
2017-01-26 21:14:55 +01:00
Value = $null
2017-01-26 20:59:18 +01:00
}
function Set-RegistryValue {
param (
[ string ] $Path ,
[ string ] $Name ,
[ string ] $Value
)
if ( -not ( Test-Path -Path $Path ) ) {
2017-01-26 21:14:55 +01:00
if ( $PSCmdlet . ShouldProcess ( " $Path $Name : $Value " , 'Creating registry key' ) ) {
2017-01-26 20:59:18 +01:00
$null = New-Item -Path $Path -Force
}
}
2017-01-26 21:14:55 +01:00
if ( $PSCmdlet . ShouldProcess ( " $Path $Name : $Value " , 'Updating registry value' ) ) {
2017-01-26 20:59:18 +01:00
$null = Set-ItemProperty @PSBoundParameters -Force
}
}
}
process {
2017-01-26 21:14:55 +01:00
switch ( 1 ) {
{ $PsCmdlet . ParameterSetName -eq 'StorageSense On' } {
$SetRegistrySplat . Name = $RegPath . StorageSense
$SetRegistrySplat . Value = 1
Set-RegistryValue @SetRegistrySplat
2017-01-26 20:59:18 +01:00
}
2017-01-26 21:14:55 +01:00
{ $PsCmdlet . ParameterSetName -eq 'StorageSense Off' } {
$SetRegistrySplat . Name = $RegPath . StorageSense
$SetRegistrySplat . Value = 0
Set-RegistryValue @SetRegistrySplat
2017-01-26 20:59:18 +01:00
}
2017-01-26 21:14:55 +01:00
{ $PSBoundparameters . Keys -contains 'RemoveAppFiles' } {
$SetRegistrySplat . Name = $RegPath . TemporaryApp
$SetRegistrySplat . Value = [ int ] $RemoveAppFiles
Set-RegistryValue @SetRegistrySplat
2017-01-26 20:59:18 +01:00
}
2017-01-26 21:14:55 +01:00
{ $PSBoundparameters . Keys -contains 'ClearRecycleBin' } {
$SetRegistrySplat . Name = $RegPath . RecycleBin
$SetRegistrySplat . Value = [ int ] $ClearRecycleBin
Set-RegistryValue @SetRegistrySplat
2017-01-26 20:59:18 +01:00
}
}
}
}