Chirag Nagrekar has Published 465 Articles

How to create a Dictionary in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-Dec-2020 07:51:06

10K+ Views

To create a dictionary in the PowerShell we need to use the class Dictionary from the .Net namespace System.Collections.Generic. It has TKey and TValue. Its basic syntax isDictionaryTo learn more about this .Net namespace check the link below.https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-5.0To create a dictionary we will first create the object for the dictionary object ... Read More

How to convert JSON file to CSV file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-Dec-2020 07:48:53

20K+ Views

To convert the JSON file to the CSV file using PowerShell, we need to use the ConvertTo-CSV command as a pipeline.For example, we have a JSON file called PatchingServer.JSON stored at C:\temp and its content is as below.ExamplePS C:\> Get-Content C:\Temp\PatchingServer.json {    "Port": "9000",    "ApplicationName": "TestApp",    "MaintenanceWindow": "Every ... Read More

How to find Windows Product Key Using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-Dec-2020 07:45:06

4K+ Views

Windows Product key can be retrieved using PowerShell or CMD. To retrieve the product key using PowerShell, we need to query SoftwareLicesingService class and there is a property called OA3xOriginalProductKey which stores the product key.ExampleGet-WmiObject -query `select * from SoftwareLicensingService' | Select OA3xOriginalProductKeyOutputOA3xOriginalProductKey ---------------------- BBBBB-CSDSC-EESSR-KKIDS-AAAAAWe can also query this WMI class ... Read More

How to find a Computer product serial number using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 15-Dec-2020 07:43:59

4K+ Views

Generally, Product serial numbers are available at the back of the laptop on the company sticker and we can use the Third-party or manufacturer software to find the Product details. The product serial number can also be found using the BIOS utility or command. We can either use the BIOS ... Read More

How to set the line breakpoint in the PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:56:47

486 Views

To set the line breakpoint in the script, we can use the Set-PSBreakpoint command with -Line parameter and need to give the path of the script on which the Line breakpoint needs to set.Consider we have the script below which retrieves the value up to 99, starting from 1, We ... Read More

What is the breakpoint in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:54:14

214 Views

Breakpoint in the PowerShell is the part of the debugger in the PowerShell commands. We use the breakpoints in PowerShell mainly for troubleshooting and logging purpose.There are three ways to set the breakpoint in PowerShell.Line BreakPoint (Can set the breakpoint for single or multiple lines)Command BreakPoint (Can set the breakpoint ... Read More

How to check if the file is empty using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:52:57

6K+ Views

To check if the file is empty using PowerShell, we can use the string method called IsNullorWhiteSpace(). This method provides result true if the file is empty or only contains the white spaces otherwise false.For example, We have a test2.txt text file which has whitespaces.Example[String]::IsNullOrWhiteSpace((Get-content C:\Test2.txt))OutputTrueBut if you have a ... Read More

How to open any file with its default application with PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:51:40

2K+ Views

To open any file using its default application, we can use the Invoke-Expression command. For example, we want to open a file on the C:\temp and the file name is NewUsers.CSV then you can run the below command.Invoke-Expression C:\Temp\NewUsers.csvThe above command will open the file from that location. If the ... Read More

How to convert raw text to the CSV (Comma Separated Values) in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:50:44

864 Views

We have a raw text example and to convert it into the CSV values, we can use below code.ExamplePS C:\> $text = "This is a PowerShell latest version" PS C:\> $text.Replace(' ', ', ')OutputThis, is, a, PowerShell, latest, versionIf there are multiple spaces between the keywords then the above replace ... Read More

How to get the list of opened applications in windows with PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 20-Nov-2020 08:49:49

3K+ Views

We can get the list of opened applications in Windows using PowerShell using Get-Process command. Get-Process command shows the currently running processes in the foreground and the background as well.If we simply run the Get-Process command then it will give the process names and their associated process IDs and CPU, ... Read More

Advertisements