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.

Expression:   (.+)
Replace with: '$1'

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!

Expression:   [\n\r]
Replace with: ,

Oh so handy, hope it saves you some time!

EDIT:

Adding another, removing blank lines in a script

^(?:[\t ]*(?:\r?\n|\r))+

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

$verbose_info = get-aduser awittig | set-aduser -Replace @{comment = 'test'} -Verbose 4>&1
write-verbose "$(get-date) - $($verbose_info -split ':')" -Verbose

#Output
VERBOSE: 04/2/2018 16:35:01 - Performing the operation "Set" on target "CN=Wittig\, Alexander,OU=users,OU=test,DC=AD,DC=bloodyshell,DC=com".

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


You might not even notice until you need it, but when you install the RSAT tools on Win 10 for 1709, the DNS manager console is missing. That’s exactly what happened to me. I needed to add some records in DNS and oops, where is it?

Well, there is a KB article on it, so there is a fix. :¬)

  1. Check if KB 2693643 is installed, if so uninstall it
  2. Create a temporary directory to put stuff in it
  3. Create a “installx64.bat” file with the following content: [assuming you run a 64 bit Windows] <pre class="lang:default decode:true">@echo off md ex expand -f:* WindowsTH-RSAT_WS_1709-x64.msu ex\ cd ex md ex copy ..\unattend_x64.xml ex\ expand -f:* WindowsTH-KB2693643-x64.cab ex\ cd ex dism /online /apply-unattend=”unattend_x64.xml” cd ..\ dism /online /Add-Package /PackagePath:”WindowsTH-KB2693643-x64.cab” cd ..\ rmdir ex /s /q</pre>
4. Create a &#8220;unattend_x64.xml&#8221; file with the following content:

<pre class="lang:default decode:true ">&lt;?xml version="1.0" encoding="UTF-8"?&gt;   &lt;unattend xmlns="urn:schemas-microsoft-com:setup" description="Auto unattend" author="pkgmgr.exe"&gt;     &lt;servicing&gt;  
&lt;package action="stage"&gt;  
  &lt;assemblyIdentity buildType="release" language="neutral" name="Microsoft-Windows-RemoteServerAdministrationTools-Client-Package-TopLevel" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" version="10.0.16299.2"/&gt;  
  &lt;source location="." permanence="temporary"/&gt;  
&lt;/package&gt;     &lt;/servicing&gt;   &lt;/unattend&gt;</pre>

5. [Download the RSAT tools](https://www.microsoft.com/en-gb/download/details.aspx?id=45520) and put the msu file in the same folder
  
[<img class="size-full wp-image-704 aligncenter" src="http://blog.vvittig.com/wp-content/uploads/2018/02/2018-02-08_15-45-30.png" alt="" width="243" height="83" />](http://blog.vvittig.com/wp-content/uploads/2018/02/2018-02-08_15-45-30.png)

6. Start a command prompt with administrative permissions and run the &#8220;installx64.bat&#8221;

Once completed, you should have your full set (including DNS) of RSAT tools back

Resource: <https://support.microsoft.com/en-us/help/4055558></li> </ol>

The WordPress 4.9.3 update introduced an updating bug: after auto-updating to 4.9.3, WordPress will no longer update automatically.

What to do?

WordPress has published an explanation of the bug and detailed instructions for “handraulic” updating; the TL;DR version is:

Simply visit your WordPress Dashboard → Updates and click “Update Now.”

Source: https://nakedsecurity.sophos.com


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.

# Using '$using'
# PowerShell v3+
$localvalue01   = 'SampleValue01'
$localvalue02   = 'SampleValue01'

Invoke-Command -ComputerName $remotecomputer -ScriptBlock {
    write-output $using:localvalue01
    write-output $using:localvalue02
}

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.

# Argument lists
# PowerShell v2 and lower
$localvalue01   = 'SampleValue01'
$localvalue02   = 'SampleValue02'

Invoke-Command -ComputerName $remotecomputer -ScriptBlock {
    write-output $args[0] #holds the value for $localvalue01
    write-output $args[1] #holds the value for $localvalue02
} -ArgumentList $localvalue01, $localvalue02

 

Reference: about_remote_variables