PowerShell
- 27 May
PowerShell Add Quotes to String
Using Backtick Characters Use backtick characters to add double quotes to string in PowerShell. [crayon-678f49fb9bdfd381360226/] [crayon-678f49fb9be04103955773/] Backtick character is escape character in PowerShell. Here, it is used to escape double quotes in the String. Use backtick characters to add single quotes to string in PowerShell. [crayon-678f49fb9be05347623028/] [crayon-678f49fb9be06061554790/] Using String Concatenation Operator Use string concatenation operator […]
- 27 May
PowerShell Add Array to Array
Using + Operator Use the + operator to add an array to another array. [crayon-678f49fb9e38e117760089/] [crayon-678f49fb9e394032136618/] First, we used the array operator represented by @() to declare two arrays, $array1 and $array2, containing the values 1,2,3and 4,5,6. After that + operator is used to concatenate the two arrays together into a $newArray. In PowerShell, when […]
- 27 May
PowerShell Check If Account Is Locked
Check if AD account is locked To check if AD account is locked, use Get-ADUSer cmdlet and select LockedOut property using Select-Object cmdlet. Here is the code: [crayon-678f49fb9e89f263349202/] [crayon-678f49fb9e8a3226101112/] Replace DELL with the username for which you want to check if AD account is locked or not. Get-ADUSer cmdlet is used to get specific user […]
- 06 May
PowerShell Compare LastWriteTime of Two Files
Using LastWriteTime property To compare LastWriteTime of two files in PowerShell: Use Get-Item to get items. Use the if-else block to compare LastWriteTime of both files. [crayon-678f49fb9ed42622601524/] [crayon-678f49fb9ed47096100835/] Using Compare-Object Cmdlet To compare the LastWriteTime of two files in PowerShell: Use Get-Item to get items. Use the Compare-Object cmdlet to compare the LastWriteTime of two […]
- 04 May
Check if AD User Exists in PowerShell
In PowerShell, we must import the ActiveDirectory module to use the Get-ADUser cmdlet. If you have imported it already, you can jump to the Checking If AD User Exists in PowerShell section; otherwise, let’s continue with us step-by-step below. Installing the ActiveDirectory Module To import the ActiveDirectory module, we first need to install it. So, […]
- 03 May
Get Logged on Users in PowerShell
This topic can be interpreted as getting all current logged-on users and retrieving one logged-on user in PowerShell. Let’s learn both interpretations. 1. Introduction to the Problem Statement In network and system administration, it’s often necessary to determine which users are currently logged on to a system. This information can be critical for security, auditing, […]
- 03 May
Append Data to File using PowerShell
Appending Text to a Text File We have various approaches to append content in a text file using PowerShell. For example, we can append information on the same line, on a new line with/without special characters, on multiple lines, and append formatted data such as tabular content. But, before moving towards possible solutions, it is […]
- 02 May
Check if Arguments Exists in PowerShell
In PowerShell, it is essential to check whether arguments exist, especially when creating scripts that take input parameters. However, before delving into the specifics of developing a PowerShell script that accepts arguments and checks for their presence, learning how to create a script .ps1 file within a directory is essential. You need to go through […]
- 02 May
Combine Multiple Conditions in if Statement in PowerShell
We use an if statement with logical operators and comparison operators to combine multiple conditions in PowerShell. We also use parentheses represented by (()) to group conditions and control the evaluation order. So, it is essential to know what logical, arithmetic and comparison operators we have, what they mean and what they can do. See […]