Navigation

PowerShell - příklady

Get-Command
Get-Command -verbget
Get-Command -verb get
Get-Command *
Get-Command *-service
history
get-help
get-help get-service
get-help Get-Service -examples
get-service -displayname *network*
ls
Get-Service --help
Get-Service -Name a*
Get-Service -Name *a*
Get-Service -Name *aw*
Get-Service -Name *w*
Get-Service -Name *wa*
Get-ADuser
Get-Service -Name *aw*
Get-Item
get-alias
Get-Alias -Definition Get-ChildItem
Get-Command *alias*
New-Alias np C:\Windows\System32\notepad.exe
np
sort
Get-Command *sort*
ip /a
Get-Process
Get-Command | sort -Property VM -descend | select -First 10
Get-Command | sort -Property VM -descend
Get-Command
Get-Process
Get-Process -filter {Name -eq "WS"}
Get-Command | sort -Property VM -descend
Get-Process | sort -Property VM -descend
Get-Process | sort -Property VS -descend
Get-Process | sort -Property PM -descend
history
Get-Help history
Get-Service | Where-Object{$_.Status -eq "running"}
Get-Service | Where-Object{$_.Status -eq "running"} | sort -Property Name -descend

Get-Service | Out-File C:\sluzby.txt
Get-Service | Out-File sluzby.txt
Get-Service | Where-Object{$_.Status -eq "running"}
Get-Service | Out-GridView
Get-Command Get-Help
Get-Command | Get-Help
Get-Help Export-Clixml
Get-Module -ListAvailable
Get-Process
Get-Service
Get-Service | Where-Object{$_.Status -eq "running"}

Get-ExecutionPolicy
Set-ExecutionPolicy
Get-Help Set-ExecutionPolicy
$Procesy = Get-Process
$Procesy | sort -Property PM -descend
$Procesy | sort -Property WS -descend
Get-Date | Get-Member

$now = Get-Date
$now.day
(Get-Date).day
$now = Get-Date
$now.day

$pole = 1,2,3,4
$pole[2]
$dny = @{"Prvni"="Pondeli";"Druhy"="Utery"}
$dny | Get-Member
$dny.GetType()

help about*

Get-Service | foreach {Write-Host $_.Name -ForegroundColor Red}

Get-Help Write-Host
Get-Help Write-Host -full
Get-Service | foreach {Write-Host (0,1,2) -ForegroundColor Green}
Get-Service | foreach {Write-Host $_.Name -ForegroundColor Green}
Get-Service | foreach {Write-Host $_.Name,$_.Status -ForegroundColor Green}
Get-Service | foreach {Write-Host | Get-Member}
Get-Service | Get-Member
Get-Service | foreach {Write-Host $_.DisplayName,$_.Status -ForegroundColor Green}
Get-Help Write-Host -full
Get-Service | foreach {Write-Host $_.DisplayName,$_.Status -Separator ", -> " -ForegroundColor Green}

Get-Credential
$heslo = Read-Host "Heslo" -AsSecureString
Get-Credential
Get-Help Get-Service
Get-Service -Name admin
Get-Service -Name "admin"
Get-Member
Get-Service | measure

Get-Process Calc | Get-Member
Get-EventLog
Get-EventLog | Get-Member
Get-EventLog system
Get-EventLog system -Newest 10
Get-EventLog system -EntryType error
Get-EventLog system -EntryType warning
history
Get-Command *event*
Get-Command *event* -Module
Get-Command *event* -CommandType cmdlet

Get-Member -InputObject $pole
$pole.count

Get-Service | fl
Get-Service | ft
Get-Service | Get-Member
Get-Service | Select Name, Status, ServiceType
Get-Service | Select Name, Status, ServiceType, CanStop
Get-Service | Select Name, Status, ServiceType | ft -AutoSize



PS U:\> Get-PSDrive
Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
Alias                                  Alias
C                  73,70         14,65 FileSystem    C:\
cert                                   Certificate   \
D                                      FileSystem    D:\
E                    ,80          6,60 FileSystem    E:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
U                1997,92          2,08 FileSystem    U:\
Variable                               Variable
WSMan                                  WSMan


cd cert:
PS cert:\> dir
Location   : CurrentUser
StoreNames : {SmartCardRoot, UserDS, AuthRoot, CA...}
Location   : LocalMachine
StoreNames : {SmartCardRoot, AuthRoot, CA, Trust...}

PS cert:\> cd .\CurrentUser
PS cert:\CurrentUser> ls

Name : SmartCardRoot
Name : UserDS
Name : AuthRoot
Name : CA
Name : ADDRESSBOOK
Name : Trust
Name : Disallowed
Name : My
Name : Root
Name : TrustedPeople
Name : ACRS
Name : TrustedPublisher

PS cert:\CurrentUser> cd ca
PS cert:\CurrentUser\ca> dir

    Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\ca

Thumbprint                                Subject
----------                                -------
XXXXXXXXXXXXXXXXX4225A10E127E911D1C7F8CF  CN=StartCom Class 1 Primary Intermediate Server CA, OU=Secure Digital Cert...
XXXXXXXXXXXXXXXXX829517566C25F422A277104  CN=VeriSign Class 3 International Server CA - G3, OU=Terms of use at https...
XXXXXXXXXXXXXXXXX4FBF685712361658F2F4357  CN=Thawte SSL CA, O="Thawte, Inc.", C=US
XXXXXXXXXXXXXXXXX46F000E87FDE2A065FD89D4  CN=Root Agency
XXXXXXXXXXXXXXXXXA30A133F8A9ED3D038E2EA8  OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign, OU=Ve...
XXXXXXXXXXXXXXXXX3EA2B94C0697C740733031C  CN=Microsoft Windows Hardware Compatibility, OU=Microsoft Corporation, OU=...
XXXXXXXXXXXXXXXXXA0978C214ECE4EF2BC6C5F4  CN=PostSignum Public CA 2, O="Česká pošta, s.p. [IČ XXXXXXXX]", C=CZ
XXXXXXXXXXXXXXXXX1C5427FCF650D8AA9EFD258  CN=MPSV CA Organization SHA-2, O=Ministerstvo prace a socialnich veci, L=P...
XXXXXXXXXXXXXXXXX684C68A0F454FB268BC966B  CN=MPSV CA Smart Card SHA-2, O=Ministerstvo prace a socialnich veci, L=Pra...
XXXXXXXXXXXXXXXXXB3E4D53C252F5DAAA89EAFC  CN=CCAeID2 - Commercial Certificate Authority (kvalifikovaný systémový cer...
XXXXXXXXXXXXXXXXXEE9A290302F4241DD41CC7A  CN=MPSV CA Universal Smart Card SHA-2, O=Ministerstvo prace a socialnich v...
XXXXXXXXXXXXXXXXX2DBBC598F025904C50347D3  CN=MPSV CA Server SHA-2, O=Ministerstvo prace a socialnich veci, L=Praha, ...
XXXXXXXXXXXXXXXXXC1ACF8B0F6A2E6D487D6762  CN=Thawte DV SSL CA, OU=Domain Validated SSL, O="Thawte, Inc.", C=US
XXXXXXXXXXXXXXXXX593E0C448D61ED58FA07F30  CN=MPSV CA Personal SHA-2, O=Ministerstvo prace a socialnich veci, L=Praha...
XXXXXXXXXXXXXXXXX20A22B1221BA03EBFB18CEF  CN=MPSV CA Data Signing SHA-2, O=Ministerstvo prace a socialnich veci, L=P...
XXXXXXXXXXXXXXXXX4B3F767F37246C5929F9829  CN=ACAeID2 - Qualified Issuing Certificate (kvalifikovaný systémový certif...
XXXXXXXXXXXXXXXXXD1C2CF29C490C485390BF3D  CN=PostSignum Qualified CA 2, O="Česká pošta, s.p. [IČ XXXXXXXX]", C=CZ
XXXXXXXXXXXXXXXXX3275E34DAF5DE01A57C18D0  CN=CA-CITY, DC=XXXXX, DC=cz
XXXXXXXXXXXXXXXXX115203089706EFF0FE26D82  CN=ROOT-CA-CITY-XXXXX, DC=XXXXX, DC=cz
XXXXXXXXXXXXXXXXXFBE1C76070B0AC16210169D  CN=ROOT-CA-CITY-XXXXX, DC=XXXXX, DC=cz



Get-Service | ft -Wrap -Autosize
Get-Service | Out-File d:\_Data_\out.txt -Width 1000


$heslo = Read-Host -AsSecureString
New-ADUser petr -AccpimtPassword $heslo | Enable-ADAccount
Enable-ADAccount Petr
New-ADUser petr -AccpimtPassword $heslo -PassThru | Enable-ADAccount
New-ADUser petr -AccpimtPassword $heslo -PassThru

-passthru (donutim mluvit)
-Verbose (taky donutim mluvit)


$url = "http://linux.duckd.cz/man1.xml"
$duckd = [xml](new-object system.net.webclient).downloadstring($url)