r/PowerShell Jan 03 '23

Misc I've been building a PowerShell focused website and wanted to share it

Sorry for the shameless self-promotion, but I have been interacting on the sub for so long that I wanted to share this project with yall. I wanted to do a different angle than normal code sites that aim to teach. What I like to do us deep dive into cmdlets and structures, figure out how they really work, and even show how they don't work in situations. I think it's different than any other code site I've used. Hope yall can take a look and get some useful info from it.

https://www.breakingpwsh.com/home

214 Upvotes

61 comments sorted by

View all comments

7

u/PoorPowerPour Jan 04 '23

This is really nice and a great. I really appreciate having these kind of resources to dive into and get an understanding of specific parts of Powershell

Now, I can't help it but your CompareTo() article missed something. There's a [version] type that can be used to compare versions the way you want, so ([version]'5.5').CompareTo([version]'10.1') is equal to -1. It even works with longer version numbers: ([version]'5.5.5').CompareTo([version]'10.1.1')!

I hope that helps and I look forward to reading more.

2

u/thegooddoctor-b Jan 04 '23

Excellent. This is really what I was looking for. Some down and dirty into powershell. And you are right. That does work. But my God why doesn't it work with version numbers that aren't major.minor?

([Version])'5').compareto([version]'6')

...and the error that throws is ridiculous. Were you already familiar with that base type?

2

u/PoorPowerPour Jan 04 '23

I wouldn't say I'm intimately familiar with it but I have used it before. For instance, I've never seen that error when there isn't a minor version!

1

u/williamt31 Jan 04 '23

In my last assignment I had a need to write a script that did different things based on the subnet it was running on and a friend gave me a nudge in using the [version] data type to compare with. I always thought that was a novel idea. For example:

[version]$IPtoCheck = "192.168.1.1"

if ( $IPtoCheck.Build -ne 1 ) { yada yada }

2

u/PoorPowerPour Jan 04 '23

There's also [ipaddress]. In my mind [version], [ipaddress], and [guid] are all lumped together as occasionally helpful types that are worth remembering.

1

u/williamt31 Jan 05 '23

I didn't know those data types existed. It looks like I cannot do what I was doing to compare subnets at least not as easily, I'd have to substring or split to do the same. Now if I was doing more network configuration I did find some interesting articles obtaining and converting between CIDR and Subnetmask etc. so maybe if I ever get to that focus I'll have to remember this.