How to startup PowerShell scripting

For the major use case the PowerShell is designed for systems administrators and engineers.  The PowerShell framework has rich features that helps self learning about its usage.  Further to that its cmdlet syntax using verb-noun helps you easily find the relevant cmdlets.   Here is how you get to know/find something within PowerShell Use Get-Command to see if there is any cmdlet that is already available for doing the action you are looking for. PS C:> Get-Command *drive CommandType Name ModuleName ———– —- ———- Cmdlet Get-PSDrive Microsoft.PowerShell.Management Cmdlet New-PSDrive Microsoft.PowerShell.Management Cmdlet Remove-PSDrive Microsoft.PowerShell.Management PS C:> Getting quick more details about […]

Read more

PS: Unix Shell Tail and Head command equivalents in PowerShell

Here is a quick way of checking through the tail or head contents of files in PS. Get all contents of a file: PS C:> Get-Content C:TempServers.txt Vm1 Vm2 Vm3 PS C:> Get Head contents of a file: PS C:> Get-Content -TotalCount 2 C:TempServers.txt Vm1 Vm2 PS C:> Get Tail contents of a file: PS C:> Get-Content -Tail 2 C:TempServers.txt Vm2 Vm3 PS C:> Here is a quick way of checking through the tail or head contents of a command result/output in PS. Get all results of a file: (nothing to be done extra) PS C:> Get-Process | measure Count    […]

Read more

PS: Using Multiple Filters in Get-WMIObject to improve WMI query performances

It’s very often we require to filter WMI query results with multiple filters.  For example, you want to get all services whose startup type is set to Manual and that are running.  Most usual practice that all use is to apply where-object filtering on getting the all the results from WMI query.  This isn’t effective since you are fetching all results from WMI query and then applying filtering on top the query results.  Instead one can fine tune the initial WMI query itself to result only in required data so that we again don’t need to run the where-objects filtering.  […]

Read more