• PowerShell change service logon account
    19 June

    PowerShell Change Service Logon Account

    Do you know what the service logon accounts are? The services are background processes that keep running without any user interface in the Windows operating system. These services are often set up to run under a particular user account, which we call a service logon account or a service account. This service account determines the […]

  • Powershell add users to administrators group
    18 June

    PowerShell Add User to Administrators Group

    The user must have administrative privileges to use the following commands. Also, the user must be created on the computer to add to the administrators group. Using *-LocalGroupMember Cmdlet Using PowerShell, we can use the *-LocalGroupMember command to add/check/remove one or multiple users to the administrators group. Here, * can be Add, Get, or Remove […]

  • PowerShell cannot index into null array
    18 June

    Cannot Index into a Null Array in PowerShell

    If you are encountering the error message Cannot index into a null array in PowerShell, this indicates that you are trying to access an index of an array that doesn’t exist or has not been initialized yet. This error may also occur if you access the array set to $null. Let’s reproduce the error before […]

  • Pass multiple parameters to Powershell script
    17 June

    Pass Multiple Parameters to PowerShell Script

    All the code snippets are written in the MyScript.ps1 file; you can name this file to any name of your choice. Using Automatic Variable $args Use automatic variable $args to pass multiple parameters to PowerShell script. foreach ($arg in $args) { Write-Host "Argument: $arg" } .\MyScript.ps1 "Param1" "Param2" "Param3" Argument: Param1 Argument: Param2 Argument: Param3 […]

  • PowerShell get object property value by name
    13 June

    PowerShell Get Object Property Value by Name

    Getting Object’s First Level Property Value by Name In PowerShell, we have multiple ways to get an object’s first-level property value by using its name. Before diving into the solutions, it is mandatory to understand how objects are created in PowerShell (if you already know it, you can jump to the solutions). We will use […]

  • PowerShell Split String by multiple delimiters
    07 June

    PowerShell Split String by Multiple Delimiters

    Using -split Operator with Regular Expression Use the -split operator with a regular expression to split string by multiple delimiters in PowerShell. $string = "one,two;three four" $delimiters = "[,; ]+" $parts = $string -split $delimiters $parts one two three four First, a string variable named $string and an array variable called $delimiters is defined. Then, […]

  • PowerShell replace String in File
    04 June

    PowerShell Replace String in File

    Using -replace Operator To replace a string in a text file: Use the Get-Content cmdlet to read the text file’s content. Use the -replace operator to replace the old string with a new string in the given text file. Use the Set-Content cmdlet to write the modified content to the text file. This is a […]

  • PowerShell round to whole number
    03 June

    PowerShell Round to Whole Number

    Using [Math]::Round Method Use the [Math]::Round to round number to whole number in PowerShell. $decimalNum = 3.14159 $roundedNum = [Math]::Round($decimalNum, 0) Write-Host "Original number: $decimalNum" Write-Host "Rounded number: $roundedNum" Original number: 3.14159 Rounded number: 3 We can observe the [Math]::Round method rounds a decimal number to the nearest whole number. In PowerShell, the [Math]::Round method […]

  • PowerShell script to keep screen active
    30 May

    PowerShell Script to Keep Screen Active

    Using while Loop with SendKeys() Method Use the while loop to invoke the SendKeys() method for an unlimited time to keep the PC/Laptop screen active using PowerShell. $wScriptShellObj = New-Object -Com "Wscript.Shell" while (1) { $wScriptShellObj.SendKeys(".") Sleep 2 } Here, we used the New-Object cmdlet to create an instance of the WSH (Windows Script Host) […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.