Skip to content

Instantly share code, notes, and snippets.

@pmsmith
pmsmith / DisableUSBPowerManagement.ps1
Last active July 29, 2018 11:10
DisableUSBPowerManagement
#- Disable 'Allow the computer to turn off this device to save power' for all USB hubs
#- This is the same as going into device manager and unselecting the option
#- Adapted from: https://social.technet.microsoft.com/Forums/azure/en-US/49991c73-9178-496d-a73e-d2f02a836844/usb-devices-and-usb-hub-power-management-disabling-under-device-properties?forum=winserverpowershell
$hubs = Get-WmiObject Win32_USBHub
$powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi
foreach ($p in $powerMgmt)
{
foreach ($h in $hubs)
{
if($($p.InstanceName.ToUpper()) -like "*$($h.PNPDeviceId)*" -and $p.Enable -ne $false)
@pmsmith
pmsmith / AddSavedCredential.ps1
Created February 9, 2018 22:05
AddSavedCredential.ps1
param([Parameter(Mandatory=$true)][string]$hostname)
#-----------------------------------------------------------------------
#- Get-SavedCredentials
#-----------------------------------------------------------------------
function Get-SavedCredentials {
$savedCredentials = C:\Windows\System32\cmdkey.exe /list | Select-String 'TERMSRV/' | ForEach-Object {
Write-Output ($_.ToString().Replace('Target: LegacyGeneric:target=','')).Trim()
}
return $savedCredentials
@pmsmith
pmsmith / AutoHotkey.ahk
Last active February 9, 2018 21:59
AutoHotkey.ahk
;---------------------------------------------------;
;- Remote Desktop ;
;---------------------------------------------------;
^d::
fqdn := TrimHostname(clipboard)
psCommand := "powershell C:\Users\paul\Documents\AddSavedCredential.ps1 " fqdn
StdoutToVar_CreateProcess(psCommand)
Run mstsc /admin /h:1200 /w:1600 /v:%fqdn%
Return
@pmsmith
pmsmith / DriveClean.ps1
Last active November 2, 2023 02:45
Simple script to clear temp files and Google Chrome cache/history
#------------------------------------------------------------------#
#- Clear-WindowsUserCacheFiles #
#------------------------------------------------------------------#
Function Clear-WindowsUserCacheFiles {
param([string]$user=$env:USERNAME)
Remove-CacheFiles "C:\Users\$user\AppData\Local\Temp"
Remove-CacheFiles "C:\Users\$user\AppData\Local\Microsoft\Windows\WER"
Remove-CacheFiles "C:\Users\$user\AppData\Local\Microsoft\Windows\Temporary Internet Files"
}