Detection:
# Check if marker file exists indicating that folders are pinned
$markerFilePath = Join-Path -Path $env:userprofile -ChildPath "QuickAccessPinned.marker"
if (Test-Path $markerFilePath) {
Write-Output "Folders are pinned to Quick Access"
exit 0
} else {
Write-Output "Folders are not pinned to Quick Access"
exit 1
}
Remediation:
$foldersToPin = @("C:\Folder One", "C:\Folder Two")
$o = New-Object -ComObject shell.application
$success = $true
foreach ($folder in $foldersToPin) {
$pinnedFolders = Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband'
if ($pinnedFolders.PinnedList -notcontains $folder) {
$o.Namespace($folder).Self.InvokeVerb("pintohome")
Write-Output "Folder $folder pinned to Quick Access"
} else {
$success = $false
}
}
# Write a marker file indicating that folders are pinned
if ($success) {
$markerFilePath = Join-Path -Path $env:userprofile -ChildPath "QuickAccessPinned.marker"
New-Item -Path $markerFilePath -ItemType File -Force | Out-Null
}
if ($success) {
exit 0
} else {
exit 1
}