ืืขืืืื ืขื PowerShell, ืืืืจ ืืจืืฉืื ืฉืื ื ื ืชืงืืื ืื ืืื ืคืงืืืืช (Cmdlets).
ืงืจืืืช ืืคืงืืื ื ืจืืืช ืื:
Verb-Noun -Parameter1 ValueType1 -Parameter2 ValueType2[]
ืขึถืืจึธื
ื ืืชื ืืืฉืช ืืขืืจื ื-PowerShell ืืืืฆืขืืช ืืคืงืืื Get-Help. ื ืืชื ืืฆืืื ืืื ืืืคืจืืืจืื: ืืืืื, ืืคืืจื, ืืื, ืืงืืื, showWindow.
Get-Help Get-Service -full ืืืืืจ ืืช ืืชืืืืจ ืืืื ืฉื ืคืขืืืช ืืคืงืืื Get-Service
Get-Help Get-S* ืืฆืื ืืช ืื ืืคืงืืืืช ืืืคืื ืงืฆืืืช ืืืืื ืืช ืืื ื-Get-S*
ืืฉ ืื ืชืืขืื ืืคืืจื ืืืชืจ ืืจืฉืื ืฉื ืืืงืจืืกืืคื.
ืื ื ืืืืื ืืขืืจื ืืคืงืืืช Get-Evenlog
ืื ืคืจืืืจืื ืืืงืคืื ืืกืืืจืืื ืืจืืืขืื [], ืื ืื ืืืคืฆืืื ืืืื.
ืืืืืจ, ืืืืืื ืื ื ืืจืฉ ืฉื ืืืืื ืขืฆืื, ืืฉื ืืคืจืืืจ
ืื ืืชื ืืกืชืื ืขื ืืคืจืืืจ EntryType, ืืชื ืืืื ืืจืืืช ืืช ืืขืจืืื ืืืืงืคืื ืืกืืืจืืื ืืกืืืกืืื. ืขืืืจ ืคืจืืืจ ืื, ืื ื ืืืืืื ืืืฉืชืืฉ ืจืง ืืขืจืืื ืืืืืจืื ืืจืืฉ ืืกืืืจืื ืืกืืืกืืื.
ืืืืข ืืืื ืืื ืืคืจืืืจ ื ืืจืฉ ื ืืชื ืืจืืืช ืืชืืืืจ ืฉืืืื ืืฉืื ืืืื. ืืืืืื ืฉืืืขืื, ืืชืืื ื After ืืื ืืืคืฆืืื ืืืช ืืืืืื ืฉ-Required ืืืืืจ ื-false. ืืืืจ ืืื, ืื ื ืจืืืื ืืช ืืฉืื Position ืืืื ืฉืืืืจ ืืฉื. ืื ืืืืจ ืฉืืชื ืืืื ืืืชืืืืก ืืคืจืืืจ ืจืง ืืคื ืืฉื, ืืืืืจ:
Get-EventLog -LogName Application -After 2020.04.26
ืืืืืื ืฉืืคืจืืืจ LogName ืืื ืืืกืคืจ 0 ืืืงืื Named, ืื ืืืืจ ืฉืื ืื ื ืืืืืื ืืืชืืืืก ืืคืจืืืจ ืืื ืฉื, ืืื ืขื ืืื ืฆืืื ืืืชื ืืจืฆืฃ ืืจืฆืื:
Get-EventLog Application -After 2020.04.26
ื ื ืื ืืช ืืกืืจ ืืื:
Get-EventLog -Newest 5 Application
ืืื ืื
ืืื ืฉื ืืื ืืืฉืชืืฉ ืืคืงืืืืช ืืจืืืืืช ืืืืกืืฃ ื-PowerShell, ืืฉื ื ืืื ืืืื (Alias).
ืืื ืื ืืืืื ืืคืงืืืช Set-Location ืืื cd.
ืืืืืจ, ืืืงืื ืืงืจืื ืืคืงืืื
Set-Location โD:โ
ืื ืื ื ืืืืืื ืืืฉืชืืฉ
cd โD:โ
ืึดืืกืืึนืจึดืึธื
ืืื ืืจืืืช ืืช ืืืืกืืืจืื ืฉื ืฉืืืืช ืคืงืืื, ืืชื ืืืื ืืืฉืชืืฉ ื-Get-History
ืืฆืข ืคืงืืื ืืืืืกืืืจืื Invoke-History 1; ืงืจื ืืืกืืืจืื 2
ื ืงื ืืืกืืืจืื
ืฆืื ืืจ
ืฆืื ืืจ ื-powershell ืืื ืืืฉืจ ืืชืืฆืื ืฉื ืืคืื ืงืฆืื ืืจืืฉืื ื ืืืขืืจืช ืืฉื ืืื. ืื ื ืืืืื ืืืืฆืขืืช ืืฆืื ืืจ:
Get-Verb | Measure-Object
ืืื ืืื ืืืืื ืืื ืืืชืจ ืืช ืืฆืื ืืจ, ื ืืงื ืืืืื ืคืฉืืื ืืืชืจ. ืืฉ ืฆืืืช
Get-Verb "get"
ืื ืชืงืจื ืืขืืจื Get-Help Get-Verb -Full, ืื ื ืจืื ืฉืืคืจืืืจ Verb ืืงืื ืงืื pipline ื-ByValue ืืชืื ืืกืืืจืืื.
ืื ืืืืจ ืฉืื ืื ื ืืืืืื ืืฉืืชื ืืช Get-Verb "ืืงืื" ื"ืงืื" | ืงืื ืคืืขื.
ืืืืืจ, ืืชืืฆืื ืฉื ืืืืืื ืืจืืฉืื ืืื ืืืจืืืช ืืืื ืืืขืืจืช ืืคืจืืืจ Verb ืฉื ืืคืงืืื Get-Verb ืืืืฆืขืืช ืงืื ืืคื ืขืจื.
ืื ืงืื ืฆืื ืืจ ืืืื ืืืืืช ByPropertyName. ืืืงืจื ืื, ื ืขืืืจ ืืืืืืงื ืืขื ืืืคืืื ืืขื ืฉื ืืืื Verb.
ืืฉืชื ืื
ืืฉืชื ืื ืืื ื ืืืงืืืื ืืืื ืืื ืืฆืืื ืื ืขื $ ืืืคื ืื
$example = 4
ืืกืื > ืคืืจืืฉื ืืืื ืืก ืืช ืื ืชืื ืื
ืืืืืื, $example > File.txt
ืขื ืืืืืื ืืื, ื ืื ืืก ืืช ืื ืชืื ืื ืืืืฉืชื ื $example ืืงืืืฅ
ืืื ื-Set-Content -Value $example -Path File.txt
ืืขืจืืื
ืืชืืื ืืขืจื:
$ArrayExample = @(โFirstโ, โSecondโ)
ืืชืืื ืืขืจื ืจืืง:
$ArrayExample = @()
ืงืืืช ืขืจื ืืคื ืืื ืืงืก:
$ArrayExample[0]
ืงืื ืืช ืื ืืืขืจื:
$ArrayExample
ืืืกืคืช ืืืื ื:
$ArrayExample += โThirdโ
$ArrayExample += @(โFourthโ, โFifthโ)
ืืืื ืืคื:
$ArrayExample | Sort
$ArrayExample | Sort -Descending
ืืื ืืืขืจื ืขืฆืื ื ืฉืืจ ืืื ืฉืื ืื ืขื ืืืืื ืืื. ืืื ืื ืื ื ืจืืฆืื ืฉืืืขืจื ืืืื ื ืชืื ืื ืืืืื ืื, ืื ืื ืื ื ืฆืจืืืื ืืืงืฆืืช ืืช ืืขืจืืื ืืืืืื ืื:
$ArrayExample = $ArrayExample | Sort
ืืื ืืจื ืืืกืืจ ืืืื ื ืืืขืจื ื- PowerShell, ืืื ืืชื ืืืื ืืขืฉืืช ืืืช ืื:
$ArrayExample = $ArrayExample | where { $_ -ne โFirstโ }
$ArrayExample = $ArrayExample | where { $_ -ne $ArrayExample[0] }
ืืกืจืช ืืขืจื:
$ArrayExample = $null
ืืืืืืช
ืชืืืืจ ืืืืื:
for($i = 0; $i -lt 5; $i++){}
$i = 0
while($i -lt 5){}
$i = 0
do{} while($i -lt 5)
$i = 0
do{} until($i -lt 5)
ForEach($item in $items){}
ืฆื ืืืืืืช ืืคืกืงื.
ืืื ืขื ืจืืื ืืืืฉื.
ืืฆืืจืืช ืขื ืชื ืื
if () {} elseif () {} else
switch($someIntValue){
1 { โOption 1โ }
2 { โOption 2โ }
default { โNot setโ }
}
ืคืื ืงืฆืื
ืืืืจืช ืคืื ืงืฆืื:
function Example () {
echo &args
}
ืืฉืงืช ืคืื ืงืฆืื:
Example โFirst argumentโ โSecond argumentโ
ืืืืจืช ืืจืืืื ืืื ืืคืื ืงืฆืื:
function Example () {
param($first, $second)
}
function Example ($first, $second) {}
ืืฉืงืช ืคืื ืงืฆืื:
Example -first โFirst argumentโ -second โSecond argumentโ
ืืจืืื
try{
} catch [System.Net.WebException],[System.IO.IOException]{
} catch {
} finally{
}
ืืงืืจ: www.habr.com