PowerShell uses execution policy to determine which scripts to run. There are in fact five scopes where execution policy can be defined, and to see...
Powershell
Checking Execution Policy
Execution policy determines what kind of scripts PowerShell will execute. You need to set execution policy to something other than Undefined,...
Classes (Static Members – Part 6)
Classes can define so-called “static” members. Static members (properties and methods) can be invoked by the class itself and do not...
Using Classes (Constructors – Part 5)
Classes can have so-called constructors. Constructors are methods that initialize a new object. Constructors are simply methods that share the name...
Using Classes (Overloading – Part 4)
Methods in classes can be overloaded: you can define multiple methods with the same name but different parameters. This works similar to parameter...
Using Classes (Adding Methods – Part 3)
One of the great advantages of classes vs. [PSCustomObject] is their ability to also define methods (commands). Here is an example that implements a...
Using Classes (Initializing Properties – Part 2)
Class properties can be assigned a mandatory type and a default value. When you instantiate an object from a class, the properties are pre-populated...
Using Classes (Creating Objects – Part 1)
Beginning in PowerShell 5, there is a new keyword called “class”. It creates new classes for you. You can use classes as a blue print...
Using “Using Namespace”
Working with .NET type names can be tiring because these names can be long. Here is an example: #requires -Version 2.0 Add-Type -AssemblyName...
Determining Person Age
How do you calculate the age of a person, based on birthday? You can subtract the current time delivered by Get-Date from the birthday, but the...
Speeding Up New-Object Synthesizer
New-Object creates new instances of objects, and you have seen one example in the past “Speech Week”: PowerShell was able to create a...
Speech-Week: Using Advanced Speech Synthesizer Options Synthesizer
The .NET speech engine accepts more than just plain text. If you use SpeakSsml() instead of Speak(), you can use XML to switch languages, speak...
Speech-Week: Recording Voice to File Synthesizer
The built-in Microsoft text to speech engine can save audio to a file. This way, you can auto-generate WAV files. Here is an example: it creates a...
Speech-Week: Using Different Voices with Speech Synthesizer
In the previous tip we showed how you can tap into the text to speech converter and speak out text. Here is a way to find out the installed...
Speech-Week: Using a Speech Synthesizer
When you add the assembly “System.Speech” to PowerShell, there is a new type called “SpeechSynthesizer” which can be used to...
Adding and Removing Backslashes
For path components, it is often necessary to “normalize” paths and, for example, make sure they all end with a backslash. Some try code...
Checking Number of Digits in Integer
Sometimes you might want to check the digits of an integer, i.e. to validate user input. Here is a really simple way using regular expressions: #...
Opening PowerShell Inside Explorer
A quick way of opening PowerShell is to launch Windows Explorer, navigate to the folder with your data, then click into the navigation bar. The...
Hiding Progress Bars
Some cmdlets and scripts use progress bars to indicate progress. As you learned in the previous tip, progress bars cause delays, so if you...
Using a Progress Bar Wisely
PowerShell comes with support for progress bars. Here is a very simple example: 1..100 | ForEach-Object { Write-Progress -Activity...
Bulk Renaming Photos
Here is a quick and fast way to bulk-rename files like photos, or other files. Have a look: #requires -Version 1.0 $Path = "$home\Pictures" $Filter...
Identifying Locked AD Accounts
When searching for specific AD accounts, you may have used Get-ADUser in the past, and filtered results with a filter parameter. Such filters can...
Exploring Local Account Management Cmdlets
PowerShell 5.1 (shipping with Windows 10 and Server 2016) can now natively manage local accounts. In the previous tip you learned how to use...
Managing Local Users
PowerShell 5.1 finally ships with cmdlets to manage local user accounts. To get a list of local user accounts, use Get-LocalUser and pipe the result...