Passing down the WhatIf and Confirm preferences to other cmdlets from an Advanced Function

A colleague of mine was writing a cool function that tidies up the GPOs, and he wanted to implement the -WhatIf common cmdlet parameter in his function. There’s a simple way of doing that, just add the [cmdletBinding(SupportsShouldProcess)] and the param() blocks in the top of your function, add the if ($PSCmdlet.ShouldProcess($target)) {} in the…

0

Using VSCode and the PowerShell extension in an offline environment

The PowerShell ISE was first shipped with PowerShell 2.0 (November 2006), and greatly improved in PowerShell 3.0 (August 2012), with the PowerShell Tabs, the Show-Command Add-on and the snippets (CTRL+J). But since then, it pretty much stayed the same. Fast forward to May 2017, David Wilson from the PowerShell team announced (amongst other things) that:…

0

Get the certificate selected in Get-Credential

Following Matt Bongiovi’s post at the Hey, Scripting Guy! Blog about PowerShell support for certificate credentials, I ported the main parts of the c# code he references in his post to PowerShell. So here you have, a quick-and-dirty Get-CertificateFromCredential function you can use to get the certificate for the credentials the user selected from the…

1

Setting share permissions with WMI

With Windows Server 2012 we got the SmbShare Module. But since it’s a CDXML module that just defines the mapping between PowerShell cmdlets and CIM class operations or methods, it’s bound to the OS having the relevant CIM Classes. So it’s not portable to older operating systems. For Windows Server 2012 and above, there’s no…

0

POC: PowerShell Desired State Configuration for Linux

Since PowerShell went open source, I’ve been asked a lot about running PowerShell on Linux. Lately, I’ve been asked more and more about configuring Linux machines with DSC (Desired State Configuration). So here goes a quick and dirty How-to download, install, and use DSC to configure your Linux machines (In my case, I used Ubuntu…

0

Install and Configure a Group Managed Service Account with PowerShell

Managed Service Accounts (MSAs) were introduced in Windows Server 2008, and Group Managed Service Accounts (gMSAs) were introduced in Windows Server 2012. Since then, a lot has been said about gMSAs (see the references section at the bottom). So in this post, I’ll just summarize the flow and the PowerShell commands needed for each step…

1

Display friendly file sizes in PowerShell

At one of my recent classes, while discussing hashtables and calculated properties I showed an example of how to list the file’s size in kilobytes instead of the default bytes size. This can be accomplished with {$_.Length/1kb} as the expression in the property’s hash, but then the output can be… not too pretty… and from…

1

ConvertFrom-ISO8601Duration

ISO 8601 describes durations as a component of time intervals and define the amount of intervening time in a time interval. From Wikipedia (https://en.wikipedia.org/wiki/ISO_8601#Durations): Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W as shown to the right. In these representations, the [n] is replaced by the value for each of the date and time…

0

Using DSC with the WinRM service disabled

  Every once in a while I come across a weird scenario where the customer’s requirements and/or limitations are so challenging that they take me to a interesting discovery journey. This time, the requirement was to use Desired State Configuration (DSC) in remote machines where there was no connectivity (with any protocol or port) to…

2

Adding extended properties as NoteProperties

Continuing my post on Filtering files by their metadata (extended properties), and a question raised by Ankor in the comments section, I decided to quickly wrap up a new function (based on the one in the post) that simply adds the specified extended properties as new note properties to the object in the pipeline. As…

3