• 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. [crayon-662c169930fc4495612227/] [crayon-662c169930fcd284046397/] [crayon-662c169930fcf539584470/] The args variable is an array that contains the value of all the parameters passed to […]

  • 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. [crayon-662c169933051000820083/] [crayon-662c16993305a229701647/] First, a string variable named $string and an array variable called $delimiters is defined. Then, the $string is assigned with "one,two;three four", while $delimiters is set with "[,; ]+". After that, […]

  • 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. [crayon-662c1699338e5932130676/] [crayon-662c1699338ed496585278/] [crayon-662c1699338ee945772888/] […]

  • 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. [crayon-662c169934e4c523446099/] [crayon-662c169934e54471937418/] We can observe the [Math]::Round method rounds a decimal number to the nearest whole number. In PowerShell, the [Math]::Round method takes two arguments: The number that you want to round. The number of decimal places to round to. Here, […]

  • 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. [crayon-662c169935883407788912/] Here, we used the New-Object cmdlet to create an instance of the WSH (Windows Script Host) Shell object using COM (Component Object Model) technology and stored it […]