Powershell, Karten 31-60

Powershell Grundlagen

Powershell Grundlagen

Roger Aschwanden

Roger Aschwanden

Set of flashcards Details

Flashcards 30
Language Deutsch
Category Computer Science
Level Vocational School
Created / Updated 11.11.2015 / 04.10.2019
Weblink
https://card2brain.ch/box/powershell_karten_3160
Embed
<iframe src="https://card2brain.ch/box/powershell_karten_3160/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>

Wie können die Default Provider von Powershell angezeigt werden?

get-psprovider #Alias, Environment, Filesystem, Function, Registry, Variable

It’s designed to take some kind of data storage and make it look like a disk drive

Welchen Möglichkeiten bietet ein Provider mit der Fähigkeit "Shouldprocess"

Der provider unterstützt -WhatIf and -Confirm Parameters

enabling you to “test” certain actions before committing to them

Welchen Möglichkeiten bietet ein Provider mit der Fähigkeit "Credentials"

the provider permits you to specify alternate credentials when connecting to data stores.

Welchen Möglichkeiten bietet ein Provider mit der Fähigkeit "Transactions"

the provider supports the use of transactions; which allows you to use the provider to make several changes; and then either roll back or commit those changes as a single unit

Wie können die Verbundenen Laufwerke angezeigt werden?

get-psdrive

Was bedeuted der command parameter "-LiteralPath"

wildcards *;? sind bei manchen Providern; z.B Registry erlaubt. Wenn Powershell Wildcards nicht interpretieren soll muss dies mit dem Parameter -LiteralPath anstelle von -Path angegeben werden.

Was ist der Unterschied von Export-CliXML und export-csv?

CliXML can hold more information than a flat CSV file

It's better for diff with compare-object

Was ist der Unterschied von ">" und "| Out-File"

Out-File also provides additional parameters that let you specify alternative character encodings (such as UTF8 or Unicode)

Was passiert hinter einem "dir"? Wie kommt die Default Ausgabe auf den Bildschirm?

Dir | Out-Default | Out-Host

Kann definiert werden wann nach einer Bestätigung zur Ausfürhung eines commands gefragt wird?

In der Variable$confirmpreference

Here’s how it works: when a cmdlet’s internal impact level is equal to or higher than the shell’s $ConfirmPreference setting, the shell will automatically ask; “Are you sure?"

Wie kann eine Bestätigungsanfrage vor der Ausführung eines commands verlangt werden?

MIt dem Paramenter -confirm

Der Parameter -whatif zeigt an was gemacht werden würde.

Mit welchem command kann ich auflisten welche Properties/Methoden von eine Objekt verfügbar sind?

get-member

Wie kann das aktuelle Verzeichnis in welchem sich Powershell befindet angezeigt werden?

get-location

Anzeigen von allen verfügbaren Eventlogs auf dem System.

get-eventlog -list

Wie können die geladenen oder installierten PSSnapins aufgelistet werden?

get-pssnapin #Loaded Snappins

get-pssnapin -registered #installed and available, but not necessary loaded

Wie können die Umgebungsvariablen aufgelistet werden?

wie kann eine einzelne Variable angezeigt werden? z.B von psmodulepath

get-childitem env: #Das gleiche wie set unter cmd

get-content env:psmodulepath

run powershell with preloaded Snapins

Export from a current powershell where everyting is loaded you want: Export-Console c:\myshell.psc

Create a shortcut: %windir%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -psconsolefile c:\myshell.psc

 

Wo sind Powershell Profile abgelegt. In diesen können zusätzliche Snapins definiert werden welche beim Starten geladen werden sollen.

1.) $pshome/profile.ps1—This will execute for all users of the computer, no matter
which host they’re using (remember that $pshome is predefined within
PowerShell and contains the path of the PowerShell installation folder)

2.) $pshome/Microsoft.PowerShell_profile.ps1—This will execute for all users of
the computer if they’re using the console host.If they’re using the PowerShell
ISE, the $pshome/Microsoft.PowerShellISE_profile.ps1 script will be executed
instead.

3.) $home/Documents/WindowsPowerShell/profile.ps1—This will execute only
for the current user (because it lives under the user’s home directory), no matter
which host they’re using.

4.) $home/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1—
This will execute for the current user if they’re using the console host. If they’re
using the PowerShell ISE, the $home/Documents/WindowsPowerShell/
Microsoft.PowerShellISE_profile.ps1 script will be executed instead.

If one or more of these scripts doesn’t exist, there’s no problem. The hosting application
will simply skip it and move on to the next one.

Objekte: Was wird unter einem "Object" verstanden?

This is what we’ve been calling a “table row.” It represents a single thing; like a single process or a single service

Objekte: Was wird unter einem "Property" verstanden?

This is what we called a “table column.” It represents one piece of information about an object; like a process name; process ID; or service status

Objekte: Was wird unter einer "Method" verstanden?

This is what we called an “action.” A method is related to a single object and makes that object do something; like killing a process or starting a service

Objekte: Was wird unter einer "Collection" verstanden?

This is the entire set of objects; or what we’ve been calling a “table.”

Does select-object remove not necessary properties?  and what does it pipe to the next command?

Select-Object can’t remove the properties you don’t want; because the result wouldn’t be a object anymore. Instead; Select-Object creates a new kind of custom object called a PSObject (Bei Objects muss mit -expandproperty der string ausgelesen werden Bsp: Get-TagCategory "Patching" | select -expandproperty Cardinality; bei PSObjects ist das Property bereits der string)

Wie kann der TypeName eines Objektes ausfindig gemacht werden? z.B. von get-date

get-date | gm #liefert ganz am Anfang der Auflistung den Typname -> System.DateTime

Bei get-help "command" -full aufrufen werden werden bei jedem Parameter weiter Angaben angezeigt wie "Required, Position, usw.

Was bedeutet "Accept pipeline input? true (ByPropertyname)"

Pipe input ist erlaubt. Bsp: "command1 | command2" -> Prüft ob die Propertynamen von command1 und command2 übereinstimmen und verbindet diese.

Bei get-help "command" -full aufrufen werden werden bei jedem Parameter weiter Angaben angezeigt wie "Required, Position, usw.

Was bedeutet "Accept pipeline input? true (ByValue)"

Pipe input ist erlaubt. Bsp: "command1 | command2" prüft ob der TypeName von command1 mit einem Propertytyp von command2 überein stimmt. Mit get-member bei command1 kann der TypName verifiziert werden, via get-help command2 -full können die möglichen "Inputs" angeschaut werden.

Es kann nur 1 Parameter einem Property übergeben werden; evtl. dem falschen was zu Fehlern führt

Wie können weitere "eigene" Properties mittels select hinzugefügt werden welche nicht im Object enthalten sind. z.B. bei get-process ein property namens "Start Day" mit dem "Value" des Wochentages anfügen.

Get-process | Select-Object -Property *,@{Name="Start Day"; Expression = {$_.StartTime.DayOfWeek}}

Anstelle von Name kann auch N, Label oder L  verwendet werden

Anstelle von Expression kann auch E verwendet werden

Wie behandelt Powershell Ausdrücke in Klammern?

Wie in der Algebra, Ausrücke in Klammer werden immer zuerst ausgeführt

Get-Process -computerName (import-csv .\computers.csv | select -property hostname) -> Der Klammerausdruck liefert ein PSCustomObject. Was kann gemacht werden um den Typ <String[]> zu erhalten?

Get-Process -computerName (import-csv .\computers.csv | select -exp hostname)

Das -expandProperty packt das Objekt aus und liefert ein String Object (exp ist Kurzform).

Es ist kein output Format definiert. Wann wird eine Liste und wann eine Tabelle ausgegeben?

the formatting system will display four or fewer properties -> it will use a table.

If there are five or more properties; it will use a list.