Function Get-OSVersion-withLogging { Param ( [Parameter(Position=0,Mandatory=$False,HelpMessage='Choose the Return Type. Name')] [ValidateSet(Name,)] [STRING]$QueryType= ) #end param ## Parameter für Zahl oder Name ## Parameter für Version oder Buildnummer BEGIN { #Clear Error Variable $error.clear() $FunctionName = $((($MyInvocation.MyCommand.Name) -split "\.")[0].ToString()) Write-Host "DEBUG Info - $($FunctionName): Begin Function." #Checking if "Write-LogFile" Module was loaded IF (Get-Module -All -Name "Write-LogFile") { Write-Host "DEBUG Info - $($FunctionName): Write-LogFile - Module exists." } #end if ELSE { Write-Host "" Write-Host "DEBUG Info - $($FunctionName): Write-LogFile - Module does not exist!" Write-Host "DEBUG Info - $($FunctionName): Please load the Module and try again, running this Function/Module!" Write-Host "DEBUG Info - $($FunctionName): Exiting, because of this Issue." EXIT } #end else } #end begin PROCESS { #Clear Error Variable $error.clear() IF (((Get-WmiObject -class Win32_OperatingSystem).version) -match 6.1) { write-host "Windows Version: 7 / Server 2008R2 was detected." Set-Variable -Name OSVersion -Value "Win8.0" Return $OSVersion } #end if ELSEIF (((Get-WmiObject -class Win32_OperatingSystem).version) -match 6.2) { write-host "Windows Version: 8.0 / Server 20012 was detected." Set-Variable -Name OSVersion -Value "Win8.0" Return $OSVersion } #end if ELSEIF (((Get-WmiObject -class Win32_OperatingSystem).version) -match 6.3) { write-host "Windows Version: 8.1 / Server 2012R2 was detected." Set-Variable -Name OSVersion -Value "Win8.1" Return $OSVersion } #end elseif ELSEIF (((Get-WmiObject -class Win32_OperatingSystem).version) -match 10.0) { Write-Host "Windows Version: 10 / Server 2016 was detected." Set-Variable -Name OSVersion -Value "Win10.0" Return $OSVersion } #end elseif ELSE { Write-Host "Windows Version:" ((Get-WmiObject -class Win32_OperatingSystem).version) "was detected." Write-Host "ERROR: The Operation-System Version is unknown, cant proceed!" Write-Host "This Script works only with Windows 8, 8.1 and 10 Versions." Set-Variable -Name OSVersion -Value "Error" Return $OSVersion } #end else } #end process END { Write-Host "DEBUG Info - $($FunctionName): End Function." } #end end } #end function