Found 989 Articles for Software & Coding

How to exclude the RunSpaceID property from the Invoke-Command output in PowerShell?

Chirag Nagrekar
Updated on 08-Feb-2021 07:51:36

3K+ Views

When we write Invoke-Command in PowerShell, sometimes we get the RunSpaceID property in PowerShell. This is because we use Select-Object (alias: Select) command inside the scriptblock. For example,ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell | Select Name, CPU, WorkingSet}OutputName           : powershell CPU            : 9.1572587 WorkingSet     : 127700992 PSComputerName : LabMachine2k12 RunspaceId     : c690f205-06d4-4cc4-be29-5302725eadf1To avoid getting the RunSpaceID property in the output, use the Select command output the scriptblock. For example,ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell} | Select Name, CPU, WorkingSetOutputName       CPU        WorkingSet ----       ---        ---------- powershell 9.1572587  127700992

How to exclude PSComputerName property from Invoke-Command output in PowerShell?

Chirag Nagrekar
Updated on 08-Feb-2021 07:49:29

819 Views

When we are working with Invoke-Command, we get the PSComputerName extra field in the output table. You can remove it by using -HideComputerName parameter. For example, the Below command gives the output with the PSComputerName property.ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Service Winrm} | ft -AutoSizeOutputStatus  Name  DisplayName PSComputerName ------  ----  -----------     -------------- Running Winrm Windows Remote Management (WS-Management) LabMachine2k12To hide the PSComputerName property,ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Service Winrm} -HideComputerNameOutputStatus  Name  DisplayName   ------  ----  -----------   Running Winrm Windows Remote Management (WS-Management)

How to find the device driver version using PowerShell?

Chirag Nagrekar
Updated on 08-Feb-2021 07:46:08

4K+ Views

To find the device driver version using PowerShell, we need to use the class win32_PnpSignedDriver of the WMI object. For example, ExampleGet-WmiObject win32_PnpSignedDriverOr if you are using PowerShell core (PowerShell 6.0 or later), you can use the CIM Instance command. For example, Get-CimInstance win32_PnpSignedDriverTo filter out the Drivers against their versions, use the below command to filter.Examplegwmi win32_PnpSignedDriver | Select Description, DriverVersionOutputACPI x64-based PC                6.2.9200.16384     UMBus Root Bus Enumerator        6.2.9200.16384     WAN Miniport (IPv6)              6.2.9200.16384     Composite Bus Enumerator ... Read More

How to check windows certificate expiry date using PowerShell?

Chirag Nagrekar
Updated on 08-Feb-2021 07:44:24

3K+ Views

To get the particular windows certificate expiry date from the particular store, we first need the full path of that certificate along with a thumbprint. If the thumbprint is not known to you, we can use the friendly name.With the thumbprint, Get-ChildItem Cert:\LocalMachine\root\0563B8630D62D75 | fl *When you run the above command, it will get all the details of the certificate having thumbprint 0563B8630D62D75.There you can see there are two fields listed, NotAfter and NotBefore which shows the expiry and start dates respectively. To filter them out, ExampleGet-ChildItem Cert:\LocalMachine\root\0563B8630D62D75 | Select FriendlyName, NotAfter, NotBeforeOutputFriendlyName NotAfter   NotBefore ------------ --------   --------- ... Read More

How to get the Windows certificate details using PowerShell?

Chirag Nagrekar
Updated on 08-Feb-2021 07:42:37

34K+ Views

We know that the Windows Certificates are resided in the Certificate store but finding the certificate with its name or getting particular certificate details might be cumbersome sometimes.You can access the certificate store using MMC or using CertMgr.msc command. There are certificates stored for CurrentUser, ServiceAccount, and Local Computer. To access the certificate store using PowerShell, you need to access the PSDrive, and Certificates are stored in the drive called Cert as you can see below.PS C:\> Get-PSDrive cert | ft -AutoSize Name Used (GB) Free (GB) Provider Root CurrentLocation ---- --------- --------- -------- ---- --------------- Cert Certificate \Let say ... Read More

How to check if PSCustomObject is empty in PowerShell?

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 = ''    City = ''    Country = ''    Company = '' }OutputPS C:\WINDOWS\system32> $output Name    City     Country    Company ----    ----     -------    ------- John    New York  US        Alpha PS C:\WINDOWS\system32> $output1 Name    City     Country    Company ... Read More

How to delete all the file contents using PowerShell?

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 the below command.Clear-Content C:\Temp\locations.txt -Force-Force switch is used to clear the contents without user confirmation.When you use this command with the pipeline in the Get-Content command, it will generate an IO Exception error that the file is in use because we are already retrieving the contents using Get-Content and then ... Read More

How to get installed windows update using PowerShell?

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 ------ ----------- -------- ----------- ----------- LABMACHINE... Update KB3191565 LABMACHINE2K12\Ad... 1/15/2021 12:00:00 AM LABMACHINE... Update KB2999226 LABMACHINE2K12\Ad... 1/13/2021 12:00:00 AMIn the above output, you can see the SourceMachine Name, HotfixID, InstalledBy, and the Installed Date.You can also sort it by the InstalledOn parameter. For example, ExampleGet-HotFix | Sort-Object InstalledOn -DescendingThis command supports the ComputerName parameter which ... Read More

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

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 the path doesn’t exist, PS C:\> Test-Path C:\Temp11\ False PS C:\> Resolve-Path C:\Temp11\ Resolve-Path : Cannot find path 'C:\Temp11\' because it does not exist. At line:1 char:1 + Resolve-Path C:\Temp11\ + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Temp11\:String) [Resolve-Path], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound, Microsoft.PowerShell.Commands.ResolvePathCommandResolve-Path is also used to get the ... Read More

How to retrieve windows registry keys and values using PowerShell?

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 ----    -------- ACPI DESCRIPTION DEVICEMAP RESOURCEMAPTo get the properties of the key, use the Get-ItemProperty command.ExampleSet-Location 'HKLM:\SOFTWARE\VMware,  Inc.' Get-ItemProperty '.\VMware Drivers'Outputefifw.status   : 1|1.1.0.0.0.1|oem2.inf vmxnet3.status : 1|1.1.8.16.0.1|oem3.inf pvscsi.status   : 1|1.1.3.15.0.1|oem4.inf vmusbmouse.status : 1|1.12.5.10.0.1|oem5.inf vmmouse.status : 1|1.12.5.10.0.1|oem6.infRead More

Advertisements