In this quick tip, I’m going to show you a way to organize and quickly access special symbols in PowerShell. (more…)
Tag: QuickTip
Quick tip: Conditional logic based on Parameter Set Name
When writing advanced functions with two (or more) parameter sets, sometimes you need to use conditional logic based on what parameter set is in use. This can be achieved easily by using the built-in PSCmdlet variable. (more…)
Quick tip: Dynamically create and use variables
Creating and using variables in PowerShell is simple. Unlike most other languages you don’t need to initialize a variable before use – you don’t even need to type them; PowerShell will attempt to set the type based on the value you give it. Because they are so simple to use, it’s easy to forget that we actually have a set of cmdlets for working with variables. (Get/Set/New/Clear/Remove-Variable) But that’s ok, they are seldom needed. But in this quick tip I will show you how to create and use variables dynamically, and then they come in handy indeed. (more…)
Quick tip: Determine if input comes from the pipeline or not
Usually you shouldn’t need to know whether data input comes from the pipeline or a parameter, but in case you are in a position where you really need to know, this post will show you a quick and easy way of determining this. (more…)
Quick tip: Get all .NET cultures
If you are working with different cultures, this quick tip might be for you. This is a one-liner that will show all cultures that ship with .NET, including neutral and specific cultures. (more…)
Quick tip: Convert to Title Case
Most people know how to convert a string to all upper case or all lower case. In this quick tip, I’ll show you how to use ‘TextInfo’ to convert a string to Title Case. (more…)
Quick tip: Integer parameter validation
Validating your parameters are important. This quick tip is about integer parameters. (more…)
Quick tip: Get all About help topics in PowerShell
Get-Help is arguably the most useful cmdlet in PowerShell, and will give you help and examples for all commands and functions. But did you know that there are more help topics available? (more…)
Quick tip: Accessing the Control Panel from PowerShell
I haven’t seen many people use this, but it’s quite simple to access items in the Control Panel directly from PowerShell, using the Get-ControlPanelItem and Show-ControlPanelItem cmdlets.
(more…)
Quick tip: Enum with string values
Using enums can come in handy in many situations. When writing an advanced function in PowerShell, using an enum as the parameter type will ensure that only valid values are used, as well as give you tab-complete functionality (The same can be achieved using ValidateSet).
Now, I was working on extending my Mockaroo function when I found myself in a position where I needed to validate a large amount of values for a parameter. I decided on an enum, but I had problem – some of the values where strings with spaces in them, and I was going to use the parameter value when creating a URI for the Mockaroo API, so I’d rather avoid using a huge switch-statement translating the enum values to strings.
(more…)