-->
5 Cmdlets To Perish You Lot Started Amongst Powershell

5 Cmdlets To Perish You Lot Started Amongst Powershell

5 Cmdlets To Perish You Lot Started Amongst Powershell

https://www.howtogeek.com/114344/5-cmdlets-to-get-you-started-with-powershell/

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users besides every bit information technology Pros. It's good worth learning a few commands to acquire yous started, therefore we've got five useful cmdlets for yous to larn today.

Get-Command

The Get-Command is 1 of the most useful cmdlets inwards the whole of PowerShell, every bit it volition aid yous getting to grips alongside PowerShell past times letting yous search for sure as shooting cmdlets. Using Get-Command on its ain is admittedly non rattling useful every bit its only going to spit out every ascendancy that PowerShell has.

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

But from this nosotros tin regard that that objects that PowerShell outputs conduct maintain both a Name in addition to a ModuleName property. Using this information nosotros tin fine grain our search, past times searching for cmdlets that incorporate sure as shooting terms. For representative if I wanted to detect all cmdlets that incorporate the give-and-take "IP", I could create this:

Get-Command –Name *IP*

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

As yous tin regard nosotros nevertheless acquire quite a few results, our adjacent selection is to search inside a specific module. In our instance i volition select the NetTCPIP module.

Get-Command –Module NetTCPIP –Name *IP*

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

Get-Help

Once yous conduct maintain institute the cmdlet yous are looking for using Get-Command, yous are going to desire to know the syntax in addition to how yous tin utilization that specific cmdlet. This is where Get-Help comes in, if yous conduct maintain always used the ascendancy work inwards Windows yous in all probability did something similar this:

ipconfig /?

Well that doesn't piece of work inwards PowerShell, this is because inwards PowerShell a infinite is used to divide a ascendancy from its parameters. So instead nosotros utilization Get-Help in addition to transcend a cmdlets elevate to Get-Help every bit a parameter.

Get-Help Get-Process

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

Get-Member

Get-Member allows us to acquire information almost the objects that a cmdlets returns. The conduct withdraw maintain of alongside get-member, is that it relies on PowerShell's pipeline feature, to demonstrate this, nosotros volition tin utilization the Get-Process cmdlet.

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

As yous tin regard PowerShell's output shows us to a greater extent than or less of the properties, which yous tin regard at the top of each column. The outset work is that, piece those are the properties yous powerfulness move looking for most of the time, at that spot are nevertheless to a greater extent than of them. The minute work is that it doesn't exhibit whatsoever methods that nosotros are able to telephone phone on the object. To regard the methods in addition to properties nosotros tin piping our output to Get-Member, similar so:

Get-Process | Get-Member

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

While it may hateful zilch to yous correct now, yous volition sooner or afterwards demand to utilization Get-Member, in addition to the sooner yous larn to utilization it the better. As an example, using the information from the output nosotros could create something like:

Start-Process notepad.exe
$NotepadProc = Get-Process -Name notepad
$NotepadProc.WaitForExit()
Start-Process calc.exe

That script volition launch notepad,  it in addition to therefore assigns output of "Get-Process –Name notepad" to the $NotepadProc variable, in addition to therefore nosotros telephone phone the WaitForExit method on $NotepadProc which causes the script to pause  until yous closed notepad, 1 time yous conduct maintain closed notepad in addition to therefore the reckoner volition launch.

$_(Current Pipeline Object)

While non just a cmdlet, it is 1 of the most used especial variables inwards PowerShell. The official elevate for $_ is "the electrical flow pipeline object" . It is used inwards script blocks, filters, the procedure clause of functions, where-object, foreach-object in addition to switches. However it is easier to explicate alongside an example, which brings us to our adjacent in addition to terminal cmdlet, Where-Object.

Where-Object

Where-Object does just what it sounds like, it selects an object based on whether it meets a sure as shooting criteria. This volition convey together $_, in addition to the properties nosotros tin regard using Get-Member. To demonstrate this, nosotros volition piping the output of Get-Process into the Where-Object cmdlet.

Get-Process | Where-Object {$_.Name –eq "iexplore"}

PowerShell is apace becoming the preferred scripting linguistic communication in addition to CLI of Power Users every bit  five Cmdlets to Get You Started alongside PowerShell

So what's going on hither yous ask? Well the outset matter nosotros are doing is getting a listing of processes on our information processor in addition to passing the output (using the | character) to our Where-Object cmdlet,  which takes a script block  every bit a parameter. The script block (defined past times the curly braces) instructs the Where-Object cmdlets to alone select objects where their elevate parameter is equal to "iexplore", in addition to therefore nosotros alone acquire a listing of the IE instances that are running. That's all at that spot is to it, conduct maintain fun!


Blogger
Disqus
Pilih Sistem Komentar

No comments

Advertiser