Install the Latest PowerShell Module Version

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

2K+ Views

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 -VerboseTo manually install the latest version of the PowerShell module, there are two methods.Use the -RequiredVersion parameter if you know the latest version of the module.Use the -MinimumVersion parameter if you know the minor version of the module and it will pick up the latest version.Using -RequiredVersion ParameterThis parameter installs ... Read More

Install Specific Version of PowerShell Module

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

7K+ Views

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, we will use the 7Zip4PowerShell module.ExampleFind-Module 7zip4PowerShell -AllVersions | ft -AutoSizeWhen you run this command, you can see there are multiple versions available for this module.OutputVersion  Name            Repository -------  ----            ---------- 1.13.0   7Zip4Powershell PSGallery 1.12.0   7Zip4Powershell PSGallery 1.11.0 ... Read More

Update Windows Host File Entry Using PowerShell

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

3K+ Views

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              # x client host # localhost name resolution is handled within DNS itself. #       127.0.0.1       localhost #       ::1             localhost 8.8.8.8   Google.comWe need to update the google.com entry to IP address ... Read More

Add Entry in Windows Host File Using PowerShell

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

9K+ Views

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 += "8.8.8.8   Google.com" Set-Content -Path $file -Value $hostfile -ForceOnce you check the host file entry  "8.8.8.8          Google.com" will be added to the host file.To add the entry on the remote computer, you just need to point that file location to the host file of the remote server and the rest of ... Read More

Read Windows Host File Using PowerShell

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

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

Test Shared Location Path from Remote Computer in PowerShell

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

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

Retrieve Certificate Thumbprint Using PowerShell

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

13K+ 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

Get Certificate's Start and Expiry Date Using PowerShell

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

2K+ 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

Change Certificate's Friendly Name Using PowerShell

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

2K+ 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"

Install Certificate to Certificate Store Using PowerShell

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

25K+ 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

Advertisements