- 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 463 Articles for PowerShell
1K+ Views
PowerShell workflows are the best way to design the script to execute on more than one node parallel which saves extensive time for the output to produce but we always don’t want to run all the commands parallel but also need some of them to run sequentially and we can design both Parallel and Sequence commands using PowerShell Workflow.Workflow TestWorkflow{ parallel{ Command1 Command2 } Sequence{ Command3 Command4 } } TestWorkflowIn the above code, Command1, Command2 will be executed parallelly in any order while command3 ... Read More
9K+ Views
There are two ways to use the foreach loop parallelly in PowerShell.Using Foreach-Object -Parallel command (Supports in PowerShell 7.0 or above)Using Foreach -Parallel in Workflow (Supports PowerShell 5.1 or below)Suppose we have Servers.txt and which contains 10 Servers. When we use the Parallel for loop, it isn’t guaranteed which server loop will pick first as shown below with two examples.Using Foreach-Object-Parallel command. (not Foreach -Parallel)This Foreach-Object -Parallel command feature is newly added to the PowerShell version 7.0 or above.Example$servers = Get-Content C:\Temp\Servers.txt $servers | foreach-Object -parallel{ Write-output "Working on $_" }OutputPS C:\> C:\Temp\Test1.ps1 Working on IndiaServer003 Working on IndiaServer002 Working on IndiaServer001 Working on ... Read More
366 Views
PowerShell workflow is built on the .Net based Windows Workflow Foundation (WWF) and it has a separate Workflow engine to execute the code because it translates code into XAML for the WWF framework.PowerShell workflow is series of steps that is mainly used forRunning activities parallelly on more than one machine.Long-running scripts.Structuring steps (Which steps will execute parallel and which in sequence)Frequently used tasks.Resuming the script from where it was terminated due to system failure or any other interruption by defining checkpoints.The PowerShell workflow was introduced in PowerShell 3.0 and discontinued for windows in the Core version (6.0 onwards) and only ... Read More
2K+ Views
To validate the IP address using PowerShell, we can use several methods as shown below.Using RegEx method.Using Typecasting method.Using TypeCasting method.In this method, we are using System.Net method class IPAddress to validate the IP address.[ipaddress]$IP = "192.168.0.1"The above one is valid. Let’s check what $IP stores in.PS C:\> $IP Address : 16820416 AddressFamily : InterNetwork ScopeId : IsIPv6Multicast : False IsIPv6LinkLocal : False IsIPv6SiteLocal : False IsIPv6Teredo : False IsIPv4MappedToIPv6 : False IPAddressToString : 192.168.0.1The above one is Ipv4 and this method also works for IPv6. See the example below.PS C:\> [ipaddress]"2001:0db8:85a3:0000:0000:8a2e:0370:7334" Address : AddressFamily : InterNetworkV6 ScopeId ... Read More
1K+ Views
To check if the PowerShell string contains a specific word, we can use the string method Contains(). For example, ExamplePS C:\> $str = 'TestNZ01LT' PS C:\> $str.Contains('NZ') TrueNow the funny thing is, even if the PowerShell is case-Insensitive, the above command is not. We need to provide the exact substring. For example, the below output will be false.ExamplePS C:\> $str.Contains('Nz') FalseTo overcome this problem, we can either provide the same search name in the method or we need to use the lowercase or uppercase method if you don’t want the search case-sensitive.PS C:\> $str = 'TestNZ01LT' PS C:\> ($str.ToLower()).Contains(('Nz').ToLower()) True ... Read More
2K+ Views
To convert any command output to the hashtable in PowerShell, we can first convert the output to the JSON format using the ConvertTo-JSON command, and applying the ConvertFrom-JSON command from the first output will produce an output to the Hashtable.ExampleGet-ServiceThe above command will give the output in the array format.OutputStatus Name DisplayName ------ ---- ----------- Stopped WwanSvc WWAN AutoConfig Stopped XblAuthManager Xbox Live Auth Manager Stopped XblGameSave Xbox Live Game Save Stopped XboxGipSvc Xbox Accessory Management Service Stopped XboxNetApiSvc Xbox Live ... Read More
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
815 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)
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
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