Chirag Nagrekar has Published 465 Articles

How to check if PSCustomObject is empty in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:41:09

3K+ Views

To check if the PSCustomObject is empty or not in PowerShell, we need to check the fields of the PSCustomObject. Consider the below example, Example$output = [PSCustomObject]@{    Name = 'John'    City = 'New York'    Country = 'US'    Company = 'Alpha'   } $output1 = [PSCustomObject]@{    Name = ''   ... Read More

How to delete all the file contents using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:38:06

3K+ Views

If you want to delete the entire text file content using PowerShell, then we can use the Clear-Content command. For example, we have the below text file called Locations.txt on the C:\Temp path. You can check the content using the below file.Get-Content C:\temp\locations.txtTo clear the file content, we can use ... Read More

How to get installed windows update using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:35:21

12K+ Views

To get the installed windows updates using PowerShell, we can use the Get-Hotfix command. This command gets the hotfixes and updates that are installed on the local and the remote computer.This command is the part of Microsoft.Management.PowerShell utility.ExampleGet-HotFixOutputPS C:\> Get-HotFix Source Description HotFixID InstalledBy InstalledOn ------ ----------- -------- ----------- ----------- ... Read More

Difference between Test-Path and Resolve-Path in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:33:02

558 Views

Test-Path command checks if the particular path exists or not and returns the Boolean output (True or False) while Resolve-Path command displays the particular directory if exists otherwise throws an exception. For example, For the path to exist, ExamplePS C:\> Test-Path C:\Temp\ True PS C:\> Resolve-Path C:\Temp\ Path ---- C:\Temp\For ... Read More

How to retrieve windows registry keys and values using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:31:24

5K+ Views

To browse through the registry in PowerShell, we can use the Get-ChildItem command. For example to get all keys from the path HKLM:\Hardware we can use the below command.Get-ChildItem HKLM:\HARDWAREOr you can set the location and use the dir (get-ChildItem or ls) command to browse the path.ExamplePS C:\> Set-Location HKLM:\HARDWARE PS HKLM:\HARDWARE> dirOutputHive: HKEY_LOCAL_MACHINE\HARDWARE Name    Property ... Read More

How to delete registry key value (property) using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 08-Feb-2021 07:28:37

10K+ Views

To delete the registry key value using PowerShell, we can use the Remove-ItemProperty command. Suppose we have the registry NodeSoftware and its Property is AppSecurity. We need to delete its key using the Remove-ItemProperty command.PS C:\> Get-Item HKLM:\SOFTWARE\NodeSoftware Hive: HKEY_LOCAL_MACHINE\SOFTWARE Name    Property ----    -------- NodeSoftware    AppSecurity : 1To delete the ... Read More

How to change the TLS version in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 25-Jan-2021 07:26:56

3K+ Views

Transport Layer Security known as TLS is a very important part while using URI commands such as Invoke−WebRequest or Invoke−Restmethod commands and package commands such as Find−Package or Install−Package because they interact on the internet and PowerShell needs TLS1.2 version for that.We may get the below errors when we use ... Read More

How to use the tree command in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 25-Jan-2021 07:26:41

9K+ Views

Tree command graphically shows the folder structure of the given drive or a path. It is similar to Get−ChildItem or dir recursive command except this shows the graphical structure. For example, the below command will retrieve the folder structure of C:\VMs includingtree c:\VMsOutputThere are also two other switches supported for ... Read More

How to convert JSON object to Hashtable format using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 25-Jan-2021 07:26:25

5K+ Views

PowerShell 7 supports the -AsHashtable parameter in the ConvertFrom−JSON command to convert the JSON to hashtable directly and that is a great feature. Consider we have the below JSON file, We can use the pipeline command ConvertFrom−JSON to convert the JSON file to the custom table format and with the ... Read More

How to mount the ISO file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 25-Jan-2021 07:26:11

3K+ Views

To mount the ISO file in Windows using PowerShell, we can use the Mount−DiskImage command. The below command will mount the image file stored at the C:\ISO location.Mount−DiskImage −ImagePath "C:\ISOs\Windows_Server_2016_Datacenter_EVAL_en−us_14393_refresh (1).ISO"OutputAttached : True BlockSize : 0 DevicePath : \.\CDROM0 FileSize : 6972221440 ImagePath : C:\ISOs\Windows_Server_2016_Datacenter_EVAL_en-us_14393_refresh (1).ISO LogicalSectorSize : 2048 Number ... Read More

Advertisements