PowerShell: Difference between revisions
Jump to navigation
Jump to search
(Created page with " == Allgemein == * Powershell ist seeeeehr inkonsistent was die Versionen angeht.... == Commands == '''ArrayList''' $files = New-Object System.Collections.ArrayList $files.Add("C:\hallo.txt") '''For Schleife''' for ($i=1; $i -lt 10; $i++) { Write-Host "$i" } '''Foreach Schleife''' $files = Get-ChildItem -Recurse -Path "$path" foreach ($file in $files) { Write-Host "$file" } '''Functions''' function sagHallo($name) { ...") |
(No difference)
|
Latest revision as of 14:52, 12 May 2023
Allgemein
- Powershell ist seeeeehr inkonsistent was die Versionen angeht....
Commands
ArrayList
$files = New-Object System.Collections.ArrayList
$files.Add("C:\hallo.txt")
For Schleife
for ($i=1; $i -lt 10; $i++)
{
Write-Host "$i"
}
Foreach Schleife
$files = Get-ChildItem -Recurse -Path "$path"
foreach ($file in $files)
{
Write-Host "$file"
}
Functions
function sagHallo($name)
{
return "Hallo $name"
}
| Command | Beschreibung |
|---|---|
| $variable = "Wert" | Variablen Deklaration |
| Install-Module -Name Posh-SSH | Ermöglicht SSH Datei Uploads |
| new-item -path "C:\hallo.txt" -type file -value "Inhalt von hallo" | Datei mit Inhalt erstellen |
| new-item -path "C:\Hallo" -type directory | Verzeichnis erstellen |
| Remove-Item "C:\hallo.txt" -Force | Datei loeschen ohne nachfragen |
| Remove-Item "C:\Hallo\" -Force | Verzeichnis loeschen ohne nachfragen |
| Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted | dem Benutzer das Ausfuehren Powershell-Skripten erlauben |
| Test-Path "C:\hallo.txt" | gucken ob Datei da ist |
| Write-Host "Ausgabe" | Schreiben auf Std-Out |