Powershell:Spicker

Hilfe / Help:

Get-Command Get-*
Get-Help Get-I*
Get-PSDrive

get-help Get-ItemProperty -detailed
get-help Get-ItemProperty -full

Ohne das geht gar nix:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force

Powershell Version:

get-host

Supress Error Messages in Script:

Fehlermeldungen im Skript unterdrücken:

Variablen auslesen:

Get-Variable -name ErrorActionPreference -scope local
     oder
$Local:ErrorActionPreference

Get-Variable -name ErrorActionPreference -scope global
     oder
$Global:ErrorActionPreference

Link:
The Hey, Scripting Guy!

Objekt-Eigenschaften und –Methoden anzeigen:

<object> | Get-Member
Get-Member -inputObject <object>

Beispiele:

([System.Int32]$Num) | Get-Member

$ie = New-Object -ComObject InternetExplorer.Application
$ie | Get-Member

($xl = New-Object -ComObject InternetExplorer.Application) | Get-Member

(New-Object -ComObject Excel.Application) | Get-Member
[System.Int32]$Num = $null
get-member -inputobject $Num

get-member -inputobject (New-Object System.int32)

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
get-member -inputobject (New-Object System.Windows.Forms.Button)

Links:
Microsoft Technet Library

ACL:

Get-ChildItem -recurse | Get-Acl | Format-List -Property *

Get-ChildItem -recurse | Get-Acl | export-csv $env:temp\filename.csv

Get-ChildItem -recurse | Get-Acl | Export-Clixml $env:temp\filename.xml

Links:
Microsoft Technet Library: Get-Acl
Microsoft Technet Library: Set-Acl
IT-Visions.de: Zugriffsrechteliste über SSDL setzen

Begriffe:
Microsoft Technet Library: SDDL (Security Descriptor Definition Language)
Microsoft Technet Library: ACL (Access Control List)

ARRAYs

$a = New-Object -TypeName System.Collections.ArrayList
[void]$a.Add("red")
[void]$a.Add("yellow")
[void]$a.Add("orange")
[void]$a.Add("green")
[void]$a.Add("blue")
[void]$a.Add("purple")
[void]$a.Add("black")
[void]$a.Add("white")

[System.Collections.ArrayList]$aaa = ("red", "yellow", "orange", "green", "blue", "purple", "black", "white")

$y = @("red", "yellow", "orange", "green", "blue", "purple", "black", "white")

http://technet.microsoft.com/en-us/library/ee692802.aspx

Datum/Zeit

Technet Get-Date

ISO-8601: get-Date -format s

Variablen/Konstanten:

Konstanten deklarieren:

New-Variable -Name "MyConstant"   -Value $LogFilePath   -Scope "Script" -Option "Constant"

Variablen auslesen:

Get-Variable -name ErrorActionPreference -scope local
     oder
$Local:ErrorActionPreference

Prüfen ob Variable vorhanden ist:

Test-Path -Path Variable:ErrorActionPreference

Prüfen ob Variable vorhanden ist und einen Wert hat:

if (Get-Variable -Name "Code" -ValueOnly -ErrorAction "Ignore") { ... }

ENV-Variablen:

# list all environment variables and values
Get-ChildItem Env:

# get environment variable value
$Env:USERPROFILE

# check whether environment variable is set
Test-Path -Path Env:USERPROFILE

http://technet.microsoft.com/en-us/library/ff730964.aspx

Powershell und MS Office:

Excel
Excel

System uptime:

[Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime)

New-TimeSpan -Start ([Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime))

(New-TimeSpan -Start ([Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime))).ToString()

Microsoft Technet Library: Windows PowerShell Tips
Microsoft Technet Library: Determining the Size of a Folder

Base64:

$Text = [System.Text.Encoding]::UTF8.GetBytes("HALLO, das ist ein Beispiel")
[System.Convert]::ToBase64String($Text)

$Text= [System.Convert]::FromBase64String("SEFMTE8sIGRhcyBpc3QgZWluIEJlaXNwaWVs")
[System.Text.Encoding]::UTF8.GetString($Text)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License