Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| pub:powershell [2013/06/14 10:24] – Externe Bearbeitung 127.0.0.1 | pub:powershell [2019/05/18 11:49] (aktuell) – Marco Krage | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ====== Powershell ====== | ====== Powershell ====== | ||
| + | Display Powershell Version | ||
| + | $PSVersionTable.PSVersion | ||
| + | If the variable does not exist, it is safe to assume the engine is version 1.0. | ||
| + | |||
| + | Ausgabe aus mehreren Befehlen zusammen | ||
| + | <code powershell> | ||
| + | Get-VM | Get-NetworkAdapter | | ||
| + | Where-object {$_.Type -ne " | ||
| + | Select @{N=" | ||
| + | </ | ||
| ===== Windows Powershell ===== | ===== Windows Powershell ===== | ||
| + | ==== Remote Session ==== | ||
| + | Enter-PSSession -ComputerName $computerName -Credential user@domain.local | ||
| - | noch nix da ;-) | + | $cred = Get-Credential user@domain.local |
| + | Enter-PSSession -ComputerName $computerName -Credential $cred | ||
| + | ==== Get Registry Value ==== | ||
| + | Get-ItemPropertyValue " | ||
| + | |||
| + | ==== Log Date ==== | ||
| + | Write-Host (get-date).DateTime | ||
| + | |||
| + | ==== Delete RAW if no matching JPG exists ==== | ||
| + | Get-ChildItem *.arw | % { if (-not (Test-Path $_.Basename+" | ||
| + | |||
| + | |||
| + | |||
| + | ==== Drucker Migration ==== | ||
| + | |||
| + | Drucker von altem Printserver zu neuem Printserver migieren inklusive Standarddrucker. | ||
| - | ===== AD Powershell ===== | ||
| <code powershell> | <code powershell> | ||
| - | $store = @() | + | $Printers |
| - | $domain = New-Object System.DirectoryServices.DirectoryEntry | + | |
| - | $searcher = New-Object System.DirectoryServices.DirectorySearcher | + | |
| - | $searcher.SearchRoot = $domain | + | |
| - | $searcher.PageSize = 100 | + | |
| - | $searcher.Filter = " | + | |
| - | $proplist | + | $oldPrintserver |
| - | foreach ($i in $propList){$prop=$searcher.PropertiesToLoad.Add($i)} | + | $newPrintserver |
| - | $results = $searcher.FindAll() | + | foreach($oldPrinter in $Printers) { |
| + | Write-Host " | ||
| - | foreach | + | if( $oldPrinter.Name.StartsWith(" |
| - | $pwdlastset=[Int64]($result.properties.Item("pwdlastset")[0]) | + | |
| - | $pwdAge=New-TimeSpan | + | $pos = $oldPrinter.Name.LastIndexOf("\") |
| - | if($pwdAge.days -gt 60){ | + | $PrinterHost = $oldPrinter.Name.Substring(0, $pos) |
| - | $obj = New-Object System.Object | + | $PrinterName |
| - | $obj | Add-Member -type NoteProperty -name Name -value | + | |
| - | $obj | Add-Member -type NoteProperty | + | Write-Host " |
| - | $obj | Add-Member -type NoteProperty -name DN -value | + | |
| - | | + | $WMIPrinter = [WMIClass]" |
| - | } | + | $res = $WMIPrinter.AddPrinterConnection("\\$newPrintserver\$PrinterName" |
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | if($oldPrinter.Default) { | ||
| + | Write-Host " | ||
| + | $newPrinter.SetDefaultPrinter() | ||
| + | } | ||
| + | |||
| + | Write-Host " | ||
| + | | ||
| + | | ||
| + | Write-Host " | ||
| + | } | ||
| + | | ||
| } | } | ||
| - | return | + | Write-Host "Press any key to continue ..." |
| + | $x = $host.UI.RawUI.ReadKey(" | ||
| </ | </ | ||
| + | ===== Active Directory ===== | ||
| - | ===== Exchange | + | ==== Gesperrte Benutzer ==== |
| + | <code powershell> | ||
| + | Import-Module activedirectory | ||
| + | |||
| + | Search-ADAccount –LockedOut | ||
| + | |||
| + | Search-ADAccount -LockedOut | Unlock-ADAccount | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Alte Computerkonten finden ==== | ||
| + | <code powershell> | ||
| + | $then = (Get-Date).AddDays(-60) # The 60 is the number of days from today since the last logon. | ||
| + | |||
| + | Get-ADComputer -Property Name, | ||
| + | |||
| + | Set-ADComputer -Enabled $false | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== Exchange ===== | ||
| Die Powershell und auch die Exchange-Verwaltungsshell nutzen s.g. Cmdlets. Diese setzt sich aus einem Verb und einem Hauptwort zusammen. Zum Beispiel '' | Die Powershell und auch die Exchange-Verwaltungsshell nutzen s.g. Cmdlets. Diese setzt sich aus einem Verb und einem Hauptwort zusammen. Zum Beispiel '' | ||
| Zeile 46: | Zeile 106: | ||
| Folgender Befehlt gibt alle Postfächer aus, welche die Zeichenfolge " | Folgender Befehlt gibt alle Postfächer aus, welche die Zeichenfolge " | ||
| < | < | ||
| - | [PS] C:\>Get-Mailbox -filter " | + | Get-Mailbox -filter " |
| Name Alias ServerName | Name Alias ServerName | ||
| Zeile 56: | Zeile 116: | ||
| Um nicht nur eine kurze tabelarische Übersicht über diese Postfächer zu bekommen, sondern alle jeweiligen Details anzuzeigen wird '' | Um nicht nur eine kurze tabelarische Übersicht über diese Postfächer zu bekommen, sondern alle jeweiligen Details anzuzeigen wird '' | ||
| < | < | ||
| - | [PS] C:\>Get-Mailbox -filter " | + | Get-Mailbox -filter " |
| Database | Database | ||
| Zeile 77: | Zeile 137: | ||
| Zuerst werden alle Postfächer ausgelesen und im nachhinein gefiltert. Je mehr Postfächer man hat um so länger dauert der Befehl dann natürlich. Auch hier kann mit '' | Zuerst werden alle Postfächer ausgelesen und im nachhinein gefiltert. Je mehr Postfächer man hat um so länger dauert der Befehl dann natürlich. Auch hier kann mit '' | ||
| < | < | ||
| - | [PS] C:\>Get-Mailbox | where {$_.EmailAddresses -match " | + | Get-Mailbox | where {$_.EmailAddresses -match " |
| Name Alias ServerName | Name Alias ServerName | ||
| Zeile 108: | Zeile 168: | ||
| Postfachgröße eines bestimmten Postfachs | Postfachgröße eines bestimmten Postfachs | ||
| < | < | ||
| - | [PS] C:\> get-MailboxStatistics kragem | ft DisplayName, | + | Get-MailboxStatistics kragem | ft DisplayName, |
| DisplayName | DisplayName | ||
| Zeile 117: | Zeile 177: | ||
| - | Postfachgrößen aller Postfächer sortiert und in größe | + | Postfachgrößen aller Postfächer sortiert und in Größe |
| < | < | ||
| - | [PS] C:> get-MailboxStatistics | Sort-Object -Descending -Property TotalItemSize | ft DisplayName, | + | Get-MailboxDatabase | Get-MailboxStatistics | Sort-Object -Descending -Property TotalItemSize | ft DisplayName, |
| DisplayName | DisplayName | ||
| Zeile 129: | Zeile 189: | ||
| Postfachgrößen als CSV (Komma) exportieren | Postfachgrößen als CSV (Komma) exportieren | ||
| < | < | ||
| - | [PS] C:> get-MailboxStatistics | Select-Object DisplayName, | + | Get-MailboxStatistics | Select-Object DisplayName, |
| </ | </ | ||
| - | Zertifika | + | ==== Datenbank ==== |
| + | Übersicht über Datenbanken und deren Größe. | ||
| + | Get-MailboxDatabase -Status | ft name, | ||
| + | |||
| + | |||
| + | ==== Postfach ==== | ||
| + | Postfach suchen | ||
| + | Get-Mailbox -filter " | ||
| + | |||
| + | Getrennte Mailboxen auflisten | ||
| + | Get-MailboxStatistics -server SERVERNAME | Where {$_.DisconnectDate -ne $null} | ||
| + | |||
| + | Mailbox Cleanup um getrennte Postfächer sofort in der GUI anzuzeigen | ||
| + | Clean-MailboxDatabase " | ||
| + | |||
| + | Postfachgröße | ||
| + | Get-MailboxStatistics kragem | ft DisplayName, | ||
| + | |||
| + | Postfachgrößen aller Postfächer sortiert und in Größe in MB | ||
| + | Get-MailboxDatabase | Get-MailboxStatistics | Sort-Object -Descending -Property TotalItemSize | ft DisplayName, | ||
| + | |||
| + | Postfachgrößen als CSV (Komma) exportieren | ||
| + | Get-MailboxStatistics | Select-Object DisplayName, | ||
| + | |||
| + | ==== Postfachfunktionen ==== | ||
| + | Postfächer mit Active Sync | ||
| + | Get-CASMailbox | where {$_.ActiveSyncEnabled -eq $true } | ||
| + | |||
| + | Postfächer mit OWA | ||
| + | Get-CASMailbox | where {$_.OWAEnabled -eq $true } | ||
| + | |||
| + | ==== Geräte ==== | ||
| + | Alle Geräte-Details anzeigen | ||
| + | Get-ActiveSyncDevice | fl UserDisplayName, | ||
| + | |||
| + | Alle Geräte-Details einer Mailbox anzeigen | ||
| + | Get-ActiveSyncDevice -Mailbox " | ||
| + | |||
| + | Alle Geräte einer Mailbox anzeigen mit LastSync Datum. Alte Geräte oben. | ||
| + | Get-ActiveSyncDeviceStatistics -Mailbox " | ||
| + | |||
| + | Alte Geräte finden | ||
| + | Get-ActiveSyncDevice -Result Unlimited | Get-ActiveSyncDeviceStatistics | Where {$_.LastSuccessSync -le (Get-Date).AddDays(" | ||
| + | |||
| + | zum löschen der Geräte statt an '' | ||
| + | |||
| + | Device manuell über ID löschen (Achtung: Wird aus allen evtl. aktiven Mailboxen gelöscht!) | ||
| + | Get-ActiveSyncDevice | where {$_.DeviceId -eq " | ||
| + | |||
| + | Device aus bestimmter Mailbox löschen (über Identity) | ||
| + | Get-ActiveSyncDevice | where {$_.Identity -eq " | ||
| + | |||
| + | http:// | ||
| + | Set-CasMailbox pponzeka –ActiveSyncAllowedDeviceIDs number1, | ||
| + | Set-CasMailbox pponzeka –ActiveSyncAllowedDeviceIDs: | ||
| + | |||
| + | ==== Zertifikat | ||
| TODO | TODO | ||
| To renew the certificate perform following steps: | To renew the certificate perform following steps: | ||
| Zeile 150: | Zeile 266: | ||
| - | ===== VMware RDM Lun ID ===== | + | ===== VMware===== |
| + | ==== RDM + LUN ID ==== | ||
| < | < | ||
| $RDMs = @() | $RDMs = @() | ||