Skip to content

Instantly share code, notes, and snippets.

@iax7
Last active November 16, 2020 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iax7/067f1cf4f110b7c16d62ac0e3819e55c to your computer and use it in GitHub Desktop.
Save iax7/067f1cf4f110b7c16d62ac0e3819e55c to your computer and use it in GitHub Desktop.
Set-Folder-Icon
$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