- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 989 Articles for Software & Coding
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
2K+ Views
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 at that location.Or you can use $env:Windir to get the windows directory.To get the file content, ExampleGet-Content $env:windir\system32\drivers\etc\hostsOutput# Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
2K+ Views
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 shown below and in this example, we are using the Invoke-Command to connect to another computer and from there we are checking if the shared path is accessible.ExampleInvoke-Command -ComputerName LabMachine2k16 -ScriptBlock { Test-Path -Path "\ad\Shared\Temp" }This script throws an exception.OutputAccess is denied + CategoryInfo : PermissionDenied: ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
11K+ Views
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 console will include the certificate thumbprint.For example, we are going to retrieve the certificate from the personal store.ExampleGet-ChildItem Cert:\LocalMachine\My\OutputPSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My Thumbprint Subject ---------- ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
1K+ Views
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 End date along with the days remaining for the certificate expiry.ExampleGet-ChildItem Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F1C1140F ` | Select @{N='StartDate';E={$_.NotBefore}}, @{N='EndDate';E={$_.NotAfter}}, @{N='DaysRemaining';E={($_.NotAfter - (Get-Date)).Days}}OutputStartDate EndDate DaysRemaining --------- ------- ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
1K+ Views
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 properties like Subject name, friendly name, etc.Example$cert = Get-ChildItem -path ` Cert:\LocalMachine\My\` | where{$_.Subject -eq "CN=mysite.local"}$cert.FriendlyName = "mysitecert"
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
20K+ Views
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 certificate on the remote computer, use the Invoke-Command method.SyntaxInvoke-Command -ComputerName RemoteServer1 -ScriptBlock {Import-Certificate -FilePath C:\Temp\Mycert.cer ` -CertStoreLocation Cert:\LocalMachine\My\ }The above command will install the certificate on RemoteServer1 from the path C:\temp of the remote server to the personal store of the remote machine.Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
3K+ Views
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 export the certificate.Example$cert = (Get-ChildItem Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F) Export-Certificate -Cert $cert -Type CERT -FilePath C:\Temp\Mycert.cerIn the above example, we are exporting the certificate from the LocalMachine -> Personal Store. You can choose a different path. Here, the certificate would be exported to the C:\temp\MyCert.cer. You can use the different types like P7B, SST to export the certificate. Alternatively, you ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
4K+ Views
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 give few properties like DNSName, FriendlyName, Certificate start date, expiry date, Subject, a path of the certificate. Similarly, you can use those properties for this command to create it. Not all properties are mandatory.ExampleNew-SelfSignedCertificate ` -CertStoreLocation Cert:\LocalMachine\My ` -DnsName "testdomain.local" -VerboseOutputPSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My Thumbprint ... Read More
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
4K+ Views
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.
![Chirag Nagrekar](https://www.tutorialspoint.com/assets/profiles/163503/profile/60_109370-1581658197.png)
420 Views
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 -PSPath 'IIS:\Sites\Default Web Site' -Name value).value -contains 'iisstart.htm'The above command checks if the IIS default website contains any iisstart.htm on the default document page.You can also use another website instead of using 'Default Web site'. To get the default documents file at the IIS level, (Get-WebConfigurationProperty -Filter //defaultDocument/files/add -PSPath 'IIS:\' ... Read More