Have you ever found yourself needing to edit a long list with usernames, and you had to go in and manually clean that list up, format it properly, wrap it in quotes and so forth? Yeah, it’s painful, but I finally found this handy regex statement that makes it all better.

So let’s take we have a regular user list

After running the regex, we have them all neatly wrapped in quotes

Now we have this nice list, but let’s say we need that as a string in a line. regex? Yeah no problem!

Oh so handy, hope it saves you some time!

EDIT:

Adding another, removing blank lines in a script

Replace this with nothing to remove all empty lines. :¬)

I wanted to append information to the verbose output of a cmdlet so that logging is neater. Well, it seems there is no nice way to do that?

This is what I came up with, redirecting the verbose stream, manipulating the verbose string, and then write it verbose back out

Source: https://blogs.technet.microsoft.com/heyscriptingguy/2014/03/30/understanding-streams-redirection-and…

I keep seeing many posts with people struggling to execute code on remote machines, it is usually not due to permissions issues, (enable PS Remoting), but mainly due to the fact that they forget that the remote machine does not know the value of the locally assigned variable.

Using (new way) PSv3+

With PowerShell Version 3 and newer, $using was introduced.
If you want to pass a local variable to the remote machine , just add $using: in front of the variable name (e.g. $using:localvariable), and the local value will be given on to the remote machine. This is so much simpler and easier to read than the ‘old’ argumentlist way.

Argumentlist (old way)

In this sample, we are looking at using an argument list to pass the values of the variable to the remote machine.
You define the values you need per usual on your local machine, and then you add an $argumentlist as parameter.
The order you list the variables is important, as the one first variable listed is addressed with $args[0], the variable next to it (to the right) is addressed with $args[1] and so forth.

 

Reference: about_remote_variables

You probably have heard or read about the current issues with chips and their vulnerability.

A fundamental design flaw in Intel’s processor chips has forced a significant redesign of the Linux and Windows kernels to defang the chip-level security bug.

CVE-2017-5754 (Meltdown) and CVE-2017-5715 (Spectre)  are two nasty exploits and you might want to check your systems if they are patched.

Luckily the Microsoft Security Response Center has released a PowerShell module named SpeculationControl which can be installed from the PowerShell Gallery.

Additionally maybe look at Mike’s post