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…

0

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

Export-CACertificatesForDscEncryption

(Updated @ 2016/05/18) When you use Desired State Configuration (DSC) and a Pull server, you should encrypt any credentials in your configurations documents. More information on this here: https://blogs.msdn.microsoft.com/powershell/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration/But instead of harvesting the certificates from the remote computers themselves (as described in the blog post above), I decided to query the CA directly, and get…

0

Disable Invoke-Expression

There was an interesting discussion in one of our internal discussion groups about disabling Invoke-Expression, so I decided to roll up my sleeves and check if it can really be done.   First of all, what is Invoke-Expression? “The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of…

2

Write to HKCU from the system account

In this scenario, I needed to be able to write to the currently logged on users’ HKCU registry, but from a process being run as local system. Afterwards I even had to write the HKCU for every user that will ever logon to the machine, and for every user that already logged-on before. The solution…

7