PowerShell for Windows Admins:

August, 2018


August 31, 2018  6:05 AM

PowerShell string contains

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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 you could do this: PS> ($s.ToCharArray()) -contains...

August 28, 2018  4:42 AM

PowerShell Day UK Agenda Update

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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/


August 23, 2018  3:21 PM

PowerShell v6.1– using PowerShell v5.1 modules

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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...


August 23, 2018  5:05 AM

PowerShell v6.1 release candidate 1

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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...


August 21, 2018  4:30 AM

Deleting folders based on month name

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

An interesting problem around deleting folders based on month name. You have a folder structure that looks like...


August 19, 2018  8:12 AM

File searches with WMI

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, 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 ( [Parameter(Mandatory =...


August 18, 2018  6:03 AM

Variable type

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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> $x = 35 PS> $x 35 PS> $x = 'now a string' PS> $x now a...


August 16, 2018  4:48 AM

Read only and constant variables

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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 and constant variables. Standard variables are changeable: PS> $x = 10 PS>...


August 15, 2018  8:23 AM

user logon time

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

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...


August 15, 2018  4:04 AM

Splitting on a \

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

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 | select...


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: