Difference between revisions of "PowerShell"

From no name for this wiki
Jump to: navigation, search
(Pipes)
Line 10: Line 10:
 
<source>
 
<source>
 
Get-Service | Sort-Object -property Status
 
Get-Service | Sort-Object -property Status
 +
</source>
 +
 +
== Fucntion ==
 +
<source>
 +
Send-Greeting -name Claude
 +
 +
 +
function Send-Greeting
 +
{
 +
    [CmdletBinding()]
 +
    Param(
 +
        [Parameter(Mandatory=$true)]
 +
        [string] $Name
 +
    )
 +
 +
    Process
 +
    {
 +
        Write-Host ("Hello " + $Name + "!")
 +
    }
 +
}
 
</source>
 
</source>

Revision as of 08:59, 4 June 2022

Pipes

$_ Variable

Get-Service | WHERE {$_.status -eq "Running"} | SELECT displayname
# “$_.” defines current element in the pipe


Get-Service | Sort-Object -property Status

Fucntion

Send-Greeting -name Claude


function Send-Greeting
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string] $Name
    )

    Process
    {
        Write-Host ("Hello " + $Name + "!")
    }
}