• Call Function with Parameters in PowerShell
    08 January

    PowerShell – Call Function with Parameters

    Using Positional Parameters To call a function, use positional parameters separated by space. Please note that you need to pass parameters in sequence while calling the function. [crayon-63dce6747df9b101655008/] [crayon-63dce6747dfa7069449302/] Microsoft’s PowerShell consists of a command-line shell and scripting language. It is based on the .NET framework for task automation and configuration management and helps power […]

  • 08 January

    Press Any Key to Continue in PowerShell

    Solutions for PowerShell Integrated Scripting Environment(ISE) and Command Line Console Using Read-Host Cmdlet Use the Read-Host command to enable press any key to continue in PowerShell. [crayon-63dce6747f514455446571/] [crayon-63dce6747f51e609749598/] The Read-Host cmdlet is the most commonly used and easy to understand. We used it to pause execution and prompt the user to get the input line […]

  • 08 January

    PowerShell – Unzip File

    Using Expand-Archive Cmdlet Use the Expand-Achrive cmdlet to unzip a file/folder in PowerShell. [crayon-63dce67480922521482979/] Please note that Expand-Archive cmdlet is available from PowerShell 5 onwards. Print envionment variable $PSVersionTable.PSVersion to check version of your PowerShell. We used the Expand-Achrive cmdlet to unzip a folder from the given location and save the unzipped folder in the […]

  • PowerShell - Write log to file
    07 January

    PowerShell – Write to Log File

    Using the Transcript To write to a log file using Transcript: Use the Start-Transcript cmdlet to start writing to the log file. Perform operations normally without writing anything to the file. Use the Stop-Transcript to stop the transcript. [crayon-63dce674822d3041991222/] [crayon-63dce674822db434444242/] A Transcript is a saved record of all the commands and output that a PowerShell […]

  • Get size of folder in PowerShell
    07 January

    PowerShell – Get Size of Folder

    Using Get-ChildItem with Measure-Object Use Get-ChildItem with the Measure-Object cmdlet to get the size of files in the specified directory. [crayon-63dce67483aff723268091/] [crayon-63dce67483b06586095121/] Please note that above sum doesn’t include subfolder sizes. If you want to include subfolder as well, header over to this section. The Measure-Object cmdlet was used to calculate the property values of […]

  • PowerShell - read file line by line
    07 January

    PowerShell – Read File Line by Line

    Using Get-Content Cmdlet Use the Get-Content cmdlet to read file line by line in PowerShell. [crayon-63dce67485394290800357/] [crayon-63dce6748539b277746009/] We used the Get-Content cmdlet to read the specified file line by line in PowerShell. It is used to get the content or data of the specified item; here, the specified item can be a text file or […]

  • Multiline comment in PowerShell
    05 January

    PowerShell – 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. [crayon-63dce67486c15592764031/] In programming, we use a comment block to provide explanations or details about the […]

  • Call PowerShell Script from another Script
    05 January

    Call PowerShell Script from Another Script

    Using . Operator To call a PowerShell script from another: Create two scripts, Script1.ps1 and Script2.ps1. Use the . operator to call Script2.ps1 from Script1.ps1. [crayon-63dce674881ca425276639/] [crayon-63dce674881d3416386592/] [crayon-63dce674881d4657828153/] [crayon-63dce674881d6621780381/] Both scripts (Script1.ps1 and Script2.ps1) were located in the E:\Test directory. When we ran Script1.ps1, it printed This message is from Script1.ps1 to the PowerShell console […]

  • Check if Service is running in PowerShell
    05 January

    Check 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. [crayon-63dce6748a169573762215/] [crayon-63dce6748a170829554971/] If you need to put if condition, then head over to this section . We used the Get-Service cmdlet to get a list of all services on a local computer; the list […]