PowerShell Befehle

Verbindung zu Office365:

neues Modul AzureAD:
Install-Module -Name AzureAD

altes Modul MSOnline:
Install-Module MSOnline

$credential = Get-Credential
Connect-MsolService -Credential $credential
Connect-AzureAD -Credential $credential

https://docs.microsoft.com/de-ch/office365/enterprise/powershell/connect-to-office-365-powershell
Office 365 AD Sync Befehle:
Import-Module ADSync
Start-ADSyncSyncCycle -PolicyType Delta
Start-ADSyncSyncCycle -PolicyType Initial
Force AzureAD Password Sync:
Entweder über das ADConnect Konfigurationstool über Troubleshooting oder mit Powershell:
$adConnector = "<insert local connector name here>"
$aadConnector = "<insert AzureAD connector name here>"
$c = Get-ADSyncConnector -Name $adConnector
$p = New-Object Microsoft.IdentityManagement.PowerShell.ObjectModel.ConfigurationParameter "Microsoft.Synchronize.ForceFullPasswordSync", String, ConnectorGlobal, $null, $null, $null
$p.Value = 1
$c.GlobalParameters.Remove($p.Name)
$c.GlobalParameters.Add($p)
$c = Add-ADSyncConnector -Connector $c
Set-ADSyncAADPasswordSyncConfiguration -SourceConnector $aadConnector -TargetConnector $azureadConnector -Enable $false
Set-ADSyncAADPasswordSyncConfiguration -SourceConnector $aadConnector -TargetConnector $azureadConnector -Enable $true

MAC Adresse per Powershell ansehen:
Get-NetAdapter | select name, macaddress | sort macaddress
Send Email per Powershell Command:
Send-MailMessage -SmtpServer IPorMailServerName -To Emailto@xyz.ch -From EmailFrom@xyz.ch -Subject "It`s me Ronald" -Body "Send a Test Mail"
Passwort Ablaufdatum ermitteln per Powershell Command:
https://bent-blog.de/powershell-ablaufdatum-des-eigenen-kennworts-ermitteln/

([System.Security.Principal.WindowsIdentity]::GetCurrent().User).Value | get-aduser -Properties Displayname,PasswordLastSet,msDS-UserPasswordExpiryTimeComputed | Select-Object -Property Displayname,SamAccountName,PasswordLastSet,@{Name="ExpirationDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}},@{Name="Duration";Expression={$(New-TimeSpan -Start $(Get-Date) -End $([datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed"))).ToString("%d")+" days"}}

Command:
net user %username% /domain

Letzter Systemstart anzeigen:
Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime


Domain Functional Level und Forest Functional Level, sowie Schema Level:
Get-ADDomain | fl Name,DomainMode
Get-ADForest | fl Name,ForestMode

Get-ADObject (Get-ADRootDSE).schemaNamingContext -Property objectVersion
Verbindungsaufbau zu M365:
https://docs.microsoft.com/de-ch/office365/enterprise/powershell/connect-to-office-365-powershell

Installierte Module anzeigen:
Get-InstalledModule

TLS muss aktiviert sein um Module zu installieren:
[Net.ServicePointManager]::SecurityProtocol
oder [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

64Bit Version:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
32Bit Version:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord


Module Installieren:
Install-Module -Name AzureAD
Install-Module -Name MicrosoftTeams
Install-Module -Name ExchangeOnlineManagement
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

 
Update der Module z.B:
Update-Module -Name ExchangeOnlineManagement
 
Installierte Version auslesen:
Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement
 
Verbindung Aufbauen:
$UserCredential = Get-Credential
Connect-AzureAD -Credential $usercredential
Connect-MsolService -Credential $usercredential
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
Connect-SPOService -Url https://<domainhost>-admin.sharepoint.com -credential $UserCredential
Connect-MicrosoftTeams -Credential $UserCredential

   
Allenfalls noch Skype Verbindung kann Warnmeldungen generieren:
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $UserCredential
Import-PSSession $sfboSession

   
Security & Compliance Center:
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication "Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc

 
 
Verbindungen sauber trennen:
Remove-PSSession $sfboSession ; Remove-PSSession $SccSession ; Disconnect-SPOService ; Disconnect-MicrosoftTeams
Check if ModernAuthentication is enabled:
Get-OrganizationConfig | Format-Table Name,OAuth* -Auto
SMTP Test mit Port 587 per Powershell:

$creds = get-credential
Send-MailMessage -From <O365 email address> -To <Recipient email address> -Subject «Test Email» -Body «Test SMTP Service from Powershell on Port 587» -SmtpServer smtp.office365.com -Credential $creds -UseSsl -Port 587
Teams Cache löschen:

Dieses Powershell Script ausführen, am besten, wenn das Teams beendet ist:

Write-Host «Microsoft Teams wird jetzt beendet, um den Cache zu leeren.»
try{
Get-Process -ProcessName Teams | Stop-Process -Force
Start-Sleep -Seconds 5
Write-Host «Microsoft Teams wurde erfolgreich beendet.»
}
catch{
echo $_
}
# Der Cache wird nun geleert
try{
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\code cache\cache» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\blob_storage» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\databases» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\cache» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\gpucache» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\Indexeddb» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\Local Storage» | Remove-Item -Force -Recurse
Get-ChildItem -Path $env:APPDATA\»Microsoft\teams\tmp» | Remove-Item -Force -Recurse
}
catch{
echo $_
}
write-host «Der Microsoft Teams Cache wurde erfolgreich geleert.»
Azure User als lokaler Admin hinzufügen
net localgroup administratoren AzureAD\ronald.schmid@uniqconsulting.ch /add
Winget Update der Tools Befehl:
winget upgrade --all --accept-package-agreements
Powershell in Powershell als andern Benutzer ausführen:
start powershell -credential ""





Hinterlassen Sie einen Kommentar