Tags » Powershell-basics

Preserving property order

This is a very common pattern:

$os = Get-CimInstance -ClassName Win32_OperatingSystem 
$comp = Get-CimInstance -ClassName Win32_ComputerSystem

$props = @{
  OS = $os.Caption
  InstallDate = $os.InstallDate
  LastBoot = $os.LastBootUpTime
  Make = $comp.Manufacturer
  Model = $comp.Model
}

New-Object -TypeName PSObject -Property $props… 130 more words
Powershell Basics

Calculating Standard Deviation – the class

You’ve seen how to calculate standard deviation and how to turn that calculation into a PowerShell function. This time we’ll use the calculation to create a class:

class stats {
  
  static  StandardDeviation (]$numbers) {

    $mean = $numbers | Measure-Object -Average | select -ExpandProperty Average
    $sqdiffs = $numbers | foreach {::Pow(($psitem - $mean), 2)}

    $sigma = ::Sqrt( ($sqdiffs | Measure-Object -Average | select -ExpandProperty Average) )
    
    return ::Round($sigma, 3)
    
  }
} 91 more words
Powershell Basics

Calculating Standard Deviation - the function

Last time I showed how to calculate the standard deviation of a set of numbers and said the code could easily be turned into a function… 81 more words

Powershell Basics

Calculating Standard Deviations–the calculation

A while ago I saw something asking about calculating standard deviations for a set of numbers in PowerShell. You can calculate the the mean (average) of a set of numbers using Measure-Object… 169 more words

Powershell Basics

using help proactively

I was reading a thread on the forum about using a particular cmdlet and it occurred to me that the person posing the question hadn’t actually looked at the help file for the cmdlet. 139 more words

Powershell Basics

Update-Help errors

Updatable help brings the benefit of up to date help with typos fixed and new edge cases described. The down side is that it sometimes fails: 225 more words

Powershell Basics

Boolean in Where-Object filter

I was testing some code yesterday and realised there was a quirk in the way the original where syntax (with {}) worked and the way the newer syntax worked. 196 more words

Powershell Basics