1

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?

3
  • ...What are you actually asking here? Commented Aug 16, 2017 at 8:07
  • I mean, will it be right to issue this code into something with array? Commented Aug 16, 2017 at 8:10
  • 1
    It's less code if you do, so probably. Fundamentally you get the same result either way so it depends on your use case. Commented Aug 16, 2017 at 8:12

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.