My goal is to customize all folder icon if the foder's name end by "_S" So i writed a PowerShell function but the customize doesn't work.
I took inspiration from:
Website to set attribute on desktop.ini
Function that sets a custom folder icon
function Set-icon_Folder_S($path)
{
$ini = '[.ShellClassInfo]
IconIndex = 0
IconResource=C:\private.ico,0
ConfirmFileOp = 0
DefaultDropEffect = 1'
Set-Location $path
#List all folder end with _S
$items = Get-ChildItem -Recurse | Where-Object {($_.Attributes -match "Directory") -and ($_.Name.EndsWith("_S"))} | Select-Object -ExpandProperty FullName
#For each folder _S ...
foreach ($item in $items)
{
Set-Location $item
#Init. Delete desktop.ini if exist
try {
Remove-Item desktop.ini -Force -erroraction stop
}
catch {
}
#Write desktop.ini
Write-Host "Go to $($item)"
$ini | Out-File desktop.ini -Force
Set-ItemProperty desktop.ini -Name Attributes -Value “ReadOnly,System,Hidden”
}
}
I doesn't find error.
Following adjusted script works for me: adding an empty-line to
desktop.ini
tail should do the trick in itself (callingattrib.exe
I have tried first so it might be superabundant):Changes are described in above code using ### comments (except
IconResource
):