PowerShell Scripts and One-Liners

Posted here will be some super short and useful scripts to gather info or do basic tasks.

Windows Updates

#How to get a list of installed updates from the local computer.
get-hotfix

#How to get a list of installed updates from a remote computer.
get-hotfix -cn ComputerName

BitLocker Drive Encryption

#How to view the current encryption status of a drive
manage-bde -status c:

#How to enable BitLocker on a drive
manage-bde -on c: -RecoveryPassword -Skiphardwaretest

#These same commands can be executed on a remote machine by adding
#-cn and then typing in the computer name
manage-bde -status -cn ComputerName c:
manage-bde -on c: -cn ComputerName -RecoveryPassword -Skiphardwaretest

#How to re-save the current BitLocker key to active directory.
#Remember that in order for the key to actaully populate the domain or OU
#needs to be configured for saving BitLocker recovery keys.

#First get the NumericalPasswordID
manage-bde -protectors C: -get
#Then type the below in replacing NumericalPasswordID with your current ID.
manage-bde -protectors -adbackup C: -id "NumericalPasswordID"

Rename a Computer

#How to rename a local computer
Rename-Computer -NewName "NewLocalName" -Restart

#Rename a remote computer
Rename-Computer -ComputerName "RemoteName" -NewName "NewRemoteName" -Restart

#If the remote computer is connected to a domain you will need to specify domain credentials.
Rename-Computer -ComputerName "RemoteName" -NewName "NewRemoteName" -DomainCredential Domain\User -Restart

Add a domain user to the Local Admin Group

Add-LocalGroupMember -Name "Administrators" -Member domain\UserAccount

Get Programs and Version Numbers

#For All Apps
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate

#For a specific App
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Where DisplayName -eq "Windows SDK for Windows Store Apps DirectX x86 Remote"

Mount an ISO and install a Program from the ISO

#Mount the ISO
$isoImg = "C:\NewFolder\NewImage.iso"
    $driveLetter = "X:\" # note the added ending backslash: mount fails if its not there
$diskImg = Mount-DiskImage -ImagePath $isoImg  -NoDriveLetter -PassThru;
$volInfo = $diskImg | Get-Volume
mountvol $driveLetter $volInfo.UniqueId

#Uncomment this to unmount the volume
#DisMount-DiskImage -ImagePath $isoImg


Disable Web Search in Windows 10

if( -not (Test-Path -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer)){
  New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer
}
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer `
  -Name "DisableSearchBoxSuggestions" -Value 1 -Type DWord