Private/Wissen/X_Technology/X01PowerShell-History.ps1

#region Windows PowerShell 1.0 - 4.0

# 1.0 = Markteinführung
# 2.0 = Remoting via RPC
Get-Help -Name * -Parameter ComputerName # Nur diese Cmdlets können remote zugreifen
# 3.0 = Default in: Windows7 / Windows Server 2008 R2; Min. OS: >XP, >VISTA
# 3.0 = Remoting via WinRM, Workflows, Scheduled[Jobs], Windows PowerShell Web Access, Netzlaufwerke verbinden (New-PSDrive), Aktualisierbare Hilfe, Web Cmdlet's
# 3.0 = Vereinfachte Syntax:
Get-Process | Where-Object -FilterScript {$_.Handles -gt 500}
Get-Process | Where-Object -Property Handles -GT -Value 500
# 4.0 = DEFAULT: Windows 8, Windows Server 2012, Desired State of Configuration (DSC)

#endregion

#region Windows PowerShell 5.0, 5.1

# Default OS: Windows 10, Windows Server 2016

# Softwarepakete installieren
# Switch-Verwaltung
# OOP

#region Details zu Neuerungen

# Alle Details zur 5.0 Version unter:
Get-Help about_Windows_PowerShell_5.0 -ShowWindow
Start-Process http://msdn.microsoft.com/de-de/powershell/scripting/whats-new/what-s-new-in-windows-powershell-50

#region Get-ItemPropertyValue

#NEU: Get-ItemPropertyValue
#FRÜHER:
(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name ApplicationBase).ApplicationBase
#JETZT:
Get-ItemPropertyValue -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name ApplicationBase

#endregion

#region Einfache String-Operationen
"Hallo Welt" | ConvertFrom-String
"Hallo Welt" | ConvertFrom-String -Delimiter "ll"
"Hallo Welt" | ConvertFrom-String -PropertyNames FirstWord, SecondWord

"Lee Holmes", "Steve Lee", "Jeffrey Schmitt" | Convert-String -Example "Bill Gates=Gates, B.","John Smith=Smith, J."

"Hallo Welt" | Format-Hex
#endregion

#region ZIP-Archive

#
#Test-Daten erzeugen
#
New-Item -Path C:\Temp\ZipMich -ItemType Directory -Force
1..1MB -join ";" | Set-Content -Path "C:\Temp\ZipMich\LogFile1.txt" -Force
1..1MB -join ";" | Set-Content -Path "C:\Temp\ZipMich\LogFile2.txt" -Force

#
# Compress-Archive
#
"C:\Temp\ZipMich" | Compress-Archive -DestinationPath C:\Temp\ZipMich.zip -CompressionLevel Optimal -Force
Get-Help Compress-Archive -ShowWindow

#
# Expand-Archive
#
"C:\Temp\ZipMich.zip" | Expand-Archive -DestinationPath C:\Temp\Backup -Force
Get-Help Expand-Archive -Full

#endregion

#region Software-Installation

Set-ExecutionPolicy -ExecutionPolicy AllSigned

Get-Command -Module PowerShellGet, PackageManagement

Find-Package | Out-GridView
Install-Package -Name AKPT -Force
Get-Module -ListAvailable
Get-Command * -Module AKPT
Get-AKAbout
Uninstall-Package -Name AKPT

Register-PSRepository -Name "myNuGetSource" â€“SourceLocation "https://www.myget.org/F/powershellgetdemo/api/v2" -PublishLocation "https://www.myget.org/F/powershellgetdemo/api/v2/Packages" -InstallationPolicy Trusted
Get-PSRepository
Unregister-PSRepository -Name "myNuGetSource"

#endregion

#region Kryptographie

Get-Command -Module Microsoft.PowerShell.Security

$MyCertInf = @"
[Version]
Signature = "$Windows NT$"
 
[Strings]
szOID_ENHANCED_KEY_USAGE = "2.5.29.37"
szOID_DOCUMENT_ENCRYPTION = "1.3.6.1.4.1.311.80.1"
 
[NewRequest]
Subject = "cn=me@example.com"
MachineKeySet = false
KeyLength = 2048
KeySpec = AT_KEYEXCHANGE
HashAlgorithm = Sha1
Exportable = true
RequestType = Cert
 
KeyUsage = "CERT_KEY_ENCIPHERMENT_KEY_USAGE | CERT_DATA_ENCIPHERMENT_KEY_USAGE"
ValidityPeriod = "Years"
ValidityPeriodUnits = "1000"
 
[Extensions]
2.5.29.37="{text}1.3.6.1.4.1.311.80.1"
"@

Set-Content -Path C:\Temp\MyCert.inf -Value $MyCertInf
CertReq -new C:\Temp\MyCert.inf C:\Temp\MyCert.cer
$cert = Get-ChildItem -pv Cert:\CurrentUser\My | Where-Object -Property Subject -EQ -Value "cn=me@example.com"

$crypt = "Hallo Welt" | Protect-CmsMessage -To $cert
Unprotect-CmsMessage -Content $crypt -To $cert

#endregion

#region OOP

Get-Help about_Classes -ShowWindow

enum Farbe
{
    Blau
    Grün
    Rot
}
$meineFarbe = [Farbe]::Grün
$meineFarbe

class Auto
{
    [Farbe]$Farbe
    $PS
}

$meinAuto = New-Object -TypeName Auto

$meinAuto.Farbe = [Farbe]::Grün
$meinAuto.PS = 100
$meinAuto | Get-Member

#endregion

#region Weitere neue Cmdlet's

Set-Clipboard -Value "Hallo Köln!"
Get-Clipboard

Clear-RecycleBin -DriveLetter c: -Confirm:$false

New-TemporaryFile

New-Guid

# symbolischer Verknüpfungen
New-Item -ItemType SymbolicLink -Name MySymLinkDir -Target $pshome

# -Depth 2
Get-ChildItem c:\ -Recurse -Depth 2 -Force

#endregion

#region DataCenter Abstraction Layer (DAL)

<#
    Mit dieser Technologie können Sie direkt auf bestimmte
    Netzwerkkomponenten wie Switches und Router zugreifen.
 
    Dazu muss die Hardware diese Technik aber auch unterstützen.
    In diesem Bereich spielen vor allem
    Cisco und Huawei eine wichtige Rolle.
#>


$Session = New-CimSession -ComputerName $MyNetworkSwitchName
Get-NetworkSwitchFeature -CimSession $Session

<#
    Name IsEnabled InstanceID PSComputerName
    ---- --------- ---------- --------------
    SSH True Contoso:Feature:2 10.19.26.49
    Tacacs True Contoso:Feature:3 10.19.26.49
    BGP False Contoso:Feature:4 10.19.26.49
    VLAN True Contoso:Feature:5 10.19.26.49
    LACP True Contoso:Feature:6 10.19.26.49
    DHCP False Contoso:Feature:7 10.19.26.49
    LLDP True Contoso:Feature:8 10.19.26.49
#>


Get-Help Get-NetworkSwitchFeature -Full

Get-Command -Module NetworkSwitchManager | Out-GridView

#endregion

#region Open Data Protocol

<# Das Open Data Protocol, kurz OData ist ein von Microsoft veröffentlichtes HTTP-basiertes Protokoll
   für den Datenzugriff zwischen kompatiblen Softwaresystemen. Aufbauend auf älteren Protokollen wie
   ODBC und JDBC kann OData u.a. innerhalb von Cloud-Diensten (Azure), MySQL, Java und Rails
   eingebunden werden und ist in der Lage, in der Client-Server-Kommunikation eine einheitliche Semantik
   für den Datenaustausch zur Verfügung zu stellen.
#>


Export-ODataEndpointProxy -Uri 'http://services.odata.org/v3/(S(snyobsk1hhutkb2yulwldgf1))/odata/odata.svc' `
                          -MetadataUri 'http://services.odata.org/v3/(S(snyobsk1hhutkb2yulwldgf1))/odata/odata.svc/$metadata' `
                          -AllowUnsecureConnection `
                          -OutputModule C:\Temp\GeneratedScript.psm1 `
                          -ResourceNameMapping @{Products = 'Merchandise'}

#endregion

#region Optimierte Unterstützung für 'Desired State Configuration' (DSC)

<#
    Weitere Neuerungen in der PowerShell betreffen die mit der
    PowerShell 4.0 eingeführte Technologie Desired State Configuration (DSC).
 
    Hauptsächlich gibt es neue Optionen um festzulegen auf wievielen Computern
    gleichzeitig die Änderungen implementiert werden sollen.
 
    Mit dem Modul 'PowerShellGet' können Sie DSC-Ressourcen in der
    'PowerShell Resource Gallery' nutzen, installieren oder hochladen.
#>


#endregion

#endregion

#region PowerShell Core 6.0

#endregion

# ! # Neue Funktionen in diesem Modul
Get-Command -Module Microsoft.PowerShell.LocalAccounts
Get-Command -Module PowerShellGet
Get-Command -Module PackageManagement
Get-ComputerInfo # Neu

# ! Besseres Debugging für DSC und PowerShell-Klassen

#endregion