Keep it Simple
Richard Siddaway's Blog
by richardsiddaway
3y ago
One of the principles I’ve always tried to stick with when writing code – in PowerShell or any other language – is Keep it Simple. Keeping code simple makes it easier to understand, easier to debug and easier to maintain. My definition of simple code may not be the same as yours but by and large simple code is easier to work with. When I was judging Scripting Games entries it was always easier to work with answers that were written in a simple manner. That doesn’t mean they were crude or badly written – it means they were written in a manner that was easy to understand. Creating a PowerShell p ..read more
Visit website
Time for cube calculation
Richard Siddaway's Blog
by richardsiddaway
3y ago
My recent post on spheres got me wondering about the time for cube calculation. Defining a variable PS> $r = 2.37 I can calculate the cube by multiplying $r by itself 3 times or by using the Power function on the Math class. Starting with the simple calculation PS> Measure-Command -Expression {$r * $r * $r} PowerShell v7 RC2 took 18 milliseconds; PowerShell v6.2.4 took 9 milliseconds and Windows PowerShell 8 milliseconds Using the math function PS> Measure-Command -Expression {[math]::Pow($r, 3)} PowerShell v7 RC 2 took 24 milliseconds; PowerShell v6.2.4 took 18 milliseconds and Windo ..read more
Visit website
Spheres
Richard Siddaway's Blog
by richardsiddaway
3y ago
Continuing my series of functions that can be used for geometric calculations its time for a quick look at spheres. Remember in all of these functions that PI is set as a constant when the module is loaded: New-Variable -Name pi -Value ([math]::PI) -Option Constant Calculating the volume of a sphere is relatively straight forward. I used the Math Power function to calculate the cube of the radius rather than multiplying it out 3 times as that starts to look messy. function Get-SphereVolume {    [CmdletBinding()]    param (      [double]$radius  &nbs ..read more
Visit website
Recent releases
Richard Siddaway's Blog
by richardsiddaway
3y ago
Recent releases of interest include: PowerShell v7 Release Candidate 2. No significant changes from RC 1 – see https://github.com/PowerShell/PowerShell/releases/tag/v7.0.0-rc.2 Windows Terminal v0.8.10261. Bug fixes – see https://github.com/microsoft/terminal/releases/tag/v0.8.10261.0 PowerShell v6.2.4. No significant changes – see https://github.com/PowerShell/PowerShell/releases/tag/v6.2.4 With GA of PowerShell v7 close not sure its worth investing too much energy in v6.2.4 ..read more
Visit website
Circles
Richard Siddaway's Blog
by richardsiddaway
3y ago
One of my all time favourite films is “The Thomas Crown Affair” – the original NOT the remake. The films theme tune – Windmillls of your Mind – with its focus on circles got me thinking about geometrical calculations in general and circles in particular. I decided I’d create a library of such calculations – eventually it’ll be available on github – starting with circles. Two calculations come to mind immediately for circles – area of a circle and its circumference: New-Variable -Name pi -Value ([math]::PI) -Option Constant #region CIRCLES function Get-CircleArea {    [CmdletBinding ..read more
Visit website
VScode improvement
Richard Siddaway's Blog
by richardsiddaway
3y ago
VScode is the recommended editor for PowerShell Core as its multi-platform. Personally, I’ve preferred the Windows PowerShell ISE as its more closely aligned with the code I create and the work I do. The latest VScode improvement means I’m beginning to question that stance. The latest version of VScode has buttons to run the whole code in the editor window or run selected code. In, and of, itself that’s not a huge improvement but it saves me remembering the specific keystrokes or digging through the menus. So, thankyou for an improvement that makes things easier for me and means I’m more likel ..read more
Visit website
Clear the trusted host list
Richard Siddaway's Blog
by richardsiddaway
3y ago
The final option in administering the trusted host list is to clear the entire list. The following function will clear the trusted host list function clear-trustedhost { [CmdletBinding()] param (   [string]$computername = $env:COMPUTERNAME ) if (Test-Connection -ComputerName $computername -Quiet -Count 1) {    Set-WSManInstance -ResourceURI winrm/config/client -ComputerName $computername -ValueSet @{TrustedHosts = “”} } else {    Write-Warning -Message “$computername is unreachable” } } Use Set-WSMANinstance to set the value of trusted hosts to being an empty string ..read more
Visit website
Remove a trusted host
Richard Siddaway's Blog
by richardsiddaway
3y ago
Continuing our collection of routines to manage the trusted hosts this time we’ll look at how to remove a trusted host function remove-trustedhost { [CmdletBinding()] param (   [string]$trustedhost,   [string]$computername = $env:COMPUTERNAME ) if (Test-Connection -ComputerName $computername -Quiet -Count 1) {    $th = Get-WSManInstance -ResourceURI winrm/config/client -ComputerName $computername |    Select-Object -ExpandProperty TrustedHosts   if ($th) {      $ths = $th -split “, |,”, 0, “Regex”     $newth = ($ths -ne $tru ..read more
Visit website
Add a trusted host
Richard Siddaway's Blog
by richardsiddaway
3y ago
Last time I showed how to read the trusted host list  – this is how you add a trusted host function add-trustedhost { [CmdletBinding()] param (   [string]$trustedhost,   [string]$computername = $env:COMPUTERNAME ) if (Test-Connection -ComputerName $computername -Quiet -Count 1) {    $th = Get-WSManInstance -ResourceURI winrm/config/client -ComputerName $computername |    Select-Object -ExpandProperty TrustedHosts   if ($th) {      $newth = $th + “, $trustedhost”    }    else {      $newth = $tru ..read more
Visit website
Trusted hosts
Richard Siddaway's Blog
by richardsiddaway
3y ago
You can use trusted hosts in WSMAN based PowerShell remoting to authenticate computers where Kerberos isn’t available. The WSMAN configuration is available through the WSMAN PowerShell drive or you can use the WSMANInstance cmdlets – available in Windows PowerShell v5.1, PowerShell 6.2 (Seem to have come back in at PowerShell v6.1) or PowerShell v7 function get-trustedhost { [CmdletBinding()] param (   [string]$computername = $env:COMPUTERNAME ) if (Test-Connection -ComputerName $computername -Quiet -Count 1) {    Get-WSManInstance -ResourceURI winrm/config/client -ComputerName ..read more
Visit website

Follow Richard Siddaway's Blog on FeedSpot

Continue with Google
Continue with Apple
OR