header image

Archive for November, 2018

Test if string contains numeric

Posted by: | November 30, 2018 Comments Off on Test if string contains numeric |

How can you test if a string contains a numeric character? The simple answer is to use a regular expression. If you’ve been reading my stuff for any length of time you’ll know how much I love regular expressions. This is a simple regex. Create a string PS> $s1 = ‘qwertyuiop’ Test if it has […]

under: PowerShell

Reverse a string

Posted by: | November 29, 2018 Comments Off on Reverse a string |

I sort of brushed over it on my last post but this is how you reverse a string.   function get-reversestring { [CmdletBinding()] param ( [string]$teststring ) $ca = $teststring.ToCharArray() [array]::Reverse($ca) -join $ca }   Take the input string and turn it into an array of chars. Use the reverse static method of the array […]

under: PowerShell

Test if a string is a palindrome

Posted by: | November 28, 2018 Comments Off on Test if a string is a palindrome |

This is the first in a short series in which I’ll look at some string handling techniques. PowerShell is all about objects but sometimes you just have to work with the basics. In this post I’ll show how to test in a string is a palindrome.   A palindrome is a list of characters that […]

under: PowerShell

Third way to find pairs for given sum

Posted by: | November 27, 2018 Comments Off on Third way to find pairs for given sum |

There’s a third way to find pairs for given sum that’s a bit more complicated. function get-pairs2 { [CmdletBinding()] param ( [int[]]$iarray, [int]$value ) $sarray = $iarray | Sort-Object Write-Information -MessageData “Array: $iarray” -InformationAction Continue Write-Information -MessageData “Sorted Array: $sarray” -InformationAction Continue Write-Information -MessageData “Sum: $value” -InformationAction Continue $left = 0 $right = $sarray.Count – […]

under: PowerShell

A more elegant way to find pairs

Posted by: | November 26, 2018 Comments Off on A more elegant way to find pairs |

Last time I showed a brute force way to find the pairs of numbers in an array that would sum to a given value. This time I have a more elegant way to find pairs.   function get-pairs1 { [CmdletBinding()] param ( [int[]]$iarray, [int]$value ) Write-Information -MessageData “Array: $iarray” -InformationAction Continue Write-Information -MessageData “Sum: $value” […]

under: PowerShell

Find pairs that give required sum

Posted by: | November 25, 2018 Comments Off on Find pairs that give required sum |

If you have an array of integers how do you find pairs that give required sum. In other words which pairs of numbers add up to a given value.   There are a number of ways to solve this. Lets start with my favourite technique – brute force. function get-pairs { [CmdletBinding()] param ( [int[]]$iarray, […]

under: PowerShell

Moving FSMO roles in PowerShell v6.1.1

Posted by: | November 22, 2018 Comments Off on Moving FSMO roles in PowerShell v6.1.1 |

With the Windows Server 2019 media now being available again it’s time to move my test lab over to the new version. I’d built a Windows Server 2019 VM and installed PowerShell v6.1.1. I discovered that in Server 2019 and the Windows 10 October 2018 update that the AD module worked in PowerShell v6.1.1. I […]

under: PowerShell and Active Directory, PowerShell v6

Active Directory cmdlets in PowerShell v6.1.1

Posted by: | November 16, 2018 Comments Off on Active Directory cmdlets in PowerShell v6.1.1 |

Just discovered that you can run the Active Directory cmdlets in PowerShell v6.1.1 BUT there is a huge caveat.   The Windows 10 October 2018 (Windows 10 1809) update includes the RSAT tools (including the AD tools) as optional features. This means that you can easily install the AD tools: Add-WindowsCapability -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 –Online   […]

under: PowerShell and Active Directory, PowerShell v6

Reverse an array

Posted by: | November 8, 2018 Comments Off on Reverse an array |

Ever needed to reverse an array? If its sorted then sorting in the opposite direction will work. Most arrays aren’t sorted so you need to use the Reverse static method of the array class   Here’s some examples $carray = ‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’ $carray -join ‘,’ [array]::Reverse($carray) $carray -join ‘,’   $iarray = 1,2,3,4,5,6,8,9,10 “$iarray” [array]::Reverse($iarray) “$iarray” […]

under: PowerShell

Hyper-V book now available

Posted by: | November 7, 2018 Comments Off on Hyper-V book now available |

My Hyper-V book now available.   Ebook direct from the publisher: https://www.apress.com/gb/book/9781484241158#otherversion=9781484241165   The Kindle version is on Amazon UK: https://www.amazon.co.uk/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=hyper-v+2019&rh=i%3Aaps%2Ck%3Ahyper-v+2019 Presumably other Amazon sites will follow soon   The paper back version is on pre-order from Apress and Amazon to be available on 25 December 2018 – Happy Christmas

under: Hyper-V

Older Posts »

Categories