Tag Archives: script

[PS] Retrieve default PDF-reader registry value

Until now, i only knew one way of retrieving the default app-association for a specific file extension (.pdf, .xlsx, .docx) and that is by using DISM and exporting an .xml file. But this can only be done with an elevated prompt (as far as i know).

This is where my problem started, if you elevate an cmd prompt, you will only export the standard app-associations for that particular user (admin user). I wanted to display the standard app-associations for the user on that specific computer.

Long story short, i found the registry value where you can see this, it’s probably not a good idea to change this value here, for that you will have to use DISM i think, correct me if i’m wrong. If you want to retrieve the standard app-association for another file extension, just change .pdf to whatever you want to retrieve.

Registry path:


HKEY_USERS\YOUR-SID-HERE\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice

And what i uses this for is just running it on remote computers through a PS-session with this script:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$sid = ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value
$path = "Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice"
(Get-ItemProperty -Path $path -Name ProgId).ProgId

 

 

 

 

[PS] Simple Powershell script to ping multiple computers

Hello world!

Simple script i wrote just to ping (test-connection to) multiple servers/computers. It uses a textfile as an input. Make sure to put one server/computer on each line in the textfile. Could probably be written 10 times cleaner, but it works.

Edit:

Modified the first script so that you could add the servers/computers directly into the script.



Computers/servers is located in a txt-file:

$path = "C:\computernames.txt"
do{
$pclist = Get-Content $path
foreach ($pc in $pclist) {
if (test-Connection -ComputerName $pc -Count 2 -Quiet ) {
Write-Host $pc is online -ForegroundColor Green
} else {Write-Host $pc is offline -ForegroundColor Red}
}
} until($forever)

 

Computers/servers are located in the script:


$pclist = "computer1", "computer2", "computer3", "computer4", "computer5"
do{
foreach ($pc in $pclist) {
if (test-Connection -ComputerName $pc -Count 2 -Quiet ) {
Write-Host $pc is online -ForegroundColor Green
} else {Write-Host $pc is offline -ForegroundColor Red}
}
} until($forever)

 

If you want more beginner-friendly commands, check out my new article

[PS] Top Ten Simple Powershell commands every IT-admin should know

 

6 1