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.ManagementPS C:>
- Getting quick more details about the cmdlets matching your search.
PS C:> Get-Help *drive
Name Category Module Synopsis
—- ——– —— ——–
Get-PSDrive Cmdlet Microsoft.PowerShell.M… Gets drives in the current session.
New-PSDrive Cmdlet Microsoft.PowerShell.M… Creates temporary and persistent mapped networ…
Remove-PSDrive Cmdlet Microsoft.PowerShell.M… Deletes temporary Windows PowerShell drives an…PS C:>
- Knowing more details about the particular cmdlet that you are interested in
PS C:> Get-Help Remove-PSDrive
NAME
Remove-PSDriveSYNOPSIS
Deletes temporary Windows PowerShell drives and disconnects mapped network drives.SYNTAX
Remove-PSDrive [-Name] <String[]> [-Force [<SwitchParameter>]] [-PSProvider <String[]>] [-Scope <String>]DESCRIPTION
The Remove-PSDrive cmdlet deletes temporary Windows PowerShell drives that were created by using the New-PSDrive
cmdlet.RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkID=113376
Get-PSDrive
New-PSDrive
about_ProvidersREMARKS
To see the examples, type: "get-help Remove-PSDrive -examples".
For more information, type: "get-help Remove-PSDrive -detailed".
For technical information, type: "get-help Remove-PSDrive -full".
For online help, type: "get-help Remove-PSDrive -online"PS C:>
- Find how to run a chosen cmdlet with valid parameters. Use: get-help Remove-PSDrive -examples
- Finding whole help documentation of a cmdlet. Use: get-help Remove-PSDrive –full
Understanding PowerShell Runtime:
As everything in PowerShell is/can be an object, the runtime of PowerShell consists of object and it’s methods/properties execution.
Usually in many scripting/programming languages the very common issue the authors encounter is the object type mismatch while assigning and/or matching the results of a command/call.
In PowerShell you can easily get to know what kind of objects you are getting from a command/function as result.
- Use Get-Member will shows what type of an object returned from a cmdlet
PS C:> Get-Help | Get-Member | select -first 1
TypeName: System.String
Name MemberType Definition
—- ———- ———-
Clone Method System.Object Clone()PS C:>
- Further to that it also gives you find what all methods available with that object, what are the properties that you can query/set for
PS C:> Get-Help | Get-Member | Group MemberType
Count Name Group
—– —- —–
33 Method {System.Object Clone(), int CompareTo(System.Object value), int CompareTo(string strB), bool Contains(string value), Sys…
6 NoteProperty {System.String Category=HelpFile, System.String Component=, System.String Functionality=, System.String Name=default…}
1 ParameterizedProperty {char Chars(int index) {get;}}
1 Property {System.Int32 Length {get;}}PS C:>
- Its possible that a cmd output be a simple string being just one object or an string array with multiple objects. To know the output is a simple string or string array, use below measure-object cmdlet. If the count is 1, then it’s a simple string otherwise a string array
- g
PS C:> "PowerShell", "cSharp", "Dotnet" | Measure-Object
Count : 3
PS C:> "PowerShell" | Measure-Object
Count : 1
PS C:>