• PowerShell kill process by name
    20 June

    PowerShell Kill Process by Name

    Using Stop-Process Cmdlet Use the Stop-Process cmdlet to kill a process by name in PowerShell. [crayon-67680a2dc6875051992315/] The Stop-Process command stops a process by its name. The -Name parameter specifies the name of the process to stop. For example, if you want to stop the notepad program, write Stop-Process -Name "notepad". You can check all running […]

  • 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-67680a2dca99b019661758/] [crayon-67680a2dca9a1125246861/] [crayon-67680a2dca9a3638475748/] The args variable is an array that contains the value of all the parameters passed to […]

  • Bash check if environment variable is set
    13 June

    Bash Check If Environment Variable Is Set

    Using if-else with -z,-v,-n Options Use the if-else statement with the -v option to check if an environment variable is set in bash. The echo command in the if block will be executed if the [-v HOME] will be true, and it will be true if the specified variable is set. [crayon-67680a2dcb26a430222601/] [crayon-67680a2dcb286776895765/] The -v […]

  • 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-67680a2dce0ff075183079/] [crayon-67680a2dce105472709794/] 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-67680a2dce4d7618972690/] [crayon-67680a2dce4dc250747780/] [crayon-67680a2dce4dd386038435/] […]