PowerShell one-liners cheat sheet

PowerShell is a powerful and flexible command-line shell and scripting language used by IT professionals and power users. One of its greatest strengths is the ability to perform tasks with just a single line of code. This "cheat sheet" article provides an overview of some of the most useful PowerShell one-liners for administrators, developers, and other technical professionals. Whether you're a seasoned PowerShell expert or just getting started, this article is an essential resource for anyone looking to streamline their work and increase their efficiency. With concise, easy-to-remember examples and explanations, this cheat sheet is the perfect tool for anyone looking to get the most out of their PowerShell experience.

Use these snippets as starting points and test them in a non-production shell first. If you need a repeatable sandbox, the PowerShell in Docker guide shows how to preload modules into a container, and the EBS encryption guide includes AWS examples that pair well with the EC2 commands below.

I also found an older Microsoft video about combining commands into one line.

And here is my PowerShell one-liner cheat sheet:

Get PowerShell version:

Get your public IP address:

Get Windows uptime (-Since parameter will show you last boot time):

Enable TLS 1.2 support:

Get Active Directory latest shadow copy backup date:

Get a list of disabled users from Active Directory

Send an email:

Get a list of all non-Windows servers that have not contacted Active Directory in the last 30 days

Copy item to the clipboard

Get EC2 instances with a specific name (in the example, containing `dev` in a name)

Get EC2 instances without any IAM roles attached:

Get EC2 instances count grouped by family/type:

Remove unused AMI images:

Get a list of unused subnets:

Get a hard drive temparature (run as Administrator):