Reputation: 375
So I have a code:
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name .bmp -Type String -Value PhotoViewer.FileAssoc.Bitmap -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name .jpg -Type String -Value PhotoViewer.FileAssoc.Jpeg -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name .jpe -Type String -Value PhotoViewer.FileAssoc.Jpeg -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name .jpeg -Type String -Value PhotoViewer.FileAssoc.Jpeg -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name .png -Type String -Value PhotoViewer.FileAssoc.Png -Force
and is it possible to make an array via PowerShell like something like this:
ForEach ($type in @(
".bmp"
".jpg"
".jpe"
"jpeg"
".png"
))
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name $type -Type String -Value $something -Force
}
Or i'll be pointless?
Upvotes: 1
Views: 71
Reputation: 174465
Given that there's no 1-to-1 relationship between the file extension and file type, you might want to go with a hashtable:
$PVPrefix = 'PhotoViewer.FileAssoc'
$Assocs = @{
".bmp" = "Bitmap"
".jpg" = "Jpeg"
".jpe" = "Jpeg"
".jpeg" = "Jpeg"
".png" = "Png"
}
foreach($ext in $Assocs.Keys){
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" -Name $ext -Type String -Value "$PVPrefix.$($Assocs[$ext])" -Force
}
Upvotes: 1