Windows Powershell Potpourri

Purpose:

The purpose of this article is to display a set of commonly used Windows Powershell Scripts

To recursively remove a folder that may contain too many folders for Windows to handle
remove-item -path "C:\Program Files\ScienceLogic" -recurse -verbose
Get System Boot Time
systeminfo | find /i "Boot Time"
Get all files in a folder and subfolders
get-childitem -file -path "c:\Temp" -Recurse -Name | Split-path -Leaf
Remove all items in Downloads folders for all users with local profile
ls c:\Users\*\Downloads -Recurse -Directory | REMOVE-ITEM -Recurse
Remove all Items that start with Archive in current Directory
Get-ChildItem | Where-Object Name -Like 'Archive*' | ForEach-Object { Remove-Item -LiteralPath $_.Name}
Import from a CSV with Name header Write Name
Import-csv .\Computers.csv | ForEach-Object { Write-host "$($_.Name)"}
Get Client DNS from Powershell
get-dnsclientserveraddress
Pay attention to the InterfaceAlias
This will be used to Set DNS with Set-DNSClientServerAddress
Set DNS quickly through Powershell
Set-DNSClientServerAddress "Ethernet" –ServerAddresses ("192.168.22.11","192.168.22.13")
Clear Client DNS Cache
Clear-DnsClientCache
Update Office Click to run
"C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe" /update user displaylevel=false forceappshutdown=true

Hash password to Registry

#Prompts for a password and saves to Registry HKCU:\Software\Nunyabusiness EncPwd String
$pass = Read-Host "Enter Password"
$pass = $pass | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
# Set variables to indicate value and key to set
$RegistryPath = 'HKCU:\Software\Nunyabusiness'
$Name = 'EncPwd'
$Value = $pass
# Create the key if it does not exist
If (-NOT (Test-Path $RegistryPath)) {
New-Item -Path $RegistryPath -Force | Out-Null
}
# Now set the value
New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType String -Force