PowerShell Sripts



POWERSHELL SCRIPTS

Get Windows License Key

(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey

Automatically delete file older than X days by PowerShell

# PATH
$dump_path = "C:temp"

# HOW MANY DAYS
$max_days = "-7"
 
# ACTUAL DAY ON COMPUTER
$curr_date = Get-Date

# HOW MANY DAYS BACK
$del_date = $curr_date.AddDays($max_days)

# DELETING
Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item

How to get BITLOCKER key from powershell

(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
$drive = Get-BitLockerVolume | ?{$_.KeyProtector | ?{$_.KeyProtectorType -eq ‚RecoveryPassword‘}} | select -f 1

$key = $drive | select -exp KeyProtector | ?{$_.KeyProtectorType -eq ‚RecoveryPassword‘} | select -f 1

Backup-BitLockerKeyProtector $drive.MountPoint $key.KeyProtectorId

Write-Host „Backing up drive $drive, key $($key.KeyProtectorId), password $($key.RecoveryPassword)“

(Many thanks to Roman)

Get the Computer Name, Model, Make, and other

Get-WMIObject -Class Win32_ComputerSystem - System info
Get-WMIObject -Class Win32_BIOS - BIOS info
Get-WMIObject -Class Win32_Baseboard - Motherboard info
Get-WMIObject -Class Win32_Processor - CPU Info
Get-WMIObject -Class Win32_LogicalDisk - Logical drivers info
Get-WMIObject -Class Win32_DiskDrive - Physical Drives info
Get-WMIObject -Class Win32_PhysicalMemory - Memory info
Get-WMIObject -Class Win32_NetworkAdapter - NIC info
Get-WMIObject -Class Win32_NetworkAdapterConfiguration - NIC configuration info
$PSVersionTable - PowerShell version info

FIND THE 5 PROCESSES USING THE MOST MEMORY

ps | sort –p ws | select –last 5

STOP RESTART START SERVICE LIKE DHCP:

Restart-Service DHCP

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.