Monthly Archives: December 2018

PowerShell articles

Here’s some links for other PowerShell articles I’ve written recently https://searchwindowsserver.techtarget.com/tip/PowerShell-commands-to-copy-files-Basic-to-advanced-methods https://searchwindowsserver.techtarget.com/tutorial/PowerShell-commands-for-Active-Directory-Groups-management https://searchwindowsserver.techtarget.com/tip/PowerShell-Core-61-offers-many-small-improvements https://searchwindowsserver.techtarget.com/tutorial/How-PowerShell-Direct-helps-polish-off-those-VMs https://searchwindowsserver.techtarget.com/tutorial/Working-with-PowerShell-module-downloads-from-the-gallery Enjoy

Posted in Powershell | Leave a comment

Change file times

When a file is created, accessed or modified that time is recorded. This is how to change file times. There are three properties to consider: CreationTime LastAccessTime LastWriteTime Just to add to the fun there are UTC (GMT in real … Continue reading

Posted in Powershell | 1 Comment

Get first non-repeating character in a string

How do you get first non-repeating character in a string. In Windows PowerShell v5.1 you could use Group-Object but as I showed last time that approach has been taken away in PowerShell v6.1. Instead you need to loop through the … Continue reading

Posted in Powershell | 1 Comment

Group-Object change in PowerShell v6.1

There’s a subtle Group-Object change in PowerShell v6.1. In PowerShell v5.1 if you do this: $ts = ‘ffrluoluntlvxutxbdvbktgyyvsvcrkxoyfotzkzogcwuwycmnhuedk’ $ts.ToCharArray() | group You get this: Count Name                      Group —– —-                      —–     3 f                         {f, f, f}     2 r                         {r, … Continue reading

Posted in PowerShell v5, PowerShell v6 | Leave a comment

Counting vowels

If you’re given a string how would you go about counting vowels, consonants  and non-alphabet characters. My approach would be: function measure-vowel {   [CmdletBinding()]   param (     [string]$teststring   )   $counts = [ordered]@{      Vowels      = 0      Consonants  = 0      NonAlphabet = … Continue reading

Posted in Powershell | 2 Comments

Create a random string

I often need to create a random string of characters. Here’s a simple function to achieve that: function get-randomstring {   [CmdletBinding()]   param (     [int]$length   )   $rca = 1..$length |   foreach {     $ran = Get-Random -Minimum 97 -Maximum 123     [char][byte]$ran   … Continue reading

Posted in Powershell | 2 Comments

Return of the missing PSDiagnostics

Return of the missing PSDiagnostics members in PowerShell v6.2 preview 3. In Windows PowerShell v5.1 the PSDiagnostics module contains these members: Disable-PSTrace Disable-PSWSManCombinedTrace Disable-WSManTrace Enable-PSTrace Enable-PSWSManCombinedTrace Enable-WSManTrace Get-LogProperties Set-LogProperties Start-Trace Stop-Trace In PowerShell v6.1.1 you just get these: Disable-PSTrace Enable-PSTrace … Continue reading

Posted in PowerShell v6 | Leave a comment

Find duplicate characters in a string

Staying with our current theme of manipulating strings this is how you find duplicate characters in a string. function get-duplicatechar {   [CmdletBinding()]   param (     [string]$teststring   )      $teststring.ToCharArray() |   Group-Object -NoElement |   where Count -gt 1 |   Sort-Object -Property Count … Continue reading

Posted in Powershell | Leave a comment

Join-String

Join-String is a new cmdlet in PowerShell v6.2 preview 3. Join-String enables you to use the pipeline to join strings. We’ve had the –join operator for a long time: PS>  1..3 -join ‘,’ 1,2,3 As an alternative you could do … Continue reading

Posted in PowerShell v6 | 1 Comment

PowerShell v6.2 preview 3 install issue

PowerShell v6.2 preview 3 install issue – PowerShell v6.2 preview 3 is now available from https://github.com/PowerShell/PowerShell/releases but you may notice a probloem if you install over the top of PowerShell v6.2 preview 2.  When you click on the icon to … Continue reading

Posted in PowerShell v6 | Leave a comment