# Zastavit, pokud nahodou F5 break # Proc toto cele? #zjisti seznam spustenych sluzeb a zastavi tyto sluzby $RunServices = Get-Service "BIT*" | Where-Object {$_.Status -eq "Running"} for ($i=0; $i -le $RunServices.count-1; $i++) { Stop-Service -Name $RunServices[$i].Name -Force } Get-Service -Name BITS | Stop-Service -WhatIf # Get-Help Get-Help about_* help about_WQL -ShowWindow # Get-Command Get-Process -Name powershell_ise -ComputerName localhost -IncludeUserName Get-Command Get-Process -Syntax # Get-Member 'david' 'david' | Get-Member 'david'.LastIndexOf('d') ls C:\temp\aaaa.csv | Get-Member # Aliasy gal # PowerShell zdroje jsou dostupne na GitHubu https://github.com/PowerShell/PowerShell # -> releases # Jak je udelan Get-Date https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetDateCommand.cs # Ping Test-Connection -ComputerName localhost Test-NetConnection Get-Command Test-NetConnection -Syntax Test-NetConnection -ComputerName 'www.pwsh.cz' -Port 80 Test-NetConnection -ComputerName 'www.pwsh.cz' -Port 3389 # Cestovni cmdlety Get-Command -Noun Path Test-Path c:\temp\nejakysoubor Join-Path -Path C:\temp -ChildPath nejakysoubor Split-path -Path C:\temp\AWS\AWS_Cloud_Best_Practices.pdf -Qualifier Split-path -Path C:\temp\AWS\AWS_Cloud_Best_Practices.pdf -NoQualifier Split-path -Path C:\temp\AWS\AWS_Cloud_Best_Practices.pdf -Parent Split-path -Path C:\temp\AWS\AWS_Cloud_Best_Practices.pdf -Leaf Convert-Path -Path Dropbox:\PowerShell Resolve-Path -Path C:\t*p\a?s # Nekonecna smycka while($true) { 1..10 |% { $_; Start-Sleep -Seconds 1 } } # Zaokrouhlovani na cela cisla Get-WmiObject Win32_LogicalDisk (Get-WmiObject Win32_LogicalDisk).FreeSpace (Get-WmiObject Win32_logicaldisk).FreeSpace/1gb (Get-WmiObject Win32_logicaldisk).FreeSpace/1gb -as [int] 1024kb 1024kb/1mb # gb, tb, pb # Jak cist log soubory 'real-time' while($true) { 1..1000 |% { [int]$_ >> c:\temp\zapisovatko.txt ; sleep 1 } } Get-Content -Path c:\temp\zapisovatko.txt -Wait Get-Content -Path c:\temp\zapisovatko.txt -Wait | Select-String -Pattern '2' # Zobrazovatko Get-Process | Out-GridView notepad Get-Process | Out-GridView -Title 'Kterou sluzbu chces zastavit?' -OutputMode Single | Stop-Process Get-Process | Out-GridView -Title 'Ktere sluzby chces zastavit?' -OutputMode Multiple | Stop-Process -WhatIf # Cmdlety s defaultnimi hodnotami $PSDefaultParameterValues Get-Date -Year 2020 $PSDefaultParameterValues.Add('Get-Date:Year', 2020) Get-Date $PSDefaultParameterValues.Remove('Get-Date:Year') # Rychlejsi Where ls C:\temp | Where-Object { $_.Extension -eq '.txt' } | Measure-Object | Select -Expand Count (ls c:\temp).where({$_.Extension -eq '.txt'}) | Measure-Object | Select -Expand Count # Prace s historii Get-History 1+1 Invoke-History 1+1 (ihy) * 10 # Vytvoreni TEMP souboru [System.IO.Path]::ChangeExtension([System.IO.Path]::GetTempFileName(), 'txt') # Prevod ceskych znaku [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding(1251).GetBytes("žščřĎŤÝ")) # Title case (Get-Culture).TextInfo.ToTitleCase('zdravim z FRESH IT') # Zmena casove zony - cas v jine zone [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTime]::UtcNow, 'Pacific Standard Time') # Elevated shell Start-Process -FilePath powershell.exe -Verb RunAs -ArgumentList {Get-Date; Start-Sleep -Seconds 3} # Schranka 'neco' | clip