Skripte zum Video über PowerShell Scopes auf YouTube https://www.youtube.com/watch?v=LPXwZ5VSETw
Created
June 13, 2023 12:22
-
-
Save diecknet/8671a6eb7e2adc6e39dc0c55b37752d9 to your computer and use it in GitHub Desktop.
PowerShell Scopes Beispiele
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
# Script: Beispiel1.ps1 | |
Write-Host '$a='$a | |
$a = "moin" | |
Write-Host '$a='$a |
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
# Script: Beispiel2.ps1 | |
Write-Host '$global:a='$global:a | |
$global:a = "moin" | |
Write-Host '$global:a='$global:a |
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
# Script: Beispiel3.ps1 | |
Write-Host '$script:a='$script:a | |
$script:a = "moin 123" | |
Write-Host '$script:a='$script:a |
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
# Private Scope Beispiel: Beispiel4.ps1 | |
Write-Host '$b='$b | |
$b = "Kann ich das überschreiben?" | |
Write-Host '$b='$b |
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
# Private / Global Scope Beispiel: Beispiel5.ps1 | |
Write-Host '$global:c='$global:c | |
$global:c = "57389579835798" | |
Write-Host '$global:c='$global:c |
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
# Scope Modifier Beispiel6.ps1 | |
Write-Host "Einfacher Aufruf ohne Scope:Modifier" | |
testfunction | |
pause | |
Write-Host "Aufruf mit Global:Scope:Modifier" | |
global:testfunction | |
pause | |
Write-Host "Definition local Funktion mit gleichen Namen" | |
function local:testfunction { | |
Write-Host "Hallo aus der lokalen Funktion" | |
} | |
Write-Host "Aufruf der lokalen Funktion mit local:Scope:modifier" | |
local:testfunction | |
pause | |
Write-Host "Aufruf der lokalen Funktion mit ohne Scope:modifier" | |
testfunction | |
pause |
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
# Beispiel7.ps1 | |
np |
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
# Beispiel8.ps1 | |
$var = "SKRIPT" | |
Get-Variable -Name var -Scope 0 | |
Write-Host "Abruf aus Scope 1 = " | |
Get-Variable -Name var -Scope 1 | |
function testx { | |
$var = "FUNKTION" | |
Write-Host "Scope 0 = " | |
Get-Variable -Name "var" -Scope 0 | |
Write-Host "Scope 1 = " | |
Get-Variable -Name "var" -Scope 1 | |
Write-Host "Scope 2 = " | |
Get-Variable -Name "var" -Scope 2 | |
} | |
testx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment