Last active
November 16, 2020 17:52
-
-
Save iax7/067f1cf4f110b7c16d62ac0e3819e55c to your computer and use it in GitHub Desktop.
Set-Folder-Icon
This file contains 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
$TargetDirectory = "." # "C:\Users\itdroplets\Desktop\tmp\Folder3" | |
$DesktopIni = @" | |
[.ShellClassInfo] | |
IconResource=.icon.ico,0 | |
"@ | |
If (Test-Path "$($TargetDirectory)\download.png") { Rename-Item "$($TargetDirectory)\download.png" -NewName .icon.png } | |
If (Test-Path "$($TargetDirectory)\download.ico") { Rename-Item "$($TargetDirectory)\download.ico" -NewName .icon.ico } | |
If (Test-Path "$($TargetDirectory)\icon.png") { Rename-Item "$($TargetDirectory)\icon.png" -NewName .icon.png } | |
If (Test-Path "$($TargetDirectory)\icon.ico") { Rename-Item "$($TargetDirectory)\icon.ico" -NewName .icon.ico } | |
If (Test-Path "$($TargetDirectory)\desktop.ini") { | |
Write-Warning "The desktop.ini file already exists." | |
Remove-Item "$($TargetDirectory)\desktop.ini" -Force | |
} | |
(Get-Item .\.icon.ico).Attributes = 'ReadOnly, Hidden' | |
(Get-Item .\.icon.png).Attributes = 'ReadOnly, Hidden' | |
#Create/Add content to the desktop.ini file | |
Add-Content "$($TargetDirectory)\desktop.ini" -Value $DesktopIni | |
#Set the attributes for $DesktopIni | |
(Get-Item "$($TargetDirectory)\desktop.ini" -Force).Attributes = 'Hidden, System, Archive' | |
#Finally, set the folder's attributes | |
(Get-Item $TargetDirectory -Force).Attributes = 'ReadOnly, Directory' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment