PowerShell
- 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 […]
- 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 […]
- 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 […]
- 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-678f32c63d5ea139363797/] [crayon-678f32c63d5f2256325095/] [crayon-678f32c63d5f4154173859/] The args variable is an array that contains the value of all the parameters passed to […]
- 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 […]
- 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-678f32c63ec22851224370/] [crayon-678f32c63ec2a287429302/] 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, […]
- 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-678f32c63f4fe270560196/] [crayon-678f32c63f507431806481/] [crayon-678f32c63f509405213500/] […]
- 03 June
PowerShell Round to Whole Number
Using [Math]::Round Method Use the [Math]::Round to round number to whole number in PowerShell. [crayon-678f32c640022539755630/] [crayon-678f32c64002c175844729/] 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, […]
- 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-678f32c64098f092296896/] 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 […]