Help and Information
The following task-based articles provide a brief introduction to getting help and information while using Windows PowerShell; these tasks include such things as listing Windows PowerShell verion information and using the Get-Member cmdlet to retrieve property and method information for an object. As is so often the case with Windows PowerShell, the code snippets found in these articles can either be included within a Windows PowerShell script or typed directly into the Windows PowerShell console.Using the Get-Help Cmdlet
Getting Help
Windows PowerShell includes two basic types of help - command help and conceptual help - both of which can be accessed from the console using the Get-Help cmdlet. To retrieve a list of all available help topics simply type the following command:Get-Help *
Name Category Synopsis ---- -------- -------- ac Alias Add-Content asnp Alias Add-PSSnapin clc Alias Clear-Content cli Alias Clear-Item clp Alias Clear-ItemProperty
Get-Help Get-Member
Get-Help Get-Member | more
Using the Get-Command Cmdlet
Listing All the Windows PowerShell Cmdlets
Can’t remember the name of each and every Windows PowerShell cmdlet? Don’t worry about it; that’s one of the things Get-Command can help you with. Just type Get-Command without any additional parameters and you’ll get back a list of all the Windows PowerShell cmdlets:Get-Command
CommandType Name Definition ----------- ---- ---------- Cmdlet Add-Content Add-Content [-Path] <String[... Cmdlet Add-History Add-History [[-InputObject] ... Cmdlet Add-Member Add-Member [-MemberType] <PS... Cmdlet Add-PSSnapin Add-PSSnapin [-Name] <String... Cmdlet Clear-Content Clear-Content [-Path] <Strin...
Get-Command | Format-List *
Name : Write-Verbose CommandType : Cmdlet DLL : C:\WINDOWS\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.U tility\1.0.9567.1__31bf3856ad364e35\Microsoft.PowerShell.Com mands.Utility.dll Verb : Write Noun : Warning HelpFile : Microsoft.PowerShell.Commands.Utility.dll-Help.xml PSSnapIn : Microsoft.PowerShell.Utility ImplementingType : Microsoft.PowerShell.Commands.WriteWarningCommand ParameterSets : {__AllParameterSets} Definition : Write-Warning [-Message] <String> [-Verbose] [-Debug] [-Erro rAction <ActionPreference>] [-ErrorVariable <String>] [-OutV ariable <String>] [-OutBuffer <Int32>] Name : Write-Warning CommandType : Cmdlet
Get-Command | Select-Object name
Name ---- Add-Content Add-History Add-Member Add-PSSnapin Clear-Content Clear-Item Clear-ItemProperty Clear-Variable
Get-Command | Get-Help | Out-File c:\scripts\help.txt
Get-Command Aliases |
---|
|
Using the Get-Host Cmdlet
Listing Windows PowerShell Version Information
The Get-Host cmdlet returns information (such as the version number) for Windows PowerShell. For example:Name : ConsoleHost Version : 1.0.458.0 InstanceId : 3a2087f5-ed5a-442d-9927-4367f2967116 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-US CurrentUICulture : en-US PrivateData :
Get-Host
Using the Get-Member Cmdlet
Listing the Properties and Methods of a Command or Object
Any time you’re writing scripts or working from the command line the biggest problem you face is this: how do I know what I can and cannot do? How do I know which properties and methods are available to me? How can I actually write a script or type a command-line command without having to memorize every object model found on MSDN?One way to do that is to use the Windows PowerShell Get-Member cmdlet. Once you connect to an object you can pipe that object to Get-Member; in turn, Get-Member will enumerate the properties and methods of that object. For example, suppose you’d like to know which properties and methods are available for event logs. Assuming you know that Get-EventLog -list will retrieve an event log object, all you need to do is issue this command:
Get-EventLog -list | Get-Member
Name MemberType Definition ---- ---------- ---------- add_Disposed Method System.Void add_Disposed(EventHandler v... add_EntryWritten Method System.Void add_EntryWritten(EntryWritt... BeginInit Method System.Void BeginInit() Clear Method System.Void Clear() Close Method System.Void Close()
Get-WmiObject win32_bios | Get-Member -membertype properties
Here’s an interesting use of Get-Member. Did you know that some of the properties returned by the Get-Process cmdlet have aliases? Well, you would if you ran this command, setting -membertype to AliasProperty:
Get-Process | Get-Member -membertype aliasproperty
Name MemberType Definition ---- ---------- ---------- Handles AliasProperty Handles = Handlecount Name AliasProperty Name = ProcessName NPM AliasProperty NPM = NonpagedSystemMemorySize PM AliasProperty PM = PagedMemorySize VM AliasProperty VM = VirtualMemorySize WS AliasProperty WS = WorkingSet
Get-Process | Select-Object name, npm
New-Object -com scripting.filesystemobject | Get-Member
Name MemberType Definition ---- ---------- ---------- BuildPath Method string BuildPath (string, string) CopyFile Method void CopyFile (string, string, bool) CopyFolder Method void CopyFolder (string, string, bool) CreateFolder Method IFolder CreateFolder (string) CreateTextFile Method ITextStream CreateTextFile (string, bool, bool) DeleteFile Method void DeleteFile (string, bool) DeleteFolder Method void DeleteFolder (string, bool) DriveExists Method bool DriveExists (string) FileExists Method bool FileExists (string) FolderExists Method bool FolderExists (string)
Get-Member Aliases |
---|
|
Using the Get-PSProvider Cmdlet
Listing Your Installed Windows PowerShell Providers
Among other things, Windows PowerShell providers determine which data stores you can navigate through. For example, you can use the Get-ChildItem command to retrieve a list of all the files found in a folder; that’s because a provider exists for the file system. You can also use Get-ChildItem to retrieve a list of all the subkeys found in a registry key. Why? You got it: because a provider exists for the registry.To determine the providers available for you, simply call the Get-PSProvider cmdlet without any parameters:
Get-PSProvider
Name Capabilities Drives ---- ------------ ------ Alias ShouldProcess {Alias} Environment ShouldProcess {Env} FileSystem Filter, ShouldProcess {C, D, E} Function ShouldProcess {Function} Registry ShouldProcess {HKLM, HKCU} Variable ShouldProcess {Variable} Certificate ShouldProcess {cert}
No comments:
Post a Comment