RMS_Support_Tool.psm1

#Requires -RunAsAdministrator
#Requires -Version 5.1

<# ╔════════════════════════════════════════════════════════════════════════════════╗
   ║ WARNING: DO NOT MODIFY ANY COMPONENT OF THE RMS_SUPPORT_TOOL IN ANY KIND, as ║
   ║ this will result in incorrect information in the analysis of your environment. ║
   ╚════════════════════════════════════════════════════════════════════════════════╝ #>


<# Defining global variables #>
$Global:strScriptVersion = "1.1.1" <# Defining version #>
$Global:strWindowsEdition = (Get-CimInstance Win32_OperatingSystem).Caption <# Evaluating Windows version #>
$Global:strTempFolder = (Get-Item Env:"Temp").Value <# Defining user temp folder #>
$Global:strUserLogPath = New-Item -ItemType Directory -Force -Path $Global:strTempFolder"\RMS_Support_Tool\Logs" <# Defining default user log path #>
$Global:strUniqueLogFolder = $null <# Defining unique user log folder; used in fncUserLogging #>
$Global:bolCommingFromMenu = $false <# Defining control variable for menu handling inside function calls #>

Function RMS_Support_Tool {

    <#
    .SYNOPSIS
        The 'RMS Support Tool' provides the functionality to reset all Microsoft® AIP/AD RMS services.
 
    .DESCRIPTION
        The 'RMS Support Tool' provides the functionality to reset all Microsoft® AIP/AD RMS services. Its main purpose is to delete the currently downloaded policies and reset the user settings for AIP/AD RMS service, and it can also be used to collect data for troubleshooting.
 
    .NOTES
        Please find more information on this website about how to use the RMS_Support_Tool:
 
        https://aka.ms/RMS_Support_Tool
 
        Note:
 
        - Please only run RMS_Support_Tool if you have been prompted to do so by a Microsoft® support technician.
        - It is recommended to test the RMS_Support_Tool with a test environment before executing it in a live environment.
        - Do not modify any component of the RMS_Support_Tool in any kind, as this will result in incorrect information in the analysis of your environment.
        - There is no support for the RMS_Support_Tool. Please see the disclaimer below.
        - Nomenclature:
            RMS = Rights Management Service.
            AD RMS = Active Directory Rights Management Service.
            AIP = Azure Information Protection.
            MSIP/MIP = Microsoft Information Protection
            MSIPC = Microsoft Information Protection Client.
            DRM = Digital Rights Management
 
        MIT LICENSE
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
        DISCLAIMER OF WARRANTY: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PLEASE DO UNDERSTAND THAT THERE IS NO GUARANTEE THAT THIS SOFTWARE WILL RUN WITH ANY GIVEN ENVIRONMENT OR CONFIGURATION. BY INSTALLING AND USING THE SOFTWARE YOU ACCEPT THIS DISCLAIMER OF WARRANTY. IF YOU DO NOT ACCEPT THE TERMS, DO NOT INSTALL OR USE THIS SOFTWARE.
         
        VERSION
        1.1.1
         
        CREATE DATE
        01/19/2020
 
        AUTHOR
        Claus Schiroky
        Customer Service & Support EMEA
        Microsoft Deutschland GmbH
 
        HOMEPAGE
        https://aka.ms/RMS_Support_Tool
 
        PRIVACY STATEMENT
        https://privacy.microsoft.com/PrivacyStatement
 
        COPYRIGHT
        Copyright (c) 2020 Microsoft (c). All rights reserved.
 
    .PARAMETER Information
        This parameter shows syntax and a description.
 
    .PARAMETER Disclaimer
        This paramter displays the disclaimer of warranty.
        Please read it carefully, and act accordingly.
 
    .PARAMETER Help
        This parameter opens the help file.
 
        Note:
 
        - If you do not have the help file on your local hard drive, it will automatically be downloaded from the internet.
 
    .PARAMETER Reset
        IMPORTANT: Before you proceed with this option, close all applications that run or use Microsoft® Office or AIP/AD RMS.
        This parameter removes all AIP/AD RMS certificates, policy templates and all corresponding registry keys. Before, the RMS_Support_Tool creates a backup copy of existing custom configurations from the following registry key:
 
        [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSIPC\ServiceLocation]
 
        The name of the backup file is “ServiceLocationBackup.reg”.
 
        IMPORTANT: Please review point 2 in the Requirements section of the help file for additional information.
 
        Note:
 
        - When an Office 2013 installation is detected, modern authentication (ADAL) is automatically enabled as a precaution.
 
    .PARAMETER SilentReset
        IMPORTANT: Before you proceed with this option, close all applications that run or use Microsoft® Office or AIP/AD RMS.
        This parameter removes all AIP/AD RMS certificates, policy templates and all corresponding registry keys. Before, the RMS_Support_Tool creates a backup copy of existing custom configurations from the following registry key:
 
        [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSIPC\ServiceLocation]
 
        The name of the backup file is “ServiceLocationBackup.reg”.
 
        IMPORTANT: Please review point 2 in the Requirements section of the help file for additional information.
 
        Note:
 
        - This parameter does not generate any output (silent).
        - When an Office 2013 installation is detected, modern authentication (ADAL) is automatically enabled as a precaution.
 
    .PARAMETER UserLogging
        IMPORTANT: Close all applications that run or use Microsoft® Office or AIP/AD RMS before you proceed with this option.
         
        In a first step, this parameter activates the required logging, tracing or debugging mechanisms by implementing registry settings, and enabling some Windows event logs. This process will be reflected by a progress bar “Enable logging...".
         
        In a second step asks you to reproduce the problem. While you’re doing so, the RMS_Support_Tool collects and records data. Once you have reproduced the problem, all collected files will be stored into the default logs folder (%temp%\RMS_Support_Tool\Logs). Every time you call this option, a new unique subfolder will be created in the logs-folder that reflects the date and time when it was created, e.g. “190221-133005”. While the files are being cached, you will see a progress bar “Collecting logs...".
 
        In the last step, the RMS_Support_Tool resets all activated log, trace, and debug settings to their defaults. This process will be reflected by a progress bar “Disable logging...".
 
        You can then review the log files in the logs folder.
 
        Note:
 
        - An additional tool from Windows Sysinternals (DebugView) is required for logging.
        - If you do not have this tool on your local hard drive, it will be automatically downloaded from the internet.
 
    .PARAMETER AdminLogging
        This parameter collects only AIP configuration information of your tenant.
        Please request assistance from your administrator to proceed this option.
 
        Note:
 
        - You need to know your Microsoft® Office 365 global administrator account information to proceed with this option, as you will be asked for your credentials.
        - An additional tool from Windows Sysinternals (DebugView) is required for logging.
        - If you do not have this tool on your local hard drive, it will be automatically downloaded from the internet.
 
    .PARAMETER CompressLogs
        IMPORTANT: This command-line parameter should always be used at the very end of a scenario. Otherwise the compressed .zip file will not be created.
 
        This parameter compress all collected logs files into a .zip file, and the corresponding path and file name is displayed.
        In addition, the default logs folder (%temp%\RMS_Support_Tool\Logs) will be cleaned.
        After this step you can review the log files, and send the collected logs to Microsoft® support technician.
 
    .PARAMETER Menu
        This will start the RMS_Support_Tool with the default menu.
 
    .PARAMETER Version
        This parameter displays the version of the RMS_Support_Tool, and offers a hyperlink to check for the latest version of the RMS_Support_Tool.
 
    .EXAMPLE
        RMS_Support_Tool -Information
        This shows syntax and a description.
 
    .EXAMPLE
        RMS_Support_Tool -Disclaimer
        This displays the disclaimer of warranty.
        Please read it carefully, and act accordingly.
 
    .EXAMPLE
        RMS_Support_Tool -Help
        This parameter opens the help file.
 
    .EXAMPLE
        RMS_Support_Tool -Reset
        This parameter removes all AIP/AD RMS certificates, policy templates and all corresponding registry keys.
 
    .EXAMPLE
        RMS_Support_Tool -SilentReset
        This parameter removes all AIP/AD RMS certificates, policy templates and all corresponding registry keys without any user output (silent).
 
    .EXAMPLE
        RMS_Support_Tool -UserLogging
        This parameter activates user logging and starts collecting data.
 
    .EXAMPLE
        RMS_Support_Tool -AdminLogging
        This parameter collects only AIP configuration information of your tenant.
 
    .EXAMPLE
        RMS_Support_Tool -CompressLogs True
        This parameter compress all collected logs files into a .zip file, and the corresponding path and file name is displayed.
 
    .EXAMPLE
        RMS_Support_Tool -Reset -UserLogging -CompressLogs True
        This parameter removes all AIP/AD RMS certificates, policy templates and all corresponding registry keys, starts user logging, and compress all collected logs files to a .zip file in the default log folder (%temp%\RMS_Support_Tool).
 
    .EXAMPLE
        RMS_Support_Tool -Menu
        This will start the RMS_Support_Tool with the default menu.
 
    .EXAMPLE
        RMS_Support_Tool -Version
        This parameter displays the version of the RMS_Support_Tool, and offers a hyperlink to check for the latest version of the RMS_Support_Tool.
 
    .LINK
        https://aka.ms/RMS_Support_Tool
 
    #>

    
    <# Defining CmdletBinding attribut to define parameter settings #>
    [CmdletBinding (
        HelpURI = "https://aka.ms/RMS_Support_Tool", <# URL for help file; used with parameter Help #>
        PositionalBinding = $false, <# Parameters in the function are not positional #>
        DefaultParameterSetName = "Menu" <# If no parameter has been selected, this will be the default parameter #>
    )]

    <# Parameter definitions #>
    Param (
        
        <# Parameter definition for Information #>
        [Parameter(ParameterSetName = "Information")]
        [switch]$Information,

        <# Parameter definition for Disclaimer #>
        [Parameter(ParameterSetName = "Disclaimer")]
        [switch]$Disclaimer,

        <# Parameter definition for Help #>
        [Parameter(ParameterSetName = "Help")]
        [switch]$Help,

        <# Parameter definition for silent Reset #>
        [Parameter(ParameterSetName = "Silent Reset")]
        [switch]$SilentReset,

        <# Parameter definition for Reset #>
        [Parameter(ParameterSetName = "Reset and logging")]
        [switch]$Reset,

        <# Parameter definition for UserLogging #>
        [parameter(ParameterSetName = "Reset and logging")]
        [switch]$UserLogging,

        <# Parameter definition for AdminLogging #>
        [Parameter(ParameterSetName = "Reset and logging")]
        [switch]$AdminLogging,

        <# Parameter definition for CompressLogs, with preset. #>
        [Parameter(ParameterSetName = "Reset and logging")]
        [ValidateSet("True")] 
        [string]$CompressLogs,
        
        <# Parameter definition for Menu #>
        [Parameter(ParameterSetName = "Menu")]
        [switch]$Menu,

        <# Parameter definition for Version #>
        [Parameter(ParameterSetName = "Version")]
        [switch]$Version

    )

    <# Action if the parameter '-Information' has been selected #>
    If ($PsCmdlet.ParameterSetName -eq "Information") {

        <# Calling information function #>
        fncInformation

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Information" -strLogValue "Proceeded"

    } 

    <# Action if the parameter '-Disclaimer' has been selected #>
    If ($PSBoundParameters.ContainsKey("Disclaimer")) {
    
        <# Calling disclaimer function #>
        fncDisclaimer
    
        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Disclaimer" -strLogValue "Proceeded"

    }
    
    <# Action if the parameter '-Help' has been selected #>
    If ($PSBoundParameters.ContainsKey("Help")) {

        <# Calling disclaimer function #>
        fncHelp

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Help" -strLogValue "Proceeded"

    }

    <# Action if the parameter '-Reset' has been selected #>
    If ($PSBoundParameters.ContainsKey("Reset")) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Parameter Reset" -strLogValue "Triggered"

        <# Calling reset function #>
        fncReset

    }

    <# Action if the parameter '-SilentReset' has been selected #>
    If ($PSBoundParameters.ContainsKey("SilentReset")) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Parameter SilentReset" -strLogValue "Triggered"

        <# Calling silent reset function #>
        fncSilentReset

    }
    
    <# Action if the parameter '-UserLogging' has been selected #>
    If ($PSBoundParameters.ContainsKey("UserLogging")) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Parameter UserLogging" -strLogValue "Triggered"

        <# Calling user logging function #>
        fncUserLogging

    }

    <# Action if the parameter '-AdminLogging' has been selected #>
    If ($PSBoundParameters.ContainsKey("AdminLogging")) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Parameter AdminLogging" -strLogValue "Triggered"

        <# Calling admin logging function #>
        fncAdminLogging

    }

    <# Action if the parameter '-CompressLogs' has been selected #>
    If ($PSBoundParameters.ContainsKey("CompressLogs")) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Parameter CompressLogs" -strLogValue "Triggered"

        <# Calling function to compress all logs into zip file #>
        fncCompressLogs

        <# Exit function #>
        Break

    }

    <# Action if the parameter '-Menu' has been selected; default without any parameter #>
    If ($PsCmdlet.ParameterSetName -eq "Menu") {

        <# Calling function to show menu #>
        fncShowMenu

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Menu" -strLogValue "Proceeded"

    }

    <# Action if the parameter '-Version' has been selected #>
    If ($PSBoundParameters.ContainsKey("Version")) {

        <# Calling function to display version information #>
        fncShowVersion

        <# Verbose/Logging #>
        fncLogging -strLogFunction "RMS_Support_Tool" -strLogDescription "Version" -strLogValue "Proceeded"

    }

}

<# Function that creates some default log enties #>
Function fncCreateDefaultLogEntries {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Script module version" -strLogValue $Global:strScriptVersion <# Script module version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Windows edition" -strLogValue $Global:strWindowsEdition <# Windows edition #>
    
    <# Verbose/Logging: Windows version #>
    If ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -Name ReleaseID -ErrorAction SilentlyContinue).ReleaseId) {

        <# Windows version and release ID #>
        fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Windows version" -strLogValue $([System.Environment]::OSVersion.Version) ($((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -Name ReleaseID).ReleaseId))

    }
    Else {

        <# Windows version #>
        fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Windows version" -strLogValue $([System.Environment]::OSVersion.Version)

    }
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Windows architecture" -strLogValue $((Get-CimInstance Win32_OperatingSystem -Verbose:$false).OSArchitecture) <# Windows architecture #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Username" -strLogValue $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) <# Username #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "Machine name" -strLogValue $([System.Environment]::MachineName) <# Machine name #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell host" -strLogValue $($Host.Name.ToString()) <# PowerShell host #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell version" -strLogValue $($Host.Version.ToString()) <# PowerShell version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell edition" -strLogValue $($PSVersionTable.PSEdition.ToString()) <# PowerShell edition #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell build version" -strLogValue $($PSVersionTable.BuildVersion) <# PowerShell build version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell current culture" -strLogValue $($Host.CurrentCulture.ToString()) <# PowerShell current culture #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell current UI culture" -strLogValue $($Host.CurrentUICulture.ToString()) <# PowerShell current UI culture #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell CLR version" -strLogValue $($PSVersionTable.CLRVersion.ToString()) <# PowerShell CRL version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell WSManStack version" -strLogValue $($PSVersionTable.WSManStackVersion.ToString()) <# PowerShell WSManStack version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell PSRemotingProtocol version" -strLogValue $($PSVersionTable.PSRemotingProtocolVersion.ToString()) <# PowerShell PSRemotingProtocol version #>
    fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "PowerShell Serialization version" -strLogValue $($PSVersionTable.SerializationVersion.ToString()) <# PowerShell Serialization version #>

    <# Verbose/Logging: AIP client version #>
    If (Get-Module -ListAvailable -Name AzureInformationProtection -Verbose:$false) {

        <# Logging: If AIP client is installed #>
        fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "AIP client version" -strLogValue $((Get-Module -ListAvailable -Name AzureInformationProtection -Verbose:$false).Version)

    }
    Else {

        <# Logging: If AIP client is not installed #>
        fncLogging -strLogFunction "fncCreateDefaultLogEntries" -strLogDescription "AIP client installed" -strLogValue $false

    }

}

<# Function for evaluating the used Windows version, and exit function, if an unsupported Windows version is found #>
Function fncCheckWindowsVersion {

    <# Checking for supported OS versions #>
    If (-Not $Global:strWindowsEdition -Match "Windows 8" -Or
        -Not $Global:strWindowsEdition -Match "Windows 10" -Or
        -Not $Global:strWindowsEdition -Match "2012" -Or
        -Not $Global:strWindowsEdition -Match "Server 2016" -Or
        -Not $Global:strWindowsEdition -Match "Server 2019") {

        <# Clear global variables #>
        $Global:strWindowsEdition = $null

        <# Console output #>
        Write-Output (Write-Host "ATTENTION:`n`nRMS_Support_Tool does not support the operating system you're using.`n`nPlease ensure to use a supported operating system. The RMS_Support_Tool supports the following operating systems:`nMicrosoft Windows 8, Windows 8.1, Windows 10, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016 and Windows Server 2019.`n" -ForegroundColor Red)

        <# Signal sound #>
        [console]::beep(500,200)

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCheckWindowsVersion" -strLogDescription "Unsupported operating system" -strLogValue $true

        <# Exit function #>
        Break

    }

}

<# Function responsable to check for updates and installing new versions #>
Function fncCheckForUpdate { <# Check for latest version of the script module #>

    <# Filling variable with trimmed local version information #>
    $Private:strLocalScriptVersion = ($Global:strScriptVersion.Replace(".", $null)).Substring(0,3)

    <# Action, if Update.dat can be found in local script module folder #>
    If ($(Test-Path $Private:PSScriptRoot"\Update.dat") -Eq $true) {

        <# Read update version from local Update.dat #>
        $Private:strReadUpdateFile = Get-Content $Private:PSScriptRoot"\Update.dat"
        $Private:strConvertedUpdateFile = ConvertTo-SecureString $Private:strReadUpdateFile
        $Private:strEncryptedUpdateFile = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Private:strConvertedUpdateFile)
        $Private:strOnlineScriptVersion = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($Private:strEncryptedUpdateFile)

        <# Comparing local version vs. latest version #>
        If ($($Private:strLocalScriptVersion) -Eq $Private:strOnlineScriptVersion.Replace(".", $null).Substring(0,3)) {

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Latest"

        }
        Else {

            <# Console output #>
            Write-Output (Write-Host "ATTENTION:`n`nYou're using an outdated version of the RMS_Support_Tool!`nPlease download the latest version of the RMS_Support_Tool: $Private:strOnlineScriptVersion`n`nNote:`n`n- If you’re working in an environment that does not have internet access, you must download the file manually.`n- You must place the file to the location where you have stored the RMS_Support_Tool files.`n- Please download the file from the following hyperlink (from a machine where you have internet access):`n https://aka.ms/RMS_Support_Tool/Latest`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Outdated"

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Temp file removed"
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Exit script module" -strLogValue $true

            <# Releasing private varibles #>
            $Private:strLocalScriptVersion = $null

            <# Releasing global varible #>
            $Global:strWindowsEdition = $null

            <# Exit function #>
            Break

        }

    }

    <# Action, if Update.dat can not be found in local script module folder #>
    If ($(Test-Path $Private:PSScriptRoot"\Update.dat") -Eq $false) {

        If ($(fncTestInternetAccess "github.com") -Eq $true) { <# Checking, internet connection is available #>

            <# Download/cache Update.dat from URL for version check #>
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
            Invoke-WebRequest -Uri "https://aka.ms/RMS_Support_Tool/Update" -OutFile $Private:PSScriptRoot"\Update.dat"

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Update" -strLogValue "Initailized"

            <# Read update version from local Update.dat #>
            $Private:strReadUpdateFile = Get-Content $Private:PSScriptRoot"\Update.dat"
            $Private:strConvertedUpdateFile = ConvertTo-SecureString $Private:strReadUpdateFile
            $Private:strEncryptedUpdateFile = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Private:strConvertedUpdateFile)
            $Private:strOnlineScriptVersion = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($Private:strEncryptedUpdateFile)

            <# Comparing local version vs. latest version #>
            If ($($Private:strLocalScriptVersion) -Eq $Private:strOnlineScriptVersion.Replace(".", $null).Substring(0,3)) {

                <# Verbose/Logging #>
                fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Latest"

            }
            Else {

                <# Console output #>
                Write-Output "A new version of the RMS_Support_Tool is available."
                Write-Output "Updating RMS_Support_Tool, please wait..."

                <# Internet availalbe: Download script module files from URL #>
                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
                Invoke-WebRequest -Uri "https://aka.ms/RMS_Support_Tool/Module" -OutFile "$Private:PSScriptRoot\RMS_Support_Tool.psm1"
                Invoke-WebRequest -Uri "https://aka.ms/RMS_Support_Tool/Manifest" -OutFile "$Private:PSScriptRoot\RMS_Support_Tool.psd1"
                Invoke-WebRequest -Uri "https://aka.ms/RMS_Support_Tool/Help" -OutFile "$Private:PSScriptRoot\RMS_Support_Tool.htm"

                <# Verbose/Logging #>
                fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Latest downloaded"

                <# Internet not availalbe: Console outpus #>
                Write-Output (Write-Host "ATTENTION:`n`nA new version of the RMS_Support_Tool has been downloaded: $Private:strOnlineScriptVersion`nThe RMS_Support_Tool is now terminated.`n`nPlease restart the RMS_Support_Tool.`n" -ForegroundColor Red)

                <# Signal sound #>
                [console]::beep(500,200)

                <# Verbose/Logging #>
                fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Update" -strLogValue "Finished"

                <# Removing local update file #>
                Remove-Item $Private:PSScriptRoot"\Update.dat" -Force -ErrorAction SilentlyContinue

                <# Verbose/Logging #>
                fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Temp file removed"

                <# Releasing private varibles #>
                $Private:strLocalScriptVersion = $null

                <# Releasing global varible #>
                $Global:strWindowsEdition = $null

                <# Exit function #>
                Break

            }

        }
        Else { <# Action, if web site is not unavailable or if there's no internet connection #>

            <# Console output #>
            Write-Output (Write-Host "ATTENTION:`n`nUpdating the RMS_Support_Tool could not be performed.`nEither the website cannot be reached or there is no internet connection.`n`nYou are using version: $Global:strScriptVersion.`n`nPlease check on the following website if you are using the latest version of the RMS_Support_Tool, and update if necessary:`nhttps://aka.ms/RMS_Support_Tool/Latest`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Update" -strLogValue "No internet connection"

            <# Console output with pause #>
            fncPause

        }

    }

    <# Removing downloaded file #>
    Remove-Item $Private:PSScriptRoot"\Update.dat" -Force -ErrorAction SilentlyContinue

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCheckForUpdate" -strLogDescription "Script module version" -strLogValue "Temp file removed"

    <# Releasing private varibles #>
    $Private:strLocalScriptVersion = $null

}

<# Function that creates single log entries for log file and verbose output #>
Function fncLogging ($strLogFunction, $strLogDescription, $strLogValue) {

    <# Checking if path exist and create it if not #>
    If ($(Test-Path -Path $Global:strUserLogPath) -Eq $false) {

        New-Item -ItemType Directory -Force -Path $Global:strUserLogPath | Out-Null <# Defining default user log path #>

    }

    <# Verbose output #>
    Write-Verbose "$(Get-Date -UFormat "%Y-%m-%d"), $(Get-Date -Format T), $strLogFunction, $strLogDescription, $strLogValue"

    <# Write (append) verbose output to log file #>
    Write-Verbose "$(Get-Date -UFormat "%Y-%m-%d"), $(Get-Date -Format T), $strLogFunction, $strLogDescription, $strLogValue" -ErrorAction SilentlyContinue -Verbose 4>> $Global:strUserLogPath"\Script.log" 

}

<# Function to show information #>
Function fncInformation {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncInformation" -strLogDescription "Information" -strLogValue "Called"

    <# Action, if function was called from command-line #>
    If ($Global:bolCommingFromMenu -eq $false) {

        <# Call Information #>
        Get-Help -Verbose:$false RMS_Support_Tool

    }

    <# Action, if function was called from the menu #>
    If ($Global:bolCommingFromMenu -eq $true) {
    
        <# Console output #>
        Write-Output "NAME:`nRMS_Support_Tool`n`nDESCRIPTION:`nThe RMS_Support_Tool provides the functionality to reset all Microsoft AIP/AD RMS services. Its main purpose is to delete the currently downloaded policies and reset the user settings for AIP/AD RMS service, and it can also be used to collect data for troubleshooting.`n`nVERSION:`n$Global:strScriptVersion`n`nAUTHOR:`nClaus Schiroky`nCustomer Service & Support EMEA`nMicrosoft Deutschland GmbH`n`nHOMEPAGE:`nhttps://aka.ms/RMS_Support_Tool`n`nPRIVACY STATEMENT:`nhttps://privacy.microsoft.com/PrivacyStatement`n`nCOPYRIGHT:`nCopyright (c) 2020 Microsoft (c). All rights reserved.`n"

    }

}

<# Function to show disclaimer #>
Function fncDisclaimer {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisclaimer" -strLogDescription "Disclaimer" -strLogValue "Called"

    <# Console output #>
    Write-Output (Write-Host "ATTENTION:`n`nDISCLAIMER OF WARRANTY: THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PLEASE DO UNDERSTAND THAT THERE IS NO GUARANTEE THAT THIS SOFTWARE WILL RUN WITH ANY GIVEN ENVIRONMENT OR CONFIGURATION. BY INSTALLING AND USING THE SOFTWARE YOU ACCEPT THIS DISCLAIMER OF WARRANTY. IF YOU DO NOT ACCEPT THE TERMS, DO NOT INSTALL OR USE THIS SOFTWARE.`n`nNote:`n`n- Please only run RMS_Support_Tool if you have been prompted to do so by a Microsoft support technician.`n- It is recommended to test the RMS_Support_Tool with a test environment before executing it in a live environment.`n- Do not modify any component of the RMS_Support_Tool in any kind, as this will result in incorrect information in the analysis of your environment.`n- There is no support for the RMS_Support_Tool.`n- Before using the RMS_Support_Tool, please ensure to read its manual:`n https://aka.ms/RMS_Support_Tool`n" -ForegroundColor Red)

}

<# Function to show help file #>
Function fncHelp {

    <# Action, if help file can be found in script module folder #>
    If ($(Test-Path $Private:PSScriptRoot"\RMS_Support_Tool.htm") -Eq $true) {

        <# Open help file #>
        Invoke-Item $Private:PSScriptRoot"\RMS_Support_Tool.htm"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncHelp" -strLogDescription "Help" -strLogValue "Called"

    }

    <# Action, if help file can't be found in script module folder #>
    If ($(Test-Path $Private:PSScriptRoot"\RMS_Support_Tool.htm") -Eq $false) {

        <# Checking, internet connection is available #>
        If ($(fncTestInternetAccess "github.com") -Eq $true) {

            <# Call online help; Set by HelpURI in CmdletBinding #>
            Get-Help -Verbose:$false RMS_Support_Tool -Online        

            <# Internet availalbe: Download helpfile from URL #>
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
            Invoke-WebRequest -Uri "https://aka.ms/RMS_Support_Tool/Help" -OutFile "$Private:PSScriptRoot\RMS_Support_Tool.htm"

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncHelp" -strLogDescription "Help" -strLogValue "Downloaded"
            fncLogging -strLogFunction "fncHelp" -strLogDescription "Help" -strLogValue "Called"

        }
        Else { <# Action, if web site is not unavailable or if there's no internet connection #>

            <# Console output #>
            Write-Output (Write-Host "ATTENTION:`n`nThe help file (RMS_Support_Tool.htm) could not be downloaded.`nEither the website cannot be reached or there is no internet connection.`n`nNote:`n`n- If you’re working in an environment that does not have internet access, you must download the file manually, before proceeding the RMS_Support_Tool.`n- You must place the file to the location where you have stored the RMS_Support_Tool files.`n- Please download the file from the following hyperlink (from a machine where you have internet access):`n https://aka.ms/RMS_Support_Tool/Latest`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncHelp" -strLogDescription "Help" -strLogValue "No internet connection"

        }

    }

}

<# Function to reset all Microsoft AIP/AD RMS services #>
Function fncReset {

    <# Console output #>
    Write-Output "RESET:`nResetting AIP/AD RMS services, please wait..."

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncReset" -strLogDescription "Reset client" -strLogValue "Initiated"

    <# If "registry overrides" exist, create a backup copy #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\MSIPC\ServiceLocation") -Eq $true) {

        <# Backup registry settings to a reg file #>
        REG EXPORT "HKLM\SOFTWARE\Microsoft\MSIPC\ServiceLocation" $Private:PSScriptRoot\Logs\ServiceLocationBackup.reg /Y | Out-Null

        <# Console output #>
        Write-Output "Your ServiceLocation registry settings were stored to"$Private:PSScriptRoot\Logs\ServiceLocationBackup.reg

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncReset" -strLogDescription "Export ServiceLocation backup" -strLogValue "ServiceLocationBackup.reg"

    }

    <# Deleting client registry keys #>
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\MSIPC"
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\AIPMigration"
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Microsoft.IPViewerChildMenu"
    fncDeleteItem "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Microsoft\MSIPC"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Wow6432Node\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Wow6432Node\Microsoft\MSDRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\Office"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Wow6432Node\Microsoft\Office"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\XPSViewer\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\MSIP"
    fncDeleteItem "HKLM:\SOFTWARE\WOW6432Node\Microsoft\MSIP"
    fncDeleteItem "HKCR:\AllFilesystemObjects\shell\Microsoft.Azip.Inspect"
    fncDeleteItem "HKCR:\AllFilesystemObjects\shell\Microsoft.Azip.RightClick"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL"

    <# Deleting/cleaning client folders in file system #>
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\MSIP
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\MSIPC
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\DRM

    <# Checking for Office 2013, and enable modern authentication if installed #>
    If ($(fncCheckForOffice2013) -Eq $true) { 

        <# Check for Office 2013 registry key #>
        If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0") -Eq $true) {
    
            <# Create registry key (overwrite) #>
            New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -ErrorAction SilentlyContinue | Out-Null
    
            <# Implement registry settings to enable modern authentication for Office 2013 #>
            New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -Name "EnableADAL" -Value 1 -PropertyType DWord -ErrorAction SilentlyContinue | Out-Null
            New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -Name "Version" -Value 1 -PropertyType DWord -ErrorAction SilentlyContinue | Out-Null
    
            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncReset" -strLogDescription "ADAL for Office 2013" -strLogValue "Enabled"

            <# Console output #>
            Write-Output "Office 2013 found: Modern authentication (ADAL) enabled"

        }

    }
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncReset" -strLogDescription "Reset client" -strLogValue "Proceeded"

    <# Console output #>
    Write-Output (Write-Host "RESET: Proceeded`n" -ForegroundColor Green)
    
    <# Signal sound #>
    [console]::beep(1000,200)

}

<# Function to silent reset all Microsoft AIP/AD RMS services #>
Function fncSilentReset {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncSilentReset" -strLogDescription "SilentReset client" -strLogValue "Initiated"

    <# If "registry overrides" exist, create a backup copy #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\MSIPC\ServiceLocation") -Eq $true) {

        <# Backup registry settings to a reg file #>
        REG EXPORT "HKLM\SOFTWARE\Microsoft\MSIPC\ServiceLocation" $Private:PSScriptRoot\Logs\ServiceLocationBackup.reg /Y | Out-Null

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncSilentReset" -strLogDescription "Export ServiceLocation backup" -strLogValue "ServiceLocationBackup.reg"

    }

    <# Deleting client registry keys #>
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\MSIPC"
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\AIPMigration"
    fncDeleteItem "HKCU:\SOFTWARE\Classes\Microsoft.IPViewerChildMenu"
    fncDeleteItem "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Microsoft\MSIPC"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Wow6432Node\Microsoft\MSIPC"
    fncDeleteItem "HKLM:\SOFTWARE\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Microsoft\MSDRM"
    fncDeleteItem "HKLM:\SOFTWARE\Policies\Wow6432Node\Microsoft\MSDRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\Office"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Wow6432Node\Microsoft\Office"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\XPSViewer\Common\DRM"
    fncDeleteItem "HKCU:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\MSIP"
    fncDeleteItem "HKLM:\SOFTWARE\WOW6432Node\Microsoft\MSIP"
    fncDeleteItem "HKCR:\AllFilesystemObjects\shell\Microsoft.Azip.Inspect"
    fncDeleteItem "HKCR:\AllFilesystemObjects\shell\Microsoft.Azip.RightClick"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL"

    <# Deleting/cleaning client folders in file system #>
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\MSIP
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\MSIPC
    fncDeleteItem $env:LOCALAPPDATA\Microsoft\DRM

    <# Checking for Office 2013, and enable modern authentication if installed #>
    If ($(fncCheckForOffice2013) -Eq $true) { 

        <# Check for Office 2013 registry key #>
        If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0") -Eq $true) {
    
            <# Create registry key (overwrite) #>
            New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -ErrorAction SilentlyContinue | Out-Null
    
            <# Implement registry settings to enable modern authentication for Office 2013 #>
            New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -Name "EnableADAL" -Value 1 -PropertyType DWord -ErrorAction SilentlyContinue | Out-Null
            New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity" -Name "Version" -Value 1 -PropertyType DWord -ErrorAction SilentlyContinue | Out-Null
    
            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncSilentReset" -strLogDescription "ADAL for Office 2013" -strLogValue "Enabled"

        }

    }
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncSilentReset" -strLogDescription "SilentReset client" -strLogValue "Proceeded"
    
    <# Signal sound #>
    [console]::beep(1000,200)

}

<# Function to check, if Office 2013 is installed; used to enable ADAL at reset #>
Function fncCheckForOffice2013 {

    <# Looping through uninstall registry key to find any Office application #>
    Get-ChildItem -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" -Name | ForEach-Object {

        <# Checking for Office applications/GUIDs #>
        If ($_.ToString() -like "*0000000FF1CE}") {

            <# Checking for major version '15' = Office 2013 #>
            If (Get-ItemProperty $_.PSPath | Where-Object {$_.VersionMajor -eq "15"}) {

                <# Returning 'true', if an Office 2013 applictation was found #>
                Return $true
                
                <# Leaving ForEach loop #>
                Break

            }
            Else {

                <# Returning 'false', if no Office 2013 applictation was found #>
                Return $false
                
                <# Leaving ForEach loop #>
                Break

            }

        }

    }

}

<# Function to delete item/s or folders (with IO error handling); used in fncReset, and fncDisableLogging #>
Function fncDeleteItem ($Private:objItem) {

    Try {

        <# Checking if key, file or folder exist and proceed with related actions #>
        If ($(Test-Path -Path $Private:objItem) -Eq $true) {

            <# Deleting folder or registry key #>
            Remove-Item -Path $Private:objItem -Recurse -Force -ErrorAction Stop | Out-Null
           
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncDeleteItem" -strLogDescription "Item deleted" -strLogValue $Private:objItem

        }

    }
    Catch [System.IO.IOException] { <# Actions, if files or folders cannot be accessed, because they are locked/used by another process <#>

        <# Console output #>
        Write-Output (Write-Host "WARNING: Some items or folders are still used by another process.`nIMPORTANT: Close all applications that run or use Microsoft Office or AIP/AD RMS and try again." -ForegroundColor Red)

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncDeleteItem" -strLogDescription "Item locked" -strLogValue $Private:objItem
        fncLogging -strLogFunction "fncDeleteItem" -strLogDescription "Reset" -strLogValue "ERROR: Reset failed"

        <# Releasing private variable #>
        $Private:objItem = $null

        <# Action, if function was not called from the menu #>
        If ($Global:bolCommingFromMenu -eq $false) {

            <# Console output #>
            Write-Output (Write-Host "RESET: Failed!`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Interrupting Reset #>
            Break

        }
        <# Action, if function was called from the menu #>
        If ($Global:bolCommingFromMenu -eq $true) {

            <# Console output #>
            Write-Output (Write-Host "RESET: Failed!`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Console output with pause #>
            fncPause

            <# Calling menu #>
            fncShowMenu

        }

    }

    $Private:objItem = $null <# Releasing private variable #>

}

<# Function to copy item/s (with error handler); used in fncCollectLogging #>
Function fncCopyItem ($Private:objItem, $Private:strDestination, $Private:strFileName) {

    Try {

        <# Checking if path exist and proceed with file copy #>
        If ($(Test-Path -Path $Private:objItem) -Eq $true) {

            <# Copy item/s #>
            Copy-Item -Path $Private:objItem -Destination $Private:strDestination -Recurse -Force -ErrorAction Stop | Out-Null
            
            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncCopyItem" -strLogDescription "Item copied" -strLogValue $Private:strFileName

        }

    }
    Catch [System.IO.IOException] { <# Action, if file cannot be accessed, because it's locked/used by another process <#>

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCopyItem" -strLogDescription "Item locked" -strLogValue "ERROR: "$Private:objItem

        <# Releasing private variable #>
        $Private:objItem = $null
        $Private:strDestination = $null

    }

    <# Releasing private variable #>
    $Private:objItem = $null
    $Private:strDestination = $null

}

<# Function for evaluating internet access; used in fncCheckForUpdate #>
Function fncTestInternetAccess ($Private:strURL) {

    <# Checking, if internet access is available #>
    If ($(Test-Connection $Private:strURL -Count 1 -Quiet) -Eq $true) {

        <# Return true, if we have internet access #>
        Return $true
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncTestInternetAccess" -strLogDescription "Internet access" -strLogValue $true

    }
    Else {

        <# Return false, if we do not have internet access #>
        Return $false
       
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncTestInternetAccess" -strLogDescription "Internet access" -strLogValue $false

    }

    <# Releasing private variable #>
    $Private:strURL = $null

}

<# Function to collect user traces #>
Function fncUserLogging {
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncUserLogging" -strLogDescription "User logging" -strLogValue "Initiated"

    <# Console output #>
    Write-Output "USER LOGGING:"
    Write-Output (Write-Host "ATTENTION: Before you proceed with this option, close all applications that run or use Microsoft Office or AIP/AD RMS!" -ForegroundColor Red)
    Read-Host "Only if the above is true, please press any key to continue"
    Write-Output "Initializing user logging, please wait..."

    <# Variables for unique log folder #>    
    $Private:strUniqueFolderName = (Get-Date -Verbose:$false -UFormat "%y%m%d-%H%M%S")
    $Global:strUniqueLogFolder = $Global:strUserLogPath.ToString() + "\" +  $Private:strUniqueFolderName.ToString()

    <# Create unique log folder #>
    New-Item -ItemType Directory -Force -Path $Global:strUniqueLogFolder | Out-Null
   
    <# Verbose/Logging #>
    fncLogging "fncUserLogging" -strLogDescription "New log folder created" -strLogValue $Private:strUniqueFolderName

    <# Calling function to enable logging #>
    fncEnableLogging

    <# Console output #>
    Write-Output "User logging enabled."
    Write-Output (Write-Host "IMPORTANT: Now start reproducing your problem! But leave this window open!" -ForegroundColor Red)
    Read-Host "After reproducing the problem, close all applications you have used for, then come back here and press any key to continue"

    <# Console output #>
    Write-Output "Collecting logs, please wait..."

    <# Calling function to collect log files #>
    fncCollectLogging
    
    <# Function to disable/rool back logging settings #>
    fncDisableLogging

    <# Releasing variable to to able to use again on n #>
    $Global:strUniqueLogFolder = $null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncUserLogging" -strLogDescription "User logging" -strLogValue "Proceeded" 

    <# Console output #>
    Write-Output (Write-Host "USER LOGGING: Proceeded.`n" -ForegroundColor Green)

    <# Signal sound #>
    [console]::beep(1000,200)

}

<# Function to initialize/enable logging #>
Function fncEnableLogging {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "User logging" -strLogValue "Triggered"

    <# Progress bar #>
    Write-Progress -Activity " Enable logging..." -PercentComplete 0
    Write-Progress -Activity " Enable logging: Office logging..." -PercentComplete (100/11 * 1)

    <# Enable Office logging for 2013 (15.o), 2016 (16.o) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging") -Eq $false) { <# Check for registry key 'Logging' (2016) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging" -Force | Out-Null

    }

    <# Check for registry key 'Logging' (2013) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging") -Eq $false) { <# Check for registry key 'Logging' (2013) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging" -Force | Out-Null

    }

    <# Check for registry key 'Logging' (2016 x64) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging") -Eq $false) { <# Check for registry key 'Logging' (2016 x64) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging" -Force | Out-Null

    }

    <# Check for registry key 'Logging' (2013 x64) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging") -Eq $false) { <# Check for registry key 'Logging' (2013 x64) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging" -Force | Out-Null

    }

    <# Implementing registry settings to enable logging for the different Office versions #>
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging" -Name "EnableLogging" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging" -Name "MsoEtwTracingEnabled" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging" -Name "EnableLogging" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging" -Name "MsoEtwTracingEnabled" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging" -Name "EnableLogging" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging" -Name "MsoEtwTracingEnabled" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging" -Name "EnableLogging" -Value 1 -PropertyType DWord -Force | Out-Null
    New-ItemProperty -Path "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging" -Name "MsoEtwTracingEnabled" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "Office Logging" -strLogValue "Enabled"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Office TCOTrace logging..." -PercentComplete (100/11 * 2)

    <# Cleaning Office TCOTrace logs #>
    If ($(Test-Path $env:LOCALAPPDATA\Microsoft\Office\MsoLogs) -Eq $true) {

        <# Cleaning log file folder #>
        Remove-Item $env:LOCALAPPDATA\Microsoft\Office\MsoLogs -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "Cleaning Office logs" -strLogValue "Proceeded"

    }

    <# Enable Office TCOTrace logging for 2010 (14.0), 2013 (15.o), 2016 (16.o) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Debug") -Eq $false) { <# Check for registry key 'Debug' (2016) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Debug" -Force | Out-Null

    }
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Debug" -Name "TCOTrace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Check for registry key 'Debug' (2013) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Debug") -Eq $false) { <# Check for registry key 'Debug' (2013) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Debug" -Force | Out-Null

    }
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Debug" -Name "TCOTrace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Check for registry key 'Debug' (2010) #>
    If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\Debug") -Eq $false) { <# Check for registry key 'Debug' (2010) #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\Debug" -Force | Out-Null

    }
    New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\Debug" -Name "TCOTrace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "Office TCOTrace" -strLogValue "Enabled"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Cleaning MSIP/MSIPC/MIP logs..." -PercentComplete (100/11 * 3)

    <# Cleaning MSIP/MSIPC/AIP v2 logs folder content #>
    If ($(Test-Path -Path $env:LOCALAPPDATA\Microsoft\MSIP\Logs) -Eq $true) { <# If foler exist #>

        <# Cleaning MSIP/AIP v1/2 log folder content #>
        Remove-Item -Path $env:LOCALAPPDATA\Microsoft\MSIP\Logs -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIP log folder" -strLogValue "Cleared"

    }

    <# If foler exist #>
    If ($(Test-Path -Path $env:LOCALAPPDATA\Microsoft\MSIPC\Logs) -Eq $true) {

        <# Cleaning MSIPC log folder content #>
        Remove-Item -Path $env:LOCALAPPDATA\Microsoft\MSIPC\Logs -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC log folder" -strLogValue "Cleared"

    }

    <# If foler exist #>
    If ($(Test-Path -Path $env:LOCALAPPDATA\Microsoft\MSIP\mip) -Eq $true) {

        <# Cleaning MIP SDK/AIP v2 log folder content #>
        Remove-Item -Path $env:LOCALAPPDATA\Microsoft\MSIP\mip -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MIP log folder" -strLogValue "Cleared"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: CAPI2 event logging..." -PercentComplete (100/11 * 4)

    <# Enable CAPI2 event log #>
    Echo Y | wevtutil set-log Microsoft-Windows-CAPI2/Operational /enabled:True
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "CAPI2 event log" -strLogValue "Enabled"

    <# Clear CAPI2 event log #>
    wevtutil.exe clear-log Microsoft-Windows-CAPI2/Operational
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "CAPI2 event log" -strLogValue "Cleared"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Flushing DNS..." -PercentComplete (100/11 * 5)

    <# Flush DNS #>
    ipconfig.exe /flushdns | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "Flush DNS" -strLogValue "Called"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Starting network trace..." -PercentComplete (100/11 * 6)

    <# Start network trace #>
    netsh.exe trace start capture=yes scenario=NetConnection,InternetClient sessionname="RMS_Support_Tool-Trace" report=disabled maxsize=1024, tracefile=$Global:strUniqueLogFolder"\NetMon.etl" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "Network trace" -strLogValue "Started"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Starting PSR..." -PercentComplete (100/11 * 7)

    <# Start PSR #>
    psr.exe /gui 0 /start /output $Global:strUniqueLogFolder"\ProblemSteps.zip"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "PSR" -strLogValue "Started"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: MSIPC/MSDRM logging..." -PercentComplete (100/11 * 8)

    <# Enable RMS-MSIPC event log #>
    If ([System.Diagnostics.EventLog]::Exists('Microsoft-RMS-MSIPC/Debug') -Eq $true) { <# Actions when RMS-MSIPC event log exist #>

        <# Ensure to have Microsoft-RMS-MSIPC/Debug event log enabled #>
        Echo Y | wevtutil set-log "Microsoft-RMS-MSIPC/Debug" /enabled:true /retention:false /maxsize:153600
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "Microsoft-RMS-MSIPC/Debug logging" -strLogValue "Enabled"

    }

    <# Enable MSIPC/MSDRM logging (DbgView) #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\MSIPC") -Eq $false) { <# Check for registry key #>

        <# Create registry key, if does not exist #>
        New-Item -Path "HKLM:\SOFTWARE\Microsoft\MSIPC" -Force | Out-Null

    }
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSIPC" -Name "Trace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Check for registry key #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\MSDRM") -Eq $false) {

        <# Create registry key, if does not exist #>
        New-Item -Path "HKLM:\SOFTWARE\Microsoft\MSDRM" -Force | Out-Null

    }
    New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSDRM" -Name "Trace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Check for registry key #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC") -Eq $false) {

        <# Create registry key, if does not exist #>
        New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC" -Force | Out-Null

    }
    New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC" -Name "Trace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Check for registry key #>
    If ($(Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM") -Eq $false) {

        <# Create registry key, if does not exist #>
        New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM" -Force | Out-Null

    }
    New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM" -Name "Trace" -Value 1 -PropertyType DWord -Force | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC/MSDRM logging" -strLogValue "Enabled"

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: MSOIdentityCRL logging..." -PercentComplete (100/11 * 9)

    <# Enabling and activating MSOIdentityCRL (MSOIDSVC = Microsoft Online Services Sign-in Assistant) trace if service exist #>
    If (Get-Service "MSOIDSVC" -ErrorAction SilentlyContinue) { <# Checking if service exist #>

        <# Checking for Trace keys in registry and create keys if they do not exist #>
        If ($(Test-Path -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace") -Eq $false) { <# Check for registry key #>

            <# Create registry key #>
            New-Item -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Force | Out-Null

        }

        <# Check for registry key #>
        If ($(Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace") -Eq $false) {

            <# Create registry key #>
            New-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Force | Out-Null

        }

        <# Check for registry key #>
        If ($(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace") -Eq $false) {

            <# Create registry key #>
            New-Item -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Force | Out-Null

        }

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSOIdentityCRL default registry keys" -strLogValue "Created"

        <# Checking if servcie is running and acting accordingly #>
        If ((Get-Service "MSOIDSVC").Status -Eq "Running") { <# Action, if service is running #>

            <# Stop service #>
            Stop-Service -Name "MSOIDSVC"
            
            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncLogging" -strLogDescription "MSOIdentityCRL service" -strLogValue "Stopped"

        }

        <# Create trace registry keys/settings #>
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "Folder" -Value $Global:strUniqueLogFolder"\MSOTrace" -PropertyType String -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "Flags" -Value "1" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "level" -Value "99" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "maxsize" -Value "10485760" -PropertyType DWord -Force | Out-Null

        New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Name "Folder" -Value $Global:strUniqueLogFolder"\MSOTrace" -PropertyType String -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Name "Flags" -Value "1" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Name "level" -Value "99" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Name "maxsize" -Value "10485760" -PropertyType DWord -Force | Out-Null

        New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "Folder" -Value $Global:strUniqueLogFolder"\MSOTraceLite" -PropertyType String -Force | Out-Null
        New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "Flags" -Value "1" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "level" -Value "99" -PropertyType DWord -Force | Out-Null
        New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Name "maxsize" -Value "10485760" -PropertyType DWord -Force | Out-Null

        <# Start service #>
        Start-Service -Name "MSOIDSVC"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSOIdentityCRL service" -strLogValue "Started"

    }
    Else { <# Action, if service is not available #>

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSOIdentityCRL service" -strLogValue "Not found"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Enable logging: Starting MSIPC/MSDRM logging..." -PercentComplete (100/11 * 10)

    <# Starting MSIPC/MSDRM logging (DbgView) #>
    If ($(Test-Path $Private:PSScriptRoot"\DebugView\Dbgview.exe") -Eq $true) { <# Action, if DebugView.exe can be found in script module folder #>

        <# Start executable #>
        Start-Process $Private:PSScriptRoot"\DebugView\Dbgview.exe" -ArgumentList "/g", "/t", "/l", "`"$Global:strUniqueLogFolder\MSIPC-MSDRM-DebugView.log"`
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC/MSDRM logging: DebugView" -strLogValue "Started"

    }

    <# Action, if DebugView.exe can't be found in script module folder #>
    If ($(Test-Path $Private:PSScriptRoot"\DebugView\Dbgview.exe") -Eq $false) {

        <# Console output #>
        Write-Output "Downloading DebugView, please wait..."

        <# Checking, internet connection is available #>
        If ($(fncTestInternetAccess "download.sysinternals.com") -Eq $true) {

            <# Download DebugView from sysinternals #>
            [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
            Invoke-WebRequest -Uri "https://download.sysinternals.com/files/DebugView.zip" -OutFile "$Private:PSScriptRoot\DebugView.zip"
            
            <# Expand archive to needed subfolder #>
            Expand-Archive -Path $Private:PSScriptRoot\DebugView.zip -DestinationPath "$Private:PSScriptRoot\DebugView" -Force
            
            <# Remove downloaded file #>
            Remove-Item $Private:PSScriptRoot\DebugView.zip -Recurse -Force | Out-Null

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC/MSDRM logging: DebugView" -strLogValue "Downloaded"

            <# Open executable file #>
            Start-Process $Private:PSScriptRoot"\DebugView\Dbgview.exe" -ArgumentList "/g", "/t", "/l", "`"$Global:strUniqueLogFolder\MSIPC-MSDRM-DebugView.log"`
            
            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC/MSDRM logging: DebugView" -strLogValue "Started"

        }
        Else { <# Action, if web site is not unavailable or if there's no internet connection #>

            <# Console output #>
            Write-Output (Write-Host "ATTENTION:`n`nThe tool 'DebugView' could not be downloaded.`nEither the website cannot be reached or there is no internet connection.`n`nIMPORTANT: If you’re working in an environment that does not have internet access, you must download the file manually, before proceeding the RMS_Support_Tool.`n`nThe file must be uncompressed into the subfolder 'DebugView' to the location where you have stored the RMS_Support_Tool files.`n`nPlease download the file from the following hyperlink (from a machine where you have internet access):`nhttps://download.sysinternals.com/files/DebugView.zip`n" -ForegroundColor Red)

            <# Signal sound #>
            [console]::beep(500,200)

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncLogging" -strLogDescription "MSIPC/MSDRM logging: DebugView" -strLogValue "No internet connection"

            <# Function to disable/rool back all logging settings #>
            fncDisableLogging

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncLogging" -strLogDescription "Logging" -strLogValue "Operation canceled"

            <# Exit function #>
            Break

        }

    }

    <# Cleaning temp folder for office.log (TCOTrace) #>
    If ($(Test-Path $Global:strTempFolder"\office.log") -Eq $true) {
    
        <# Removing file office.log #>
        Remove-Item -Path $Global:strTempFolder"\office.log" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncLogging" -strLogDescription "Office TCOTrace temp file" -strLogValue "Cleared"
    
    }

    <# Progress bar update #>
    Write-Progress -Activity " User logging enabled" -Completed

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncLogging" -strLogDescription "User logging" -strLogValue "Enabled" 

}

<# Function to disable/rool back all logging settings #>
Function fncDisableLogging {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Disable logging" -strLogValue "Triggered" 

    <# Progress bar #>
    Write-Progress -Activity " Disable logging..." -PercentComplete 0

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: Office logging..." -PercentComplete (100/9 * 1)

    <# Disable Office logging for 2013 (15.o), 2016 (16.o) #>
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging"
    fncDeleteItem "HKCU:\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\Logging"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Office Logging" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: Office TCOTrace..." -PercentComplete (100/9 * 2)

    <# Disable Office TCOTrace logging for 2010 (14.0), 2013 (15.o), 2016 (16.o) #>
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Debug"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Debug"
    fncDeleteItem "HKCU:\SOFTWARE\Microsoft\Office\14.0\Common\Debug"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Office TCOTrace" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: MSIPC/MSDRM..." -PercentComplete (100/9 * 3)

    <# Disabling MSIPC/MSDRM logging #>
    Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSIPC" -Name "Trace" -Force | Out-Null
    Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\MSDRM" -Name "Trace" -Force | Out-Null
    Remove-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSIPC" -Name "Trace" -Force | Out-Null
    Remove-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSDRM" -Name "Trace" -Force | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "MSIPC/MSDRM logging" -strLogValue "Disabled"

    <# Disable RMS-MSIPC event log #>
    If ([System.Diagnostics.EventLog]::Exists('Microsoft-RMS-MSIPC/Debug') -Eq $true) { <# Actions when RMS-MSIPC event log exist #>

        <# Enable Microsoft-RMS-MSIPC/Debug event log #>
        Echo Y | wevtutil.exe set-log "Microsoft-RMS-MSIPC/Debug" /enabled:true /retention:false /maxsize:153600 <# Set back to false #>
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Microsoft-RMS-MSIPC/Debug logging" -strLogValue "Enabled"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: CAPI2 event log..." -PercentComplete (100/9 * 4) 

    <# Disable CAPI2 event log #>
    wevtutil.exe set-log Microsoft-Windows-CAPI2/Operational /enabled:false
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "CAPI2 event log" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: Network trace..." -PercentComplete (100/9 * 5)

    <# Stopping network trace #>
    netsh.exe trace stop sessionname="RMS_Support_Tool-Trace" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Network trace" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: PSR..." -PercentComplete (100/9 * 6)

    <# Stop PSR #>
    psr.exe /stop
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "PSR" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: MSOIdentityCRL..." -PercentComplete (100/9 * 7)

    <# Disabling MSOIdentityCRL (MSOIDSVC = Microsoft Online Services Sign-in Assistant) trace if service exist #>
    If (Get-Service "MSOIDSVC" -ErrorAction SilentlyContinue) { <# Checking if service exist #>

        <# Remove trace registry key #>
        Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue
        Remove-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue
        Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue

        <# Start service #>
        Start-Service -Name "MSOIDSVC"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "MSOIdentityCRL logging" -strLogValue "Disabled"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Disable logging: MSIPC/MSDRM..." -PercentComplete (100/9 * 8)

    <# Disable MSIPC/MSDRM logging #>
    Start-Process taskkill.exe -ArgumentList "/IM", "dbgview.exe" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "MSIPC/MSDRM logging" -strLogValue "Disabled"

    <# Progress bar update #>
    Write-Progress -Activity " Logging disabled" -Completed

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncDisableLogging" -strLogDescription "Disable logging" -strLogValue "Proceeded" 

}

<# Function to finalize logging (collecting/exporting data) #>
Function fncCollectLogging {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Collecting logs" -strLogValue "Triggered" 

    <# Progress bar #>
    Write-Progress -Activity " Collecting logs..." -PercentComplete 0

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Website certificates..." -PercentComplete (100/27 * 1)

    <# Collecting website certificates for Azure RMS/AD RMS URLs #>
    If ($(Test-Path -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\MSIPC") -Eq $true) { <# Actions, if registry key exist #>

        Get-ChildItem -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\MSIPC" | ForEach-Object { <# Loop though folder #>

            <# Defining private variables #>
            $Private:strSubKeys = $_.Name.Substring(75).ToString() <# Defining variable for subkey/filename and removing registy path (75) #>
            $Private:strSubKeys = "https://$Private:strSubKeys".ToString() <# Extending variable with needed text/https #>
            $Private:strCertFileName = $_.Name.Substring(75) + ".ce_" <# Defining file name; chosen .ce_ instead of .cer #>
            $Private:strCertFile = $Global:strUniqueLogFolder + "\" + $Private:strCertFileName <# Defining path and file name #>
            $Private:strWebRequest = [System.Net.HttpWebRequest]::Create($Private:strSubKeys) <# Defining web request for subkey/URL #>

            Try {

                <# Get response/connect to website, to be able to read certificate #>
                $Private:strWebRequest.GetResponse() | Out-Null

            }
            Catch {

                <# Verbose/Logging: Ignoring 'Catch' (happen when GetResponse fails in 'Try') #>
                fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export website certificate failed" -strLogValue $Private:strSubKeys

            }

            <# Feeding variable with certificate from web request #>
            $Private:strCertificate = $Private:strWebRequest.ServicePoint.Certificate

            <# Actions, if variable/data steam is not empty #>
            If(-Not $Private:strDataStream) {

                <# Action, if certificate contain data #>
                If($Private:strCertificate) {

                    <# Feeding data steam with binary data from certificate #>
                    $Private:strDataStream = $Private:strCertificate.Export([Security.Cryptography.X509Certificates.X509ContentType]::Cert)

                    <# Writing data into .cer-file #>
                    Set-Content -Value $Private:strDataStream -Encoding Byte -Path $Private:strCertFile -Force -ErrorAction SilentlyContinue

                    <# Verbose/Logging #>
                    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export website certificate" -strLogValue $Private:strCertFileName

                }

                Else { <# Action, if certificate does't contain data/if website cannot be reached #>

                    <# Verbose/Logging #>
                    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export website certificate failed" -strLogValue $Private:strSubKeys

                }

            }

            <# Releaseing private variables for next loop #>
            $Private:strCertificate = $null
            $Private:strDataStream = $null
            $Private:strCertFile = $null
            $Private:strWebRequest = $null
            $Private:strCertFileName = $null

        }

    }
    Else { <# Actions, if registry key does not exist #>

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Key does not exist" -strLogValue "HKCU:\Software\Classes\Local Settings\Software\Microsoft\MSIPC"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: MSIPC/MSDRM log files..." -PercentComplete (100/27 * 2)

    <# Export MSIPC/MSDRM logging #>
    Start-Process taskkill.exe -ArgumentList "/IM", "dbgview.exe" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export MSIPC/MSDRM log" -strLogValue "MSIPC-MSDRM-DebugView.log"

    <# Export RMS-MSIPC event log #>
    If ([System.Diagnostics.EventLog]::Exists('Microsoft-RMS-MSIPC/Debug') -Eq $true) { <# Actions when RMS-MSIPC event log exist #>

        <# Disable Microsoft-RMS-MSIPC/Debug event log #>
        wevtutil.exe set-log "Microsoft-RMS-MSIPC/Debug" /Enabled:False
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Microsoft-RMS-MSIPC/Debug logging" -strLogValue "Disabled"

        <# Export Microsoft-RMS-MSIPC/Debug event log #>
        wevtutil.exe export-log Microsoft-RMS-MSIPC/Debug $Global:strUniqueLogFolder"\MSIPC.evtx" /overwrite:true
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Microsoft-RMS-MSIPC/Debug event log" -strLogValue "MSIPC.evtx"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: CAPI2 event log..." -PercentComplete (100/27 * 3)

    <# Export CAPI2 event log #>
    wevtutil.exe export-log Microsoft-Windows-CAPI2/Operational $Global:strUniqueLogFolder"\CAPI2.evtx" /overwrite:true
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export CAPI2 event log" -strLogValue "CAPI2.evtx"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: AIP event log..." -PercentComplete (100/27 * 4)

    <# Actions when AIP event log exist #>
    If ([System.Diagnostics.EventLog]::Exists('Azure Information Protection') -Eq $true) {

        <# Export AIP event log #>
        wevtutil.exe export-log "Azure Information Protection" $Global:strUniqueLogFolder"\AIP.evtx" /overwrite:true
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export AIP event log" -strLogValue "AIP.evtx"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Network trace..." -PercentComplete (100/27 * 5)

    <# Stopping network trace #>
    netsh.exe trace stop sessionname="RMS_Support_Tool-Trace" | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Network trace" -strLogValue "Stopped"
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export network trace" -strLogValue "NetMon.etl"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: PSR recording..." -PercentComplete (100/27 * 6)

    <# Stop PSR #>
    psr.exe /stop

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "PSR" -strLogValue "Stopped"
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export PSR" -strLogValue "ProblemSteps.zip"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Application event log..." -PercentComplete (100/27 * 7)

    <# Export Application event log #>
    wevtutil.exe export-log Application $Global:strUniqueLogFolder"\Application.evtx" /overwrite:true
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Application event log" -strLogValue "Application.evtx"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: System event log..." -PercentComplete (100/27 * 8)

    <# Export System event log #>
    wevtutil.exe export-log System $Global:strUniqueLogFolder"\System.evtx" /overwrite:true
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export System event log" -strLogValue "System.evtx"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Office log file..." -PercentComplete (100/27 * 9)

    <# Copy office.log (TCOTrace) file from temp folder to logs folder #>
    fncCopyItem $Global:strTempFolder"\office.log" $Global:strUniqueLogFolder"\office.log" "office.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Office TCOTrace" -strLogValue "office.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Office TCOTrace log files..." -PercentComplete (100/27 * 10)

    <# Copy Office logging files for 2013 (15.o), 2016 (16.o) to logs folder #>
    fncCopyItem $env:LOCALAPPDATA\Microsoft\Office\MsoLogs $Global:strUniqueLogFolder"\MsoLogs" "MsoLogs\*"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Office logs" -strLogValue "\MsoLogs"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: MSOIdentityCRL logs..." -PercentComplete (100/27 * 11)

    <# Disabling MSOIdentityCRL (MSOIDSVC = Microsoft Online Services Sign-in Assistant) trace if service exist #>
    If (Get-Service "MSOIDSVC" -ErrorAction SilentlyContinue) { <# Checking if service exist #>

        <# Remove trace registry key #>
        Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue
        Remove-Item -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue
        Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\MSOIdentityCRL\Trace" -Recurse -Force -ErrorAction SilentlyContinue

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "MSOIdentityCRL logging" -strLogValue "Stopped"

        <# Start service #>
        Start-Service -Name "MSOIDSVC"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export MSOIdentityCRL logs" -strLogValue "\MsoTrace"
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export MSOIdentityCRL trace" -strLogValue "\MsoTracLite"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: RMS logs..." -PercentComplete (100/27 * 12)

    <# Export MSIP/MSIPC content to logs folder #>
    fncCopyItem $env:LOCALAPPDATA\Microsoft\MSIP $Global:strUniqueLogFolder"\MSIP" "MSIP\*"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export MSIP content" -strLogValue "\MSIP"

    <# Copy files to logs folder #>
    fncCopyItem $env:LOCALAPPDATA\Microsoft\MSIPC $Global:strUniqueLogFolder"\MSIPC" "MSIPC\*"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export MSIPC content" -strLogValue "\MSIPC"

    <# Copy files to logs folder #>
    fncCopyItem $env:LOCALAPPDATA\Microsoft\DRM $Global:strUniqueLogFolder"\DRM" "DRM\*"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export DRM content" -strLogValue "\DRM"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: WinHTTP..." -PercentComplete (100/27 * 13)

    <# Export WinHTTP #>
    netsh.exe winhttp show proxy > $Global:strUniqueLogFolder"\WinHTTP.log"
    
    <# Verbose/Logging #>
    fncLOgging -strLogFunction "fncCollectLogging" -strLogDescription "Export WinHTTP" -strLogValue "WinHTTP.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: WinHTTP (WoW6432)..." -PercentComplete (100/27 * 14)

    <# Export WinHTTP_WoW6432, if 64-bit OS #>
    If ((Get-CimInstance Win32_OperatingSystem  -Verbose:$false).OSArchitecture -eq "64-bit") {

        & $env:WINDIR\SysWOW64\netsh.exe winhttp show proxy > $Global:strUniqueLogFolder"\WinHTTP_WoW6432.log"
       
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export WinHTTP_WoW6432" -strLogValue "WinHTTP_WoW6432.log"

    }

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Machine certificates..." -PercentComplete (100/27 * 15)

    <# Export machine certificates #>
    certutil.exe -silent -store my > $Global:strUniqueLogFolder"\CertMachine.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export machine certificates" -strLogValue "CertMachine.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: User certificates..." -PercentComplete (100/27 * 16)

    <# Export user certificates #>
    certutil.exe -silent -user -store my > $Global:strUniqueLogFolder"\CertUser.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export user certificates" -strLogValue "CertUser.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Credentials information..." -PercentComplete (100/27 * 17)

    <# Export Credential Manager #>
    cmdkey.exe /list > $Global:strUniqueLogFolder"\CredMan.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Credential Manager" -strLogValue "CredMan.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: IP configuration..." -PercentComplete (100/27 * 18)

    <# Export ipconfig all #>
    ipconfig.exe /all > $Global:strUniqueLogFolder"\IPConfigAll.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export ipconfig" -strLogValue "IPConfigAll.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: DNS..." -PercentComplete (100/27 * 19)

    <# Display DNS #>
    ipconfig.exe /displaydns > $Global:strUniqueLogFolder"\WinIPConfig.txt" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export DNS" -strLogValue "WinIPConfig.txt"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Environment information..." -PercentComplete (100/27 * 20)

    <# Export environment variables #>
    Get-ChildItem Env: | Out-File $Global:strUniqueLogFolder"\EnvVar.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export environment variables" -strLogValue "EnvVar.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Group policy report..." -PercentComplete (100/27 * 21)
    
    <# Export Gpresult #>
    gpresult /f /h $Global:strUniqueLogFolder"\Gpresult.htm" | Out-Null
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export group policy report" -strLogValue "Gpresult.htm"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Time zone information..." -PercentComplete (100/27 * 22)

    <# Export timezone difference (UTC) #>
    (Get-Timezone).BaseUTCOffset.Hours | Out-File $Global:strUniqueLogFolder"\BaseUTCOffset.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export timezone offset" -strLogValue "BaseUTCOffset.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Tasklist..." -PercentComplete (100/27 * 23)

    <# Export Tasklist #>
    Tasklist.exe /svc > $Global:strUniqueLogFolder"\Tasklist.log"
    
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Tasklist" -strLogValue "Tasklist.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: Programs and Features..." -PercentComplete (100/27 * 24)

    <# Export Programs and Features (32) #>
    If ($(Test-Path -Path "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") -Eq $true) {

        <# Programs32 #>
        Get-ItemProperty "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Export-CSV $Global:strUniqueLogFolder"\Programs32.log" -ErrorAction SilentlyContinue

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Programs (x86)" -strLogValue "Programs32.log" 

    }
    
    <# Export Programs and Features (64) #>
    Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Export-CSV $Global:strUniqueLogFolder"\Programs64.log" -ErrorAction SilentlyContinue

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Programs (x64)" -strLogValue "Programs64.log"

    <# Progress bar update #>
    Write-Progress -Activity " Collecting logs: AIP registry keys..." -PercentComplete (100/27 * 25)
    
    <# Export AIP plugin Adobe Acrobat RMS logs #>
    If ($(Test-Path -Path $env:LOCALAPPDATA\Microsoft\RMSLocalStorage\MIP\logs) -Eq $true) {

        <# Progress bar update #>
        Write-Progress -Activity " Collecting logs: Adobe logs..." -PercentComplete (100/27 * 26)

        <# Export MSIP/MSIPC content to logs folder #>
        fncCopyItem $env:LOCALAPPDATA\Microsoft\RMSLocalStorage\MIP\logs $Global:strUniqueLogFolder"\Adobe\LOCALAPPDATA" "Adobe\LOCALAPPDATA\*"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Adobe logs" -strLogValue "\Adobe"

    }

    If ($(Test-Path -Path $env:LOCALAPPDATA\Microsoft\RMSLocalStorage\MIP\logs) -Eq $true) {

        <# Progress bar update #>
        Write-Progress -Activity " Collecting logs: Adobe logs..." -PercentComplete (100/27 * 26)

        <# Export MSIP/MSIPC content to logs folder #>
        fncCopyItem $env:USERPROFILE\appdata\locallow\Microsoft\RMSLocalStorage\mip\logs $Global:strUniqueLogFolder"\Adobe\USERPROFILE" "Adobe\USERPROFILE\*"

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export Adobe logs" -strLogValue "\Adobe"

    }

    <# Export several AIP registry keys: Defining an array and feeding it with relate AIP registry keys #>
    $Private:arrRegistryKeys = "HKLM:\Software\Classes\MSIP.ExcelAddin", 
                               "HKLM:\Software\Classes\MSIP.WordAddin",
                               "HKLM:\SOFTWARE\Classes\MSIP.PowerPointAddin",
                               "HKLM:\SOFTWARE\Classes\MSIP.OutlookAddin",
                               "HKLM:\SOFTWARE\Classes\AllFileSystemObjects\shell\Microsoft.Azip.RightClick",
                               "HKLM:\SOFTWARE\Microsoft\MSIPC",
                               "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\DRM",
                               "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\SOFTWARE\Microsoft\Office\16.0\Common\DRM",
                               "HKLM:\SOFTWARE\Microsoft\Office\Word\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\Excel\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\PowerPoint\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\Outlook\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\SOFTWARE\Microsoft\Office\Word\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\SOFTWARE\Microsoft\Office\Excel\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\SOFTWARE\Microsoft\Office\PowerPoint\Addins",
                               "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\SOFTWARE\Microsoft\Office\Outlook\Addins",
                               "HKLM:\SOFTWARE\WOW6432Node\Microsoft\MSIPC",
                               "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\Word\Addins",
                               "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\Excel\Addins",
                               "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\PowerPoint\Addins",
                               "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\Outlook\Addins",
                               "HKCU:\SOFTWARE\Microsoft\MSIP",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\DRM",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Security",
                               "HKCU:\Software\Microsoft\Office\16.0\Common\Identity",
                               "HKCU:\SOFTWARE\Microsoft\Office\Word\Addins",
                               "HKCU:\SOFTWARE\Microsoft\Office\Excel\Addins",
                               "HKCU:\SOFTWARE\Microsoft\Office\PowerPoint\Addins",
                               "HKCU:\SOFTWARE\Microsoft\Office\Outlook\Addins",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\Word\Resiliency",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\Excel\Resiliency",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\PowerPoint\Resiliency",
                               "HKCU:\SOFTWARE\Microsoft\Office\15.0\Outlook\Resiliency",
                               "HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\Resiliency",
                               "HKCU:\SOFTWARE\Classes\Local Settings\SOFTWARE\Microsoft\MSIPC",
                               "HKCR:\MSIP.ExcelAddin",
                               "HKCR:\MSIP.WordAddin",
                               "HKCR:\MSIP.PowerPointAddin",
                               "HKCR:\MSIP.OutlookAddin",
                               "HKCR:\Local Settings\SOFTWARE\Microsoft\MSIPC"

    <# Loop though array and cache to a temp file #>
    ForEach ($_ in $Private:arrRegistryKeys) {

        If ($(Test-Path -Path $_) -Eq $true) {

            $Private:strTempFile = $Private:strTempFile + 1
            & REG EXPORT $_.Replace(":", $null) "$Global:strTempFolder\$Private:strTempFile.reg" /Y | Out-Null <# Remove ":" for export (replace) #>

        }

    }

    <# Inserting first information; create log file #>
    "Windows Registry Editor Version 5.00" | Set-Content "$Global:strUniqueLogFolder\Registry.log"

    <# Reading data from cached temp file, and add it to the logfile #>
    (Get-Content "$Global:strTempFolder\*.reg" | ? {$_ -ne "Windows Registry Editor Version 5.00"} | Add-Content "$Global:strUniqueLogFolder\Registry.log")

    <# Cleaning temp folder of cached files #>
    Remove-Item $Global:strTempFolder"\*.reg" -Force -ErrorAction SilentlyContinue | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Export AIP registry keys" -strLogValue "Registry.log"

    <# Progress bar update #>
    Write-Progress -Activity " Logs collected" -Completed

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCollectLogging" -strLogDescription "Collecting logs" -strLogValue "Proceeded" 

}

<# Function to collect admin logs #>
Function fncAdminLogging {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "Admin logging" -strLogValue "Initiated"

    <# Console output #>
    Write-Output "ADMIN LOGGING:"
    Write-Output (Write-Host "ATTENTION: Please request assistance from your administrator to proceed this option." -ForegroundColor Red)
    Read-Host "Only if the above is true, please press any key to continue"
    Write-Output "Initializing admin logging, please wait..."

    <# Checking for AADRM module and uninstalling it #>
    <# AADRM retired, and replaced by AIPservice: https://docs.microsoft.com/en-us/powershell/azure/aip/overview?view=azureipps #>
    If (Get-Module -ListAvailable -Name AADRM) {

            <# Unstalling AADRM PowerShell module #>
            Uninstall-Module -Verbose:$false -Name AADRM | Out-Null 

            <# Verbose/Logging #>
            fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "AADRM module" -strLogValue "AADRM module removed"

    }

    <# Install/update needed nuGet provider to be able to install the latest modules #>
    $Private:strOriginalPreference = $Global:ProgressPreference <# Remember default progress bar status: "Continue" #>
    $Global:ProgressPreference = "SilentlyContinue" <# Hiding progress bar #>
    Find-PackageProvider -Name 'NuGet' -ForceBootstrap -IncludeDependencies -Verbose:$false | Out-Null <# Install latest NuGet provider, to be able to install AIPService module #>

    <# Define powershellgallery.com as trusted location, to be able to install AIPService module #>
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

    <# Set back progress bar to previous default #>
    $Global:ProgressPreference = $Private:strOriginalPreference

    <# Checking for AIPService module and quite installing it, if not already installed #>
    If (-Not (Get-Module -ListAvailable -Name "AIPService")) {

        <# Console output #>
        Write-Output "Installing AIPService PowerShell module..."

        <# Installing AIPService PowerShell module #>
        Install-Module -Verbose:$false -Name AIPService | Out-Null

    }
        
    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "AIPService module version" -strLogValue (Get-Module -Verbose:$false -ListAvailable -Name AIPService).Version

    <# Console output #>
    Write-Output "Connecting to AIPService..."

    <# Connecting/Logon to AIPService #>
    If (Connect-AIPService -Verbose:$false) { <# Action if AIPService connection was opened #>

        <# Console output #> 
        Write-Output "AIPService connected."

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "AIPService connected" -strLogValue $true

    }
    Else{ <# Action if AIPService connection failed #>
    
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "AIPService connected" -strLogValue $false 
        fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "Admin logging" -strLogValue "Login failed"
    
        <# Console output #>
        Write-Output (Write-Host "ADMIN LOGGING: Failed! Please try again.`n" -ForegroundColor Red)
    
        <# Signal sound #>
        [console]::beep(500,200)

        <# Exit function #>
        Break

    }

    <# Check for existing AIPService logging file and create it, if it not exist #>
    If ($(Test-Path $Global:strUserLogPath"\AipServiceConfiguration.log") -Eq $false) {

        <# Create AIPService logging file #>
        Out-File -FilePath $Global:strUserLogPath"\AipServiceConfiguration.log" -Encoding UTF8 -Append -Force

    }

    <# Check for existing AIPService logging file and extend it, if it exist #>
    If ($(Test-Path $Global:strUserLogPath"\AipServiceConfiguration.log") -Eq $true) {

        <# Exporting AADRM configuration #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("Date/Timestamp: " + (Get-Date -Verbose:$false -UFormat "%y%m%d-%H%M%S")) <# Timestamp #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("Module version: " + (Get-Module -Verbose:$false -ListAvailable -Name AIPService).Version).ToString() <# AIPService Module version #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("BPOSId: " + (Get-AipServiceConfiguration).BPOSId).ToString() <# BPOSId #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("RightsManagementServiceId: " + (Get-AipServiceConfiguration).RightsManagementServiceId).ToString() <# RightsManagementServiceId #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("LicensingIntranetDistributionPointUrl: " + (Get-AipServiceConfiguration).LicensingIntranetDistributionPointUrl).ToString() <# LicensingIntranetDistributionPointUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("LicensingExtranetDistributionPointUrl: " + (Get-AipServiceConfiguration).LicensingExtranetDistributionPointUrl).ToString() <# LicensingExtranetDistributionPointUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("CertificationIntranetDistributionPointUrl: " + (Get-AipServiceConfiguration).CertificationIntranetDistributionPointUrl).ToString() <# CertificationIntranetDistributionPointUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("CertificationExtranetDistributionPointUrl: " + (Get-AipServiceConfiguration).CertificationExtranetDistributionPointUrl).ToString() <# CertificationExtranetDistributionPointUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("AdminConnectionUrl: " + (Get-AipServiceConfiguration).AdminConnectionUrl).ToString() <# AdminConnectionUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("AdminV2ConnectionUrl: " + (Get-AipServiceConfiguration).AdminV2ConnectionUrl).ToString() <# AdminV2ConnectionUrl #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("OnPremiseDomainName: " + (Get-AipServiceConfiguration).OnPremiseDomainName).ToString() <# OnPremiseDomainName #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("Keys: " + (Get-AipServiceConfiguration).Keys).ToString() <# Keys #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("CurrentLicensorCertificateGuid: " + (Get-AipServiceConfiguration).CurrentLicensorCertificateGuid).ToString() <# CurrentLicensorCertificateGuid #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("Templates: " + (Get-AipServiceConfiguration).Templates).ToString() <# Templates #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("FunctionalState: " + (Get-AipServiceConfiguration).FunctionalState).ToString() <# FunctionalState #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("SuperUsersEnabled: " + (Get-AipServiceConfiguration).SuperUsersEnabled).ToString() <# SuperUsersEnabled #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("SuperUsers: " + (Get-AipServiceConfiguration).SuperUsers).ToString() <# SuperUsers #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("AdminRoleMembers: " + (Get-AipServiceConfiguration).AdminRoleMembers).ToString() <# AdminRoleMembers #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("KeyRolloverCount: " + (Get-AipServiceConfiguration).KeyRolloverCount).ToString() <# KeyRolloverCount #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("ProvisioningDate: " + (Get-AipServiceConfiguration).ProvisioningDate).ToString() <# ProvisioningDate #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("IPCv3ServiceFunctionalState: " + (Get-AipServiceConfiguration).IPCv3ServiceFunctionalState).ToString() <# IPCv3ServiceFunctionalState #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("DevicePlatformState: " + (Get-AipServiceConfiguration).DevicePlatformState).ToString() <# DevicePlatformState #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("FciEnabledForConnectorAuthorization: " + (Get-AipServiceConfiguration).FciEnabledForConnectorAuthorization).ToString() <# FciEnabledForConnectorAuthorization #>
        Add-Content -Path $Global:strUserLogPath"\AipServiceConfiguration.log" -Value ("DocumentTrackingFeatureState: " + (Get-AipServiceConfiguration).DocumentTrackingFeatureState).ToString() <# DocumentTrackingFeatureState #>

    }

    <# Disconnect from AIPService #>
    Disconnect-AIPService | Out-Null

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "Export Admin log" -strLogValue "AipServiceConfiguration.log"
    fncLogging -strLogFunction "fncAdminLogging" -strLogDescription "Admin logging" -strLogValue "Proceeded"

    <# Console output #> 
    Write-Output (Write-Host "ADMIN LOGGING: Proceeded.`n" -ForegroundColor Green)

    <# Signal sound #>
    [console]::beep(1000,200)

}

<# Function to compress all log files into a .zip file #>
Function fncCompressLogs {

    <# Console output #> 
    Write-Output "COMPRESS LOGS:`nCompressing logs, please wait..."
        
    <# Defining default zip folder path #>
    $Global:strZipLogPath = $Global:strTempFolder + "\RMS_Support_Tool"

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncCompressLogs" -strLogDescription "Zip folder path" -strLogValue $Global:strZipLogPath

    <# Check, if MSOIDSVC service (Microsoft Online Services Sign-in Assistant) exist #>
    If (Get-Service "MSOIDSVC" -ErrorAction SilentlyContinue) {

        <# Checking if servcie is running and acting accordingly #>
        If ((Get-Service "MSOIDSVC").Status -Eq "Running") { <# Needs to be stopped to prevent file locks while compressing zip file #>

            <# Stop service #>
            Stop-Service -Name "MSOIDSVC"

        }

    }

    <# Compress all files into a .zip file #>
    If ($(Test-Path -Path $Global:strZipLogPath) -Eq $true) { <# Actions, if path exist #>

        <# Defining .zip file name #>
        $Private:strZipFile = "RMS_Support_Tool (" + $env:USERNAME + (Get-Date -UFormat "-%H%M%S") + ").zip".ToString()

        <# Compress all files and logs into zip file (overwrites) #>
        Compress-Archive -Path $Global:strZipLogPath"\Logs\*" -DestinationPath $Global:strZipLogPath\$Private:strZipFile -Force -ErrorAction SilentlyContinue

        }

        <# Cleaning Logs folders to start from scratch next time #>
        Remove-Item $Global:strZipLogPath"\Logs" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null

        <# Console output #>
        Write-Output "Zip file path and name: $Global:strZipLogPath\$Private:strZipFile"
        Write-Output (Write-Host "COMPRESS LOGS: Proceeded.`n" -ForegroundColor Green)

        <# Signal sound #>
        [console]::beep(1000,200)

    <# Check, if MSOIDSVC service (Microsoft Online Services Sign-in Assistant) exist #>
    If (Get-Service "MSOIDSVC" -ErrorAction SilentlyContinue) { <# Checking if service exist #>

        <# Checking if servcie is not running and acting accordingly #>
        If (-Not (Get-Service "MSOIDSVC").Status -Eq "Running") { <# Action, if service is not running. #>

            <# Start service #>
            Start-Service -Name "MSOIDSVC"

        }

    }

    <# Releasing private varibles #>
    $Private:strZipFile = $null

    <# Releasing global varible #>
    $Global:strWindowsEdition = $null
    $Global:strZipLogPath = $null

}

<# Function to pause menu for message display #>
Function fncPause {

    $Private:strPauseMessage = "Press any key to continue"

    <# Pausing the script module with a message #>
    If ($Global:psISE) { <# Actions, if running in PowerShell ISE #>

        Add-Type -AssemblyName System.Windows.Forms
        [System.Windows.Forms.MessageBox]::Show("$Private:strPauseMessage")

    }
    Else { <# Actions, if running in PowerShell command window #>

        <# Console output #> 
        Write-Output (Write-Host $Private:strPauseMessage -ForegroundColor Yellow)
        $Private:strValue = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    }

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncPause" -strLogDescription "Pause" -strLogValue "Called"

}

<# Function to call script module menu #>
Function fncShowMenu {

    <# Clearing console #>
    Clear-Host

    <# Helper variable to control menu handling inside function calls #>
    $Global:bolCommingFromMenu = $true

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncShowMenu" -strLogDescription "Main menu" -strLogValue "Called"

    <# Menu output #>
    Write-Output (Write-Host " [1] INFORMATION" -ForegroundColor Green)
    Write-Output (Write-Host " [2] DISCLAIMER" -ForegroundColor Red)
    Write-Output (Write-Host " [3] HELP" -ForegroundColor Green)
    Write-Output (Write-Host " [4] RESET" -ForegroundColor Yellow)
    Write-Output (Write-Host " [5] USER LOGGING" -ForegroundColor Yellow)
    Write-Output (Write-Host " [6] ADMIN LOGGING" -ForegroundColor Yellow)
    Write-Output (Write-Host " [7] COMPRESS LOGS" -ForegroundColor Yellow)
    Write-Output (Write-Host " [8] EXIT MENU`n" -ForegroundColor Green)

    <# Defining menu selection variable #>
    $Private:intMenuSelection = Read-Host "Please select an option and press enter"

    <# Actions, for information menu selected #>
    If ($Private:intMenuSelection -Eq 1) {
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[1] INFORMATION" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host
        
        <# Calling information function #>
        fncInformation
        
        <# Calling pause function #>
        fncPause

    }

    <# Actions, for disclaimer menu selected #>
    If ($Private:intMenuSelection -Eq 2) {
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[2] DISCLAIMER" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host

        <# Calling disclaimer function #>
        fncDisclaimer

        <# Calling pause function #>
        fncPause
    }
   
    <# Actions, for help menu selected #>
    If ($Private:intMenuSelection -Eq 3) {
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[3] HELP" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host

        <# Calling help function #>
        fncHelp

    }
    
    <# Actions, for reset menu selected #>
    If ($Private:intMenuSelection -Eq 4) {

        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[4] RESET" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host

        <# Calling reset function #>
        fncReset

        <# Calling pause function #>
        fncPause

    }

    <# Actions, for user logging menu selected #>
    If ($Private:intMenuSelection -Eq 5) {
        
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[5] USER LOGGING" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host
        
        <# Calling user logging function #>
        fncUserLogging
        
        <# Calling pause function #>
        fncPause

    }

    <# Actions, for admin logging menu selected #>
    If ($Private:intMenuSelection -Eq 6) {
    
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[6] ADMIN LOGGING" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host
        
        <# Calling admin logging function #>
        fncAdminLogging
        
        <# Calling pause function #>
        fncPause

    }

    <# Actions, for compress logs menu selected #>
    If ($Private:intMenuSelection -Eq 7) {
    
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[7] COMPRESS LOGS" -strLogValue "Selected"
        
        <# Clearing console #>
        Clear-Host
        
        <# Calling compress logs function #>
        fncCompressLogs
        
        <# Calling pause function #>
        fncPause
        
    }

    <# Actions, for exit menu selected #>
    If ($Private:intMenuSelection -Eq 8) {
    
        <# Verbose/Logging #>
        fncLogging -strLogFunction "fncShowMenu" -strLogDescription "[8] EXIT" -strLogValue "Selected"

        <# Clear global variables #>
        $Global:bolCommingFromMenu = $false
        
        <# Exit function #>
        Break
        
    }
    Else {

        <# Clearing console #>
        Clear-Host

        <# Calling show menu function #>
        fncShowMenu

    }

 }

<# Function to show version #>
Function fncShowVersion {

    <# Verbose/Logging #>
    fncLogging -strLogFunction "fncShowVersion" -strLogDescription "Version" -strLogValue "Called"

    <# Console output version information #>
    Write-Output "You are using version: $Global:strScriptVersion`nPlease check on this website if you are using the latest version of the RMS_Support_Tool, and update if necessary:`nhttps://aka.ms/RMS_Support_Tool/Latest`n"

}

<# Creating default log entries #>
fncCreateDefaultLogEntries

<# Checking Windows version and exit script module if running on unsupported Windows version #>
fncCheckWindowsVersion

<# Check for latest version of the script module #>
fncCheckForUpdate

<# Export functions for script module manifest #>
Export-ModuleMember -Function RMS_Support_Tool

# SIG # Begin signature block
# MIIYoQYJKoZIhvcNAQcCoIIYkjCCGI4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUGIfu6Yn/bYN2O6PqRZ+oz407
# IRCgghPJMIID7jCCA1egAwIBAgIQfpPr+3zGTlnqS5p31Ab8OzANBgkqhkiG9w0B
# AQUFADCBizELMAkGA1UEBhMCWkExFTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTEUMBIG
# A1UEBxMLRHVyYmFudmlsbGUxDzANBgNVBAoTBlRoYXd0ZTEdMBsGA1UECxMUVGhh
# d3RlIENlcnRpZmljYXRpb24xHzAdBgNVBAMTFlRoYXd0ZSBUaW1lc3RhbXBpbmcg
# Q0EwHhcNMTIxMjIxMDAwMDAwWhcNMjAxMjMwMjM1OTU5WjBeMQswCQYDVQQGEwJV
# UzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xMDAuBgNVBAMTJ1N5bWFu
# dGVjIFRpbWUgU3RhbXBpbmcgU2VydmljZXMgQ0EgLSBHMjCCASIwDQYJKoZIhvcN
# AQEBBQADggEPADCCAQoCggEBALGss0lUS5ccEgrYJXmRIlcqb9y4JsRDc2vCvy5Q
# WvsUwna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