Last active
February 22, 2020 19:48
-
-
Save iyre/0b9198e821ff483c1a461553518cc372 to your computer and use it in GitHub Desktop.
Add or remove libraries listed in 'This PC'
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
### Usage: | |
## Import functions | |
# >. .\Set-ThisPcLibrary.ps1 | |
## Add library to 'This PC' | |
# >Set-ThisPcItem pictures | |
# Pictures | |
## Remove specific library | |
# >Set-ThisPcItem -Remove pic | |
# Pictures | |
## Remove all libraries | |
# >Set-ThisPcItem -Remove | |
# Desktop | |
# ... | |
# Videos | |
$ThisPcPaths = | |
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\", # 32-bit path | |
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\" # 64-bit path | |
$ThisPcRegLib = @{ | |
# Major Version 10 (Windows 10 and Server 2016) | |
"10" = @{ | |
"3D Objects" = "{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" | |
"Desktop" = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" | |
"Documents" = "{D3162B92-9365-467A-956B-92703ACA08AF}" | |
"Downloads" = "{088E3905-0323-4B02-9826-5D99428E115F}" | |
"Music" = "{3DFDF296-DBEC-4FB4-81D1-6A3438BCF4DE}" | |
"Pictures" = "{24AD3AD4-A569-4530-98E1-AB02F9417AA8}" | |
"Videos" = "{F86FA3AB-70D2-4FC7-9C99-FCBF05467F3A}" | |
} | |
# Major version 6 (Windows 8.1 and Server 2012R2) | |
"6" = @{ | |
"Desktop" = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" | |
"Documents" = "{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}" | |
"Downloads" = "{374DE290-123F-4565-9164-39C4925E467B}" | |
"Music" = "{1CF1260C-4DD0-4ebb-811F-33C572699FDE}" | |
"Pictures" = "{3ADD1653-EB32-4cb0-BBD7-DFA0ABB5ACCA}" | |
"Videos" = "{A0953C92-50DC-43bf-BE83-3742FED03C9C}" | |
} | |
} | |
Function Set-ThisPcItem { | |
Param( | |
[String]$Name, | |
[Switch]$Remove | |
) | |
$Version = [String][System.Environment]::OSVersion.Version.Major | |
Foreach ( $Item in $ThisPcRegLib.$Version.GetEnumerator() ) { | |
If ( $Item.Key -match $Name ) { | |
Set-ThisPcItemRegKey -Key $Item.Value -Remove:$Remove; $Item.Key | |
} | |
} | |
} | |
Function Set-ThisPcItemRegKey { | |
Param( | |
[String]$Key, | |
[Switch]$Remove | |
) | |
Foreach ( $Path in $ThisPcPaths ) { | |
If ( $Remove ) { | |
Remove-Item -Path "$Path$Key" -ErrorAction SilentlyContinue | |
} | |
Else { | |
New-Item -Path "$Path$Key" -ErrorAction SilentlyContinue | Out-Null | |
} | |
} | |
} | |
Function Get-ThisPcReg { | |
$Version = [String][System.Environment]::OSVersion.Version.Major | |
Foreach ( $Key in Get-ChildItem -Path $Paths[0] ) { | |
$KeyLeaf = Split-Path $Key -Leaf | |
Foreach ( $Item in $ThisPcRegLib.$Version.GetEnumerator() ) { | |
If ( $Item.Value -match $KeyLeaf ) { $Item.Name } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment