PowerShell Archive

Get-service: Checking the Status of Windows Services with PowerShell

You can use the Get-Service cmdlet to get a list of all the services installed on the Windows operating systems, their status and startup type. This one and other cmdlets to get the status and management of Windows services first time appeared in Powershell 1.0. In this article we...

How to Create a GUI for PowerShell Scripts?

One of the significant drawbacks of PowerShell scripts, when used by users (not sysadmins or programmers), is its command-line interface. The result of the scripts is displayed in the PowerShell CLI console and it is not always convenient for the end user. However, Powershell is a powerful and modern...

How to Check Windows Uptime?

Uptime is the measure of the uninterrupted time that an operating system experiences since the last boot. Unlike Linux/Unix, Windows doesn’t have a native uptime command. On Windows, you can get the computer uptime value in several different ways: from the GUI, command prompt, or PowerShell. Let’s consider all...

PowerShell Comparison Operators

PowerShell comparison operators allow you to find out if the value of a variable contains a string, is it larger, smaller, or equal to some value, etc. Most programming languages use symbols as comparison operators, like <, >, !=, =, however, in PowerShell, pseudo-commands are used instead of these...

PowerShell: Script for Loop through Files and Folders

In this article, we will look at examples of using constructions to loop over all files and folders on a disk or in a specific directory that you can widely use in your PowerShell scripts. Usually, the task of iterating over all file system objects in a directory arises...

PowerShell: Function Return

Most PowerShell newbies believe that PowerShell functions can return a value only through the Return statement. The return statement usually terminates the function and returns control to the calling function. But in Windows PowerShell, this is not entirely true… In this article, we will look at how to return...

PowerShell Function Parameters: How to Add?

When developing your PowerShell functions, sometimes you need to put some input values to your functions, such as a file name, string, or any other value. In PowerShell, there are two ways to pass parameters to functions: through the $Args variable and by setting formal parameters. Passing Parameters to...

Using GPUpdate to Update Group Policy Settings

After changing any Group Policy setting using the local GPO editor (gpedit.msc) or domain policy editor (gpmc.msc), the new policy setting is not immediately applied to the user/computer. You can wait for automatic updating of GPO (up to 90 minutes), or you can update and apply policies manually using...

Using WhatIf Parameter in PowerShell

The -WhatIf parameter in PowerShell scripts is typically used to avoid accidental changes to managed objects. Adding the -WhatIf parameter to the PowerShell command will display the objects to be changed by this command and the changes made. At the same time, no changes are actually made. For example,...

PowerShell: Switch Statement Usage

Usually, an if-else construct is used to test conditions in PowerShell scripts. If you need to immediately check several conditions instead of doing complex constructions with if-else, it is much easier to use the switch statement. The syntax of the construction with the Switch operator is looks like follow:...