Installieren von Powershell 7

Mit winget ist ein Command-Line Tool und Bestandteil von Windows 11

winget search Microsoft.PowerShell

Output ist

Name               Id                           Version Source
---------------------------------------------------------------
PowerShell         Microsoft.PowerShell         7.3.7.0 winget
PowerShell Preview Microsoft.PowerShell.Preview 7.4.0.5 winget

Hiermit installieren wir die neues Version

winget install --id Microsoft.Powershell --source winget

Output während der Installation

Found PowerShell [Microsoft.PowerShell] Version 7.3.7.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.3.7/PowerShell-7.3.7-win-x64.msi
  ██████████████████████████████   100 MB /  100 MB
Successfully verified installer hash
Starting package install...
Successfully installed

Installieren von ExchangeOnlineManagement

<#
.SYNOPSIS
Checks if the ExchangeOnlineManagement module is installed and installs it if not.

.DESCRIPTION
This function checks if the ExchangeOnlineManagement module is installed on the system. If the module is not installed, it installs it using the Install-Module cmdlet.

.OUTPUTS
[bool]
Returns $true if the module is already installed or if it is successfully installed, otherwise returns $false.

.EXAMPLE
Check-ExchangeOnlineManagementModule
Checks if the ExchangeOnlineManagement module is installed and installs it if not.
#>
function Check-ExchangeOnlineManagementModule
{
	# Check if the module is already installed
	$moduleInstalled = Get-Module -ListAvailable -Name ExchangeOnlineManagement
	
	if ($moduleInstalled)
	{
		Write-Output "ExchangeOnlineManagement module is already installed."
		return $true
	}
	else
	{
		# Install the module
		try
		{
			Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber -Scope CurrentUser -ErrorAction Stop
			Import-Module ExchangeOnlineManagement -ErrorAction Stop
			Write-Output "ExchangeOnlineManagement module has been successfully installed."
			return $true
		}
		catch
		{
			Write-Output "Failed to install the ExchangeOnlineManagement module."
			return $false
		}
	}
}

# Usage example for the Check-ExchangeOnlineManagementModule function
Check-ExchangeOnlineManagementModule

Installieren der Remote Server Tools in Windows 10

<#
.SYNOPSIS
Installs the Remote Server Administration Tools (RSAT) and its requirements.

.DESCRIPTION
This function installs the RSAT tool and its requirements on the local machine. The RSAT tool allows administrators to remotely manage Windows servers from a Windows client computer.

.NOTES
- This function requires administrative privileges to install the RSAT tool.
- The RSAT tool and its requirements may vary depending on the Windows version.

.EXAMPLE
Install-RSAT
Installs the RSAT tool and its requirements on the local machine.
#>
function Install-RSAT
{
	# Check if the user has administrative privileges
	if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
	{
		Write-Output "This function requires administrative privileges."
		exit 1
	}
	
	# Check the Windows version
	$osVersion = (Get-WmiObject -Class Win32_OperatingSystem).Caption
	$isWindows10 = $osVersion -like "*Windows 10*"
	
	# Install the RSAT tool and its requirements
	if ($isWindows10)
	{
		# RSAT for Windows 10
		Write-Output "Installing RSAT for Windows 10..."
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.CertificateServices.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.DHCP.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.Dns.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.FileServices.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.IPAM.Client.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.LLDP.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.NetworkController.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.NetworkLoadBalancing.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.ServerManager.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.Shielded.VM.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.StorageMigrationService.Management.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.StorageReplica.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.SystemInsights.Management.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.VolumeActivation.Tools~~~~0.0.1.0" -NoRestart
		Enable-WindowsOptionalFeature -Online -FeatureName "Rsat.WSUS.Tools~~~~0.0.1.0" -NoRestart
		Write-Output "RSAT for Windows 10 has been installed."
	}
	else
	{
		# RSAT for other Windows versions
		Write-Output "Installing RSAT for other Windows versions..."
		$rsatInstallerPath = "https://download.microsoft.com/download/1/1/7/117FB25C-8F8C-42E3-9F0E-7A5BFB5C0F9F/WindowsTH-RSAT_WS2016-x64.msu"
		$rsatInstallerFilePath = "$env:TEMP\WindowsTH-RSAT_WS2016-x64.msu"
		
		# Download the RSAT installer
		Write-Output "Downloading RSAT installer..."
		Invoke-WebRequest -Uri $rsatInstallerPath -OutFile $rsatInstallerFilePath
		
		# Install RSAT
		Write-Output "Installing RSAT..."
		Start-Process -FilePath $rsatInstallerFilePath -ArgumentList "/quiet" -Wait
		
		# Clean up the RSAT installer file
		Write-Output "Cleaning up..."
		Remove-Item -Path $rsatInstallerFilePath
		
		Write-Output "RSAT has been installed."
	}
}

# Usage example for the Install-RSAT function
Install-RSAT

Herstellen einer Verbindung zu Exchange Online mit PowerShell

Herstellen einer Verbindung ohne Proxy

$Cred = Get-Credential 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell/ -Credential $cred -Authentication Basic -AllowRedirection 
import-PSSession $Session

Herstellen einer Verbindung mit Proxy

$Cred = Get-Credential 
$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell/ -Credential $cred -Authentication Basic -AllowRedirection -SessionOption $proxysettings 
import-PSSession -AllowClobber $Session