This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Syntax | |
<condition> ? <if-true> : <if-false> | |
# Example | |
$message = (Test-Path $path) ? "Path exists" : "Path not found" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example | |
$SomeValue ??= 100 | |
# taki sam efekt w PowerShell 5.1 | |
if(-not $SomeValue) | |
{ | |
$SomeValue = 100 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell 7 - ForEach and Parallel | |
$logNames = 'Security','Application','System','Windows PowerShell','Microsoft-Windows-Store/Operational' | |
$logEntries = $logNames | ForEach-Object -Parallel { | |
Get-WinEvent -LogName $_ -MaxEvents 10000 | |
} -ThrottleLimit 5 | |
$logEntries.Count | |
50000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install or update PowerShell 7 on Windows 10 | |
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI" | |
# Install or update PowerShell 7 on Linux | |
wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh; rm install-powershell.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One-liner to install or update PowerShell 7 on Windows 10 | |
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI" | |
# One-liner to install or update PowerShell 7 on Linux | |
wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh; rm install-powershell.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "azurerm_resource_group" "rg" { | |
name = "rg-akademia-tf" | |
location = "west europe" | |
} | |
resource "azurerm_sql_server" "instance" { | |
name = "sql-tf" | |
resource_group_name = azurerm_resource_group.rg.name | |
location = azurerm_resource_group.rg.location | |
version = "12.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ResourceGroup = New-AzResourceGroup -Name "rg-akademia-ps" -Location "westeurope" -Force | |
$Credentials = $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'sqladmin', | |
$(ConvertTo-SecureString -String "JakieTrudneHaslo99" -AsPlainText -Force)) | |
$ParamSqlServer = @{ | |
ResourceGroupName = $ResourceGroup.ResourceGroupName | |
ServerName = "sql-ps" | |
Location = $ResourceGroup.Location | |
SqlAdministratorCredentials = $Credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-Tls12 | |
{ | |
<# Get-Help Set-Tls12 -Online #> | |
[CmdletBinding(HelpURI = "https://akademiapowershell.pl/11")] | |
[Alias('tls12')] | |
param() | |
Write-Verbose "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12" | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SqlInstance = 'SERWER-SQL\MSSQLSERVER17' | |
$Database = 'master' | |
$ScriptBlock = { | |
param( | |
[Parameter(Mandatory)] | |
$SQLInstance, | |
[Parameter(Mandatory)] | |
$Database, | |
[Parameter(Mandatory)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Join-PathElement { | |
param( | |
[string[]]$Element | |
) | |
[array]$FullPath = $Element[0] | |
for ($i = 1; $i -lt $Element.Count; $i++) { | |
$FullPath += Join-Path -Path $FullPath -ChildPath $Element[$i] | |
} | |
$Id = $FullPath.Count - 1 |