header image

Archive for May, 2018

Splitting into pairs

Posted by: | May 31, 2018 Comments Off on Splitting into pairs |

During my session on scriptblocks at Summit 2018 I showed how to split a string into pairs of values Start with this string PS> $str = ‘Jack,Jill,Bill,Ben,Eric,Ernie,Cagney,Lacey’   You want the string split in the commas – but every other comma so you get pairs if values separated by a comma. You need to set […]

under: PowerShell

Summit 2018 sessions

Posted by: | May 31, 2018 Comments Off on Summit 2018 sessions |

The code and slides from my Summit 2018 sessions can be found at https://github.com/RichardSiddaway/Summit2018TroubleShootingRemoting and https://github.com/RichardSiddaway/Summit2018ScriptBlocksDecoded

under: PowerShell, Summit

PowerShell functionality

Posted by: | May 31, 2018 Comments Off on PowerShell functionality |

PowerShell functionality – in the form of modules – comes from a number of different sources. These are: Powershell itself including the Microsoft.PowerShell.* modules and CIM cmdlets Windows Team – this includes the modules such as NetAdapter, NetTCPIP, Storage that were first introduced with Windows 8 and have been part of all subsequent Windows client […]

under: PowerShell

Hyper-V book

Posted by: | May 28, 2018 Comments Off on Hyper-V book |

The Month of Lunches Hyper-V book I was working on was cancelled by the publisher. The good news is that it’s most likely going to be resurrected with another publisher and will hopefully be available later this year. More to follow when the details are finalised

under: Hyper-V

WMI and CIM accelerators

Posted by: | May 26, 2018 Comments Off on WMI and CIM accelerators |

In PowerShell an accelerator is a shortcut to a .NET type. The WMI accelerators have been around since PowerShell v1. The WMI accelerators were heavily used in v1 fill some of the gaps in cmdlet coverage. The CIM accelerators appeared in PowerShell v3 (I think – only discovered them recently!). This is how you use […]

under: PowerShell and CIM, PowerShell and WMI

PowerShell parameter sets

Posted by: | May 22, 2018 Comments Off on PowerShell parameter sets |

PowerShell parameter sets allow you to control which parameters can be used together. If a parameter isn’t in the parameter set you’re trying to use you’ll get an error message. PS> Get-VM -Name XYZ -id (New-Guid) Get-VM : Parameter set cannot be resolved using the specified named parameters. At line:1 char:1 + Get-VM -Name XYZ […]

under: PowerShell

PowerShell version

Posted by: | May 22, 2018 Comments Off on PowerShell version |

Discovering the PowerShell version you’re using can be an interesting task. The automatic variable $PSVersionTable was introduced in PowerShell v2. On my Windows 10 version 1803 machine for Windows PowerShell I get PS> $PSVersionTable Name Value —- —– PSVersion 5.1.17134.48 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} BuildVersion 10.0.17134.48 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 […]

under: PowerShell v5, PowerShell v6

Format Data

Posted by: | May 18, 2018 Comments Off on Format Data |

PowerShell will format the output of objects that it knows about. For instance Get-Process shows different sets of properties depending on whether you choose a table or list view. The format data is stored in files named *.format.ps1xml. In Windows PowerShell the format files are found in C:\Windows\System32\WindowsPowerShell\v1.0. In PowerShell v6 the format files are […]

under: PowerShell v6

where –not

Posted by: | May 15, 2018 Comments Off on where –not |

PowerShell v6.1 preview 2 has added the where –not option. The option adds another parameter to the syntax where-object <property name> <operator like parameter> <value>   Couple of examples of using the syntax Get-Process | where CPU -gt 12 Get-Service | where Status -like ‘Stop*’   Use –Not when you’re looking for properties that aren’t […]

under: PowerShell v6

Calculating standard deviation

Posted by: | May 11, 2018 Comments Off on Calculating standard deviation |

Calculating a standard deviation isn’t a difficult exercise but PowerShell v6.1 offers an easier method.   In Windows PowerShell v5.1 and PowerShell v6.0 the Measure-Object cmdlet has this syntax PS> Get-Command Measure-Object -Syntax Measure-Object [[-Property] <string[]>] [-InputObject <psobject>] [-Sum] [-Average] [-Maximum] [-Minimum] [<CommonParameters>] Measure-Object [[-Property] <string[]>] [-InputObject <psobject>] [-Line] [-Word] [-Character] [-IgnoreWhiteSpace] [<CommonParameters>]   In […]

under: PowerShell v6

Older Posts »