如果 foder 的名称以“_S”结尾,我的目标是自定义所有文件夹图标所以我编写了一个 PowerShell 函数,但自定义不起作用。
我的灵感来自:
Website to set attribute on desktop.ini
设置自定义文件夹图标的功能
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”
}
}
我没有发现错误。