Ha re sebetsa le PowerShell, ntho ea pele eo re kopanang le eona ke litaelo (Cmdlets).
Mohala oa taelo o shebahala tjena:
Verb-Noun -Parameter1 ValueType1 -Parameter2 ValueType2[]
Thusa
Thuso e fumaneha ho PowerShell ho sebelisoa taelo ea Get-Help. O ka hlakisa e 'ngoe ea liparamente: mohlala, lintlha tse qaqileng, tse felletseng, inthaneteng, showWindow.
Fumana-Help Get-Service -full e tla khutlisa tlhaloso e felletseng ea hore na taelo ea Fumana-Tšebeletso e sebetsa joang
Get-Help Get-S* e tla bontša litaelo tsohle tse teng le mesebetsi e qalang ka Get-S*
Ho boetse ho na le litokomane tse qaqileng ho webosaete ea semmuso ea Microsoft.
Mona ke mohlala oa thuso bakeng sa taelo ea Get-Evenlog
Haeba liparamente li kentsoe ka masakaneng a lisekoere [], ke tsa boikhethelo.
Ke hore, mohlaleng ona, lebitso la koranta ka boeona le tlamehile, le lebitso la parameter
Haeba u sheba parameter ea EntryType, u ka bona litekanyetso tse kentsoeng ka har'a li-curly braces. Bakeng sa paramethara ena, re ka sebelisa feela boleng bo boletsoeng esale pele ho li-curly braces.
Re ka bona tlhahisoleseling mabapi le hore na paramente e ea hlokahala tlhalosong e ka tlase lebaleng le Hlokehang. Mohlaleng o ka holimo, tšobotsi ea After ke ea boikhethelo hobane Ho Hlokahala e setetsoe ho fosahetse. Ka mor'a moo re bona sebaka sa Position se shebaneng le se reng E rehiloe. Sena se bolela hore parameter e ka fumanoa feela ka lebitso, ke hore:
Get-EventLog -LogName Application -After 2020.04.26
Kaha parameter ea LogName e ne e e-na le nomoro ea 0 e boletsoeng ho e-na le Lebitso, sena se bolela hore re ka fumana parameter ntle le lebitso, empa ka ho e hlalosa ka tatellano e hlokahalang:
Get-EventLog Application -After 2020.04.26
Ha re nke taelo ena:
Get-EventLog -Newest 5 Application
Alias
E le hore re ka sebelisa litaelo tse tloaelehileng tse tsoang ho console, PowerShell e na le li-alias (Alias).
Mohlala oa lebitso la taelo ea Set-Location ke cd.
Ke hore, sebakeng sa ho bitsa taelo
Set-Location “D:”
re ka sebelisa
cd “D:”
History
Ho sheba nalane ea mehala ea litaelo, o ka sebelisa Get-History
Etsa taelo ho tloha historing Invoke-History 1; Invoke-Histori 2
Hlakola nalane ea nalane e hlakileng
Pipe
Phaephe e ho powershell ke ha sephetho sa tšebetso ea pele se fetisetsoa ho ea bobeli. Mona ke mohlala oa ho sebelisa pipeline:
Get-Verb | Measure-Object
Empa ho utloisisa phaephe hantle, a re nke mohlala o bonolo haholoanyane. Ho na le sehlopha
Get-Verb "get"
Haeba re bitsa thuso ea Get-Help Get-Verb -Full, re tla bona hore paramethara ea Leetsi e amohela tlhahiso ea pipline mme ByValue e ngotsoe ka masakaneng.
Sena se bolela hore re ka ngola hape Get-Verb "fumana" ho "fumana" | Fumana-Leetsi.
Ke hore, sephetho sa polelo ea pele ke khoele 'me e fetisetsoa ho Leetsi paramethareng ea Get-Verb taelo ka pipline input ka boleng.
Hape ho kenya pipline e ka ba ByPropertyName. Tabeng ena, re tla fetisa ntho e nang le thepa e nang le lebitso le tšoanang Leetsi.
Mefuta-futa
Liphetoho ha lia ngoloa ka matla 'me li hlalositsoe ka letšoao la $ ka pele
$example = 4
Letšoao la > le bolela ho kenya data
Ka mohlala, $mohlala > File.txt
Ka polelo ena re tla beha data ho tsoa ho $mohlala e fapaneng ho ea faeleng
Hoa tšoana le Set-Content -Boleng $mohlala -Path File.txt
tse fapaneng
Array initialization:
$ArrayExample = @(“First”, “Second”)
Ho qala lethathamo le se nang letho:
$ArrayExample = @()
Ho fumana boleng ka index:
$ArrayExample[0]
Fumana lethathamo lohle:
$ArrayExample
Ho eketsa element:
$ArrayExample += “Third”
$ArrayExample += @(“Fourth”, “Fifth”)
Ho hlophisa:
$ArrayExample | Sort
$ArrayExample | Sort -Descending
Empa sehlopha ka boeona ha se fetohe nakong ea ho hlophisoa hona. 'Me haeba re batla hore sehlopha se be le data e hlophisitsoeng, joale re hloka ho fana ka litekanyetso tse hlophisitsoeng:
$ArrayExample = $ArrayExample | Sort
Ha ho na mokhoa oa 'nete oa ho tlosa ntho ho tsoa ho PowerShell, empa u ka e etsa ka tsela ena:
$ArrayExample = $ArrayExample | where { $_ -ne “First” }
$ArrayExample = $ArrayExample | where { $_ -ne $ArrayExample[0] }
Ho tlosa sehlopha:
$ArrayExample = $null
Loops
Loop syntax:
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){}
Tsoa ho loop ea khefu.
Ho tlohela elemente e tsoelang pele.
Lipolelo tsa maemo
if () {} elseif () {} else
switch($someIntValue){
1 { “Option 1” }
2 { “Option 2” }
default { “Not set” }
}
mosebetsi
Tlhaloso ea Mosebetsi:
function Example () {
echo &args
}
Mosebetsi oa ho sebetsa:
Example “First argument” “Second argument”
Ho hlalosa mabaka a tshebetso:
function Example () {
param($first, $second)
}
function Example ($first, $second) {}
Mosebetsi oa ho sebetsa:
Example -first “First argument” -second “Second argument”
Ntho e ikhethang
try{
} catch [System.Net.WebException],[System.IO.IOException]{
} catch {
} finally{
}
Source: www.habr.com