Author: Java2blog
05 JanuaryPowerShell – Multiline Comment
Using <# #> Tags Use the <# tag at the beginning of comments and the #> tag at the end of comments to create multiline comments in PowerShell scripts. All lines inside the comment block are part of the comments. <# Hello, this is 1st line of multiline comments, this is 2nd line, this is […]
05 JanuaryCall PowerShell Script from Another Script
1. Introduction to the Problem Statement PowerShell, a powerful scripting language and command-line shell, is widely used for automation in Windows environments. A common requirement in PowerShell scripting is to call one script from another, enabling modular programming and reusability of code. Suppose we have two scripts: ChildScript.ps1: This script performs a task and returns […]
05 JanuaryWhat is awk print $2
In this tutorial, we will see about what is meant by awk print $2. awk is interpreted programming language. It is very powerful programming language and used for text processing. Awk stands for the names of its authors “Aho, Weinberger, and Kernighan”. awk print $2 As said before, awk can be used for text processing. […]
05 JanuaryCheck if Service is Running in PowerShell
Using Get-Service Cmdlet Use Get-Service with the Where-Object cmdlet to check if a particular service is running on our local machine. Get-Service | Where-Object { ($_.Status -EQ "Running") -and ($_.DisplayName -EQ "Workstation") } Status Name DisplayName ------ ---- ----------- Running LanmanWorkstation Workstation If you need to put if condition, then head over to this section […]
05 JanuaryRun .reg File Using PowerShell
Using Invoke-Item Cmdlet Use the Invoke-Item cmdlet to run the .reg file using PowerShell. Invoke-Item ".\file.reg" For the above command, Invoke-Item performed its default action, which means it allowed us to execute a .reg file. We can also use it to run a file, for instance, a script file. When we ran the Invoke-Item cmdlet […]
05 JanuaryPowerShell – Restart Computer
Using Restart-Computer cmdlet Use the Restart-Computer cmdlet to restart the local/remote computer. The syntax of this command is given below. Restart-Computer [parameters] The Restart-Computer command has some parameters that we can use based on our requirements. You can find parameter names and their description below: Parameter Description ComputerName It is used to enter the system’s […]
05 JanuaryGet Current Directory in PowerShell
Using Get-Location Cmdlet Use the Get-Location cmdlet to get the path of the current working directory in PowerShell. Get-Location Path ------ C:\Users\DELL As we can see above, our current working directory is C:\Users\DELL, which means we are currently working in the DELL folder within the Users folder on the C drive of the Windows operating […]
04 JanuaryPowerShell – Check If Variable Is Null
1. Introduction In PowerShell, checking if a variable is null (or in PowerShell terms, $null) is a fundamental task in scripting, especially when dealing with the output of commands, function returns, or processing user input. For instance, a variable storing data from database might be null if no data is present. In this article, we […]
03 JanuaryPowerShell – Get Filename from Path
PowerShell – Get Filename From Specified Path The location of a file on a system can be determined by its path. In PowerShell, there are several ways to get filename from path. Firstly, it’s essential to understand what is in a path before going into depth. What is in a Path? A path indicates the […]