PowerShell Archive

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:

How to Run PowerShell Script on Remote Computer?

The functionality of remote command execution in PowerShell is called PowerShell Remoting (appeared in PowerShell 2.0) and is based on the capabilities of the Web Services for Management protocol (WS-Management). With PowerShell Remoting, you can run commands on one or several remote computers. You can use the interactive session

Viewing Office 365 User Account Details Using Get-MsolUser

In this article we’ll show you how to get a various information about Office 365 user accounts using the Get-MsolUser PowerShell cmdlet. The Get-MsolUser cmdlet allows you to view the properties of one or several Office 365 accounts, this is an analogue of the Get-ADUser cmdlet for on-premises Active