Cheat Sheet

Cheat Sheet

Re-usable snippets of commands and codes.

# Single line to get exit code from an MSI run in PowerShell
return (Start-Process msiexec.exe -Wait -PassThru -ArgumentList "/i $MSIName /q").ExitCode

Windows Services - in elevated prompt
# PoSh - Local machine:
Get-Service -Name $service | Start-Service
# PoSh - Remote machine:
Get-Service -Name $service -ComputerName $computer | Set-Service -Status Running
# CMD - Check for remote service status
sc \\$computer query $service
# CMD - Start a service remotely (You must stop and start a service to restart, there is no restart option)
sc \\$computer start|stop $service

Check Azure MFA Status
Connect-MsolService
(Get-MsolUser -UserPrincipalName username@contoso.com).StrongAuthenticationMethods

# Remove user account and files as in SysPref
sudo sysadminctl -deleteUser USERNAME

# Permission Repairs
sudo /usr/libexec/repair_packages --repair --standard-pkgs --volume /

Screenshot for OS X
command-shift-3 captures screen and saves to desktop
command-shift-4 captures selection and saves it to the desktop
command-shift-4, hold ctrl while selecting captures selection to clipboard
command-shift-4, spc captures active window, saves to deskto

# ffmpeg H.264 encode - https://trac.ffmpeg.org/wiki/Encode/H.264
ffmpeg -hide_banner -i "INPUT.wmv" -c:v libx264 -crf 20 -preset slow -c:a libfdk_aac -b:a 128k "OUTPUT.mp4"

# H.265 that works with Apple QuickTime and QuickLook
ffmpeg -i "INPUT.rm"  -c:v libx265 -tag:v hvc1 -preset slow -crf 23 -c:a libfdk_aac -b:a 128k "~/Desktop/OUTPUT.mov"

Xerox Icons
/Library/Printers/Xerox/PDEs/XeroxFeatures.plugin/Contents/Resourcces/Products

# FileVault Unlocking in Terminal
diskutil corestorage list # Get UUID of Volume
diskutil corestorage unlockVolume $UUID -stdinpassphrase # If you have the password of enabled user
diskutil corestorage unlockVolume $UUID -passphrase $recoverykey # If you have recovery key

Make softwareupdate check a different catalog (10.8.5 and older only)
sudo softwareupdate -l --CatalogURL "https://example.com/content/catalogs/index_BSS.sucatalog"

Remove MCX (if conneted to old LDAP)
dscl . -list Computers | grep -v "^localhost$" | while read computer_name ; do sudo dscl . -delete Computers/"$computer_name" ; done

Find Installed Printer PPDs
lpinfo -m | grep -i Canon


Add everyone as printer admin on their machine
dseditgroup -o edit -n /Local/Default -u administrator -p -a everyone -t group lpadmin


Boot into macserver05 on the next boot
sudo bless --netboot --server bsdp://macserver05 --nextonly


Get your computer's names (Case sensitive)
scutil --get LocalHostName
scutil --get ComputerName
scutil --get HostName

Disable keyboard shortcuts (Allows repeated keystroke by holding a key)
defaults write -g ApplePressAndHoldEnabled -bool false


List directory with: @ extended attribute, d directory as plain (no recursive), e ACL, l Long listing, O File flag
ls -@delO ~/Path/to/Directory


Delete ACL entry by number
sudo chmod -a# 0 ~/Path/to/file


Lock Screen Text/Loginwindow Text
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "All Your Screens Are Belong To Me"


Restore Apple's Java 6 after 7 is installed.
sudo ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo ln -sf /System/Library/Frameworks/JavaVM.framework/Commands/javaws /usr/bin/javaws


# Flush DNS
# Yosemite 10.10.4 and up
sudo killall -HUP mDNSResponder

# Yosemite 10.10 to 10.10.3
sudo discoveryutil mdnsflushcache

# Lion, Mountain Lion, Mavericks
sudo killall -HUP mDNSResponder

# Snow Leopard
sudo dscacheutil -flushcache

Build a no-payload package
sudo pkgbuild --identifier com.company.myscript --nopayload --version 1.0 --scripts /Users/username/Desktop/scriptsfolder "~/Desktop/Your.pkg"


# Example on how to package via the commandline
chmod # Reminder to fix your files' permissions!
mkdir -p /tmp/foo/Library/Fonts
cp /path/to/some/fonts /tmp/foo/Library/Fonts/
sudo pkgbuild --root /tmp/foo --identifier com.company.fonts.futura --version 1.1 ~/Desktop/Futura11.pkg

Stop GoToMeeting from spawning more children
launchctl unload /Users/$USER/Library/LaunchAgents/com.citrixonline.GoToMeeting.G2MUpdate.plist
rm /Users/$USER/Library/LaunchAgents/com.citrixonline.GoToMeeting.G2MUpdate.plist


# Reset Launchpad

# Yosemite and up, no sudo, run in user's space
defaults write com.apple.dock ResetLaunchPad -bool true ; killall Dock
    
# Mavericks and below
rm ~/Library/Application\ Support/Dock/*.db ; killall Dock

Check Disk Usage of current user home's first folder (c=grand total-optional depending on depth, h=human-readable, d=depth), no trailing slash needed
[sudo] du -hd 0 ~