Tips and Tricks

Tips and Tricks
Colyn Via
PowerShell for Admins

The Ternary Cometh

Developers are likely to be familiar with ternary conditional operators as they’re legal in many languages (Ruby, Python, C++, etc). They’re also often used in coding interviews to test an applicant as they can be a familiar source of code errors. While some developers couldn’t care less about ternary operators, there’s been a cult following waiting for them to show up in Powershell. That day is almost upon us. Any Powershell developer can easily be forgiven for scratching their heads and wondering what a ternary is.

Colyn Via
PowerShell for Admins

A Peculiar Parse

One of the best enhancements to Powershell was the inclusion of custom classes in v5. We originally wrote scripts, then we wrote cmdlets, followed by modules, and now we’ve graduated, with Class. I recently decided I wanted to write some code that would build a website. What better way to do that than by creating a class just for me? That’s rhetorical by the way. My early class code looked like this:

Nathaniel Webb (ArtisanByteCrafter)
PowerShell for Admins

Quick ProTip: Negotiate TLS Connections In Powershell With A Minimum TLS Version Requirement

Synopsis This is a quick post to highlight the nuances of Powershell and protocol management in regard to TLS connections. If you’ve ever attempted to make a secure connection (for example, an API request) to a service with certain net security requirements, you might have run into this problem. While TLS is negotiated at the highest level existing on both the server and the client, the minimum protocols defined by Powershell may include ones that you explicitly do not want.

Mark Roloff
PowerShell for Admins

ICYMI: PowerShell Week of 17-May-2019

Topics include working with the Graph API, Chocolatey, jazzing up your functions with pipeline support, and shrinking VMDKs. Special thanks to Robin Dadswell, Prasoon Karunan V, and Mark Roloff. How to shrink VMDK with a couple of PowerShell scripts? by Kevin Soltow on May 8th Not just a set of useful scripts for anyone still working in a space-constrained environment, but a great bit of interesting detail has also gone into this.

Mark Roloff
PowerShell for Admins

Phenomenal number of ACLs, itty-bitty living space

I recently had a need to backup file and folder ACLs for a client that would then need to restore them to their original objects following a hardware upgrade that would wipe them out. Easy enough, but the catch was that there was 1.5 million of them. Fortunately, getting ACLs in PowerShell is easy. `PS > Get-Acl -Path somefile.txt Directory: C: Path Owner Access somefile.txt BUILTIN\Administrators BUILTIN\Administrators Allow… `See? Now, if you needed multiple ACLs, say, all 1.

Nathaniel Webb (ArtisanByteCrafter)
PowerShell for Admins

Learn To Use Verbose Output Streams In Your Pester Tests

I’m going to file this under “Either I’m a genius, or there’s a much better way and everyone knows it except for me.” I recently began adding a suite of Pester tests to one of my projects and I found myself needing to mock some unit tests against a particular function that would modify a variable based on the parameter specified. Since all the functions I write nowadays are considered advanced functions (and yours should be too, they’re free!

pwshliquori
Tips and Tricks

Hear, Hear for Here-Strings

Running commands in PowerShell that require a format that will not run natively in PowerShell could be a difficult task, or can it? PowerShell provides a way to store, for example, a JSON as a string, enter here-string. A here-string is a single or double quoted string in which the quotation marks are interpreted literally. An example would be invoking a Rest API that requires a JSON body. Lets take a look at an example and see how here-strings work.

Nathaniel Webb (ArtisanByteCrafter)
PowerShell for Admins

Secure Your Powershell Session with JEA and Constrained Endpoints

Index What is a Constrained Endpoint and Why Would I Need One? Setup and Configuration Using our Endpoint What is a constrained endpoint and why would I need one? Powershell constrained endpoints are a means of interacting with powershell in a manner consistent with the principal of least privilege. In Powershell terms, this is referred to as Just-Enough-Administration, or JEA. JEA is very well documented, so this won’t simply be repeating everything those references detail.