Chirag Nagrekar has Published 468 Answers

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

How to get the certificate's start and expiry date using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:38:44

To get the certificate's start and expiry date using PowerShell, we first need to retrieve the certificate details using a thumbprint or other properties like friendly name, subject name, etc.Let say we have a certificate thumbprint details. So we can use the below command to retrieve the certificate's Start and ... Read More

How to change the Certificate's friendly name using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:37:42

Suppose we know the Thumbprint of the certificate then we can use the below command to update or change the certificate's friendly name.Example$cert = Get-ChildItem `    -Path Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F1C1140F$cert.FriendlyName = "mysitecert"The above command will update the certificate-friendly name to "mysitecert". If you don't know the thumbprint or how to retrieve it, you can use different ... Read More

How to install a certificate to the certificate store using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:33:58

To install the certificate using PowerShell, we need to use the Import-Certificate command. For example, we have a certificate stored at the location C:\temp\Mycert.cer and we need to install it in the Personal store of the local machine.ExampleImport-Certificate -FilePath C:\Temp\Mycert.cer `    -CertStoreLocation Cert:\LocalMachine\My\You can also use the below method.PS C:\> Set-Location Cert:\LocalMachine\My\ PS Cert:\LocalMachine\My\> Import-Certificate -FilePath C:\Temp\Mycert.cerTo install a ... Read More

How to Export a certificate from a certificate store using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:33:34

To export or download a certificate from the certificate store using PowerShell, we need to use the command Export-Certificate.First, you need to get the certificate details from the store. If you know the thumbprint, you can directly get the certificate details using the thumbprint and then use that details to ... Read More

How to create a self-signed certificate using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

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

To create a self-signed certificate there are various methods like OpenSSL, IIS, PowerShell, etc. Here, we will see how we can create a self-signed certificate with PowerShell.To create a self-signed certificate with PowerShell, we need to use the New-SelfSignedCertificate command. When you create a self-signed certificate manually, you need to ... Read More

How to create a dummy file of any size with PowerShell?

Chirag Nagrekar

Chirag Nagrekar

Updated on 18-Mar-2021 07:32:51

To create any dummy file of having any size with PowerShell, we can use the below command.Example$f = new-object System.IO.FileStream c:\temp\test.dat,  Create,  ReadWrite $f.SetLength(50MB) $f.Close()The above command will create 50MB of Test.dat dummy file in the C:\temp. Such files are used for testing purposes.Read More

How to get the default Documents from the IIS site using PowerShell?

Chirag Nagrekar

Chirag Nagrekar

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

To get the default documents stored on the IIS default website page, you can use the below command.ExampleGet-WebConfigurationProperty -Filter //defaultDocument/files/add    -PSPath 'IIS:\Sites\Default Web Site' -Name value `    | select valueOutputValue ----- Default.htm Default.asp index.htm index.html iisstart.htmTo check if the Default document contains a specific file, (Get-WebConfigurationProperty -Filter //defaultDocument/files/add ... Read More

Advertisements