Monthly Archives: August 2018

PowerShell string contains

How can you check if a PowerShell string contains a character or substring? You might be tempted to try this: PS> $s = ‘abcdefghijk’ PS> $s -contains ‘f’ False But –contains is for working with the contents of arrays. So … Continue reading

Posted in Powershell | 1 Comment

PowerShell Day UK Agenda Update

There’s been a Powershell Day UK Agenda Update. Looks like there’ll be three tracks for most of the day. Full agenda and tickets from – https://psday.uk/

Posted in Powershell | Leave a comment

PowerShell v6.1– using PowerShell v5.1 modules

Something new to be aware of in PowerShell v6.1– using PowerShell v5.1 modules . In PowerShell v6.0.4 the default module path is PS>  $env:PSModulePath -split ‘;’ C:\Users\Richard\Documents\PowerShell\Modules C:\Program Files\PowerShell\Modules c:\program files\powershell\6.0.4\Modules If you want to use the netadapter cmdlets for … Continue reading

Posted in PowerShell v6 | Leave a comment

PowerShell v6.1 release candidate 1

PowerShell v6.1 release candidate 1 is now available from https://github.com/PowerShell/PowerShell/releases The release notes don’t show any major new functionality compared to preview 4 though there are a number of minor updates, changes and bug fixes.

Posted in PowerShell v6 | Leave a comment

Deleting folders based on month name

An interesting problem around deleting folders based on month name. You have a folder structure that looks like this C:\Testdata\2011\08-Aug C:\Testdata\2011\09-Sep C:\Testdata\2011\10-Oct C:\Testdata\2011\11-Nov C:\Testdata\2011\12-Dec C:\Testdata\2012\01-Jan C:\Testdata\2012\02-Feb C:\Testdata\2012\03-Mar C:\Testdata\2012\04-Apr C:\Testdata\2012\05-May C:\Testdata\2012\06-Jun C:\Testdata\2012\07-Jul C:\Testdata\2012\08-Aug C:\Testdata\2012\09-Sep C:\Testdata\2012\10-Oct C:\Testdata\2012\11-Nov C:\Testdata\2012\12-Dec C:\Testdata\2013\01-Jan C:\Testdata\2013\02-Feb C:\Testdata\2013\03-Mar C:\Testdata\2013\04-Apr … Continue reading

Posted in Powershell | Leave a comment

File searches with WMI

I saw a question about file searches with WMI. If you just know the file name it’s a very slow process. Painfully slow. If you have an idea about the folder its much quicker. function get-wmifile { [CmdletBinding()] param (   … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

Variable type

Usually when you create a variable you implicitly set the type by the value you use. Sometimes though you may want to explicitly set the variable type. if you don’t give the variable a type you can do this: PS> … Continue reading

Posted in Powershell | Leave a comment

Read only and constant variables

When you create a variable you usually want to be able to change its value – the clue is in the term variable. Sometimes though you might want to use a value that doesn’t change – you want read only … Continue reading

Posted in Powershell | Leave a comment

user logon time

Saw an interesting question about user logon time. How can you tell the logged on user and when they logged on $logon = Get-CimInstance -ClassName Win32_LogonSession | sort StartTime -Descending | select -First 1 $user = Get-CimAssociatedInstance -InputObject $logon -ResultClassName … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

Splitting on a \

Splitting strings is usually easy – you use the –split operator or the Split() method.  Occasionally you may hit a problem – for instance splitting on a \ character. Let me demonstrate with an example. PS> Get-CimInstance -ClassName Win32_ComputerSystem | … Continue reading

Posted in Powershell | Leave a comment