Chirag Nagrekar has Published 465 Answers

How to get empty files in Windows OS using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 30-Mar-2021 13:05:47

To get the list of empty files in Windows OS using PowerShell, there are two ways, a) Using Length parameter. We will count the length of the file. If it is 0 then the file is empty as shown below.Get-ChildItem C:\Temp\ -Recurse | where{$_.Length -eq 0} | Select @{N='EmptyFiles';E={$_.FullName}}Output:b) Another ... Read More

How to take the backup of environment variables using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 30-Mar-2021 12:53:56

Sometimes changes in the Windows environment variable can be deadly because it saves information about user profiles, application information, and OS information. It is always better to keep the Environment backup handy and update that file whenever there are any changes or at the regular interval.Taking up the environment variables ... Read More

How to uninstall the PowerShell Module?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:54:23

To uninstall the PowerShell module, we can directly use the Uninstall-Module command but the module should not be in use, otherwise, it will throw an error.When we use the Uninstall-Module command, it can uninstall the module from the current user profile or from the all users profile.Uninstall-Module 7Zip4PowerShell -Force -VerboseAnother ... Read More

How to install the latest PowerShell module version?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:50:56

Although simply running Install-Module command picks up the latest version of the module, we can still use the -RequiredVersion and -MinimumVersion parameter to install the latest version manually. Below command directly installs the latest available version of the module.In this example we are using 7Zip4PowerShell module.Install-Module 7Zip4PowerShell -Scope AllUsers -Force ... Read More

How to install the specific version of the PowerShell module version?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:50:01

To install the specific version of the PowerShell module, we need to use the -RequiredVersion parameter with the Install-Module command.To find which module versions are available, we can use the Find-Module command with the -AllVersions parameter which retrieves all the versions of the module available in the PSGallery.In this example, ... Read More

How to update the windows host file entry using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:49:12

Let say you want to update the host file particular entry, we have the below host file in our local computer.ExampleGet-Content $env:windir\system32\drivers\etc\hostsOutput# For example: # #      102.54.94.97     rhino.acme.com          # source server #       38.25.63.10     x.acme.com       ... Read More

How to add the entry in the windows host file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:46:18

To add the content to the host file, we need to first retrieve the content using the Get-Content command and the need to set the content to the host file after adding the entry. The Code is shown below. We need to add the global entry to it.Example$file = "C:\Windows\System32\drivers\etc\hosts" $hostfile = Get-Content $file $hostfile += ... Read More

How to read the windows host file using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:45:09

Windows Host file that maps the hostname and the IP address is the plain text file. So reading the host file is simpler. We just need to use the Get-Content command to retrieve the file content.Generally, the host file is stored at the location c:\windows\System32\drivers\etc\.  If the OS is installed ... Read More

How to test the shared location path from the remote computer in PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:43:29

Many times we need to test the NAS path or shared path location from the remote server. Meaning we need to check if the shared path is accessible from the remote location and we use the Test-Path that time but we get an error of PermissionDenied or UnauthorizedAccessExcept.Our sample code is ... Read More

How to retrieve certificate thumbprint using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:39:17

A certificate thumbprint is a hash or signature of the thumbprint and it plays a crucial role in the security aspect. To get the certificate thumbprint using PowerShell is very much easy.We just need to retrieve the path where certificates reside and the default property that is shown on the ... Read More

Advertisements