ActivateAll.psm1

    function Get-Answer
    {
        [CmdletBinding()]
        [OutputType([boolean])]
        param
        (
            [Parameter(Mandatory = $true)]
            [string]$question,
            [boolean]$answer
        )
        
        $YN = Read-Host -Prompt "$question`n(Y)es, ENTER - No"
        if ($YN -eq "Y")
        {
            [boolean]$answer = $true
        }
        else
        {
            [boolean]$answer = $false
        }
        [boolean]$answer
    }
    function Test-Admin
    {
        [CmdletBinding()]
        [OutputType([boolean])]
        param ()
        
        return [boolean]([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    }
    
    <#
        .SYNOPSIS
            Install Office (R) Tool module
         
        .DESCRIPTION
            Installs Office (R) Tool module and prompt to install Office (R) Tool
         
        .PARAMETER Force
            CAUTIOUS! This will skip if antivirus realtime protection is enabled !
         
        .EXAMPLE
            PS C:\> Install-OfficeRTool
            PS C:\> Install-OfficeRTool - Force # Install OfficeRTool module without antivirus check
         
        .NOTES
            Additional information about the function.
    #>

    function Install-OfficeRTool
    {
        [CmdletBinding(SupportsShouldProcess = $true)]
        param
        (
            [switch]$Force
        )
        
        if (!(Test-Admin -ErrorAction SilentlyContinue))
        {
            return Write-Error -Message "Need to open Powershell with Admin privileges." -Category PermissionDenied
        }
        
        if (!(Get-Module -Name "AntivirusProductsDetailedStatus" -ListAvailable -ErrorAction SilentlyContinue))
        {
            Install-Module -Name "AntivirusProductsDetailedStatus" -Force
        }
        
        $RTL = Get-Module -Name "OfficeRTool" -ListAvailable -ErrorAction SilentlyContinue
        if (!$RTL)
        {
            if (Get-Answer -question "Install Office (R) Tool ?")
            {
                Install-Module -Name "OfficeRTool" -Force
                if (Get-RealTimeProtection)
                {
                    Write-Output "`nAntivirus Realtime proteciton emabled.`nDisable antivirus first to install Office (R) Tool."
                    return Start-Process -FilePath "windowsdefender://Threatsettings"
                }
                else
                {
                    return Install-RTool
                }
            }
            else
            {
                return Write-Output -InputObject "`nSkipping Office (R) Tool installation."
            }
        }
        elseif ($RTL.Version.Build -lt 2)
        {
            if (Get-RealTimeProtection)
            {
                Write-Output "`nAntivirus Realtime proteciton emabled.`nDisable antivirus first to update Office (R) Tool."
                Start-Process -FilePath "windowsdefender://Threatsettings"
            }
            else
            {
                Write-Output -InputObject "`nUpdating Office (R) Tool module."
                Update-Module -Name "OfficeRTool" -Force
                Write-Output -InputObject "`nInstalling Office (R) Tool."
                Install-RTool -IgnoreAntivirus
            }
        }
        
        if ($Force)
        {
            return Install-RTool -IgnoreAntivirus
        }
        elseif (Get-Answer -question "Activate Office ?")
        {
            Write-Output -InputObject "`nActivating Office permanently."
            & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://get.activated.win"))) /Ohook
        }
    }
    
    <#
        .SYNOPSIS
            Activate Windows permanently
         
        .DESCRIPTION
            Activates Windows permanently with online activation script.
         
        .PARAMETER Force
            Skip checking if Windows is already activated.
         
        .PARAMETER alternative
            Use alternative method for activation.
         
        .PARAMETER office
            Activate Office permanently.
         
        .EXAMPLE
            PS C:\> Invoke-WindowsHWIDactivation # Activate Windows permanently.
            PS C:\> Invoke-WindowsHWIDactivation -office # Activate Office permanently.
         
        .NOTES
            Additional information about the function.
    #>

    function Invoke-WindowsHWIDactivation
    {
        [CmdletBinding()]
        param
        (
            [switch]$Force,
            [switch]$alternative,
            [switch]$office
        )
        
        if (!(Test-Admin -ErrorAction SilentlyContinue))
        {
            return Write-Error -Message "Need to open Powershell with Admin privileges." -Category PermissionDenied
        }
        
        if ($office)
        {
            Write-Output -InputObject "`nActivating Office permanently."
            return & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://get.activated.win"))) /Ohook
        }
        
        if ($Force)
        {
            if ($alternative)
            {
                return & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://massgrave.dev/get"))) /HWID
            }
            else
            {
                return & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://get.activated.win"))) /HWID
            }
        }
        
        [int]$WinActivated = (Get-CimInstance -ClassName SoftwareLicensingProduct -Filter "Name like 'Windows%'" | Where-Object { $_.PartialProductKey } | Select-Object LicenseStatus).LicenseStatus
        
        if ($WinActivated -ne 1)
        {
            if (Get-Answer -question "Activate Windows ?")
            {
                Write-Output -InputObject "Activating Windows permanently."
                if ($alternative)
                {
                    return & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://massgrave.dev/get"))) /HWID
                }
                else
                {
                    return & ([ScriptBlock]::Create((Invoke-RestMethod -Uri "https://get.activated.win"))) /HWID
                }
            }
            else
            {
                Write-Output -InputObject "Windows NOT activated !"
            }
        }
        else
        {
            Write-Output -InputObject "Windows already activated."
        }
    }
    
    <#
        .SYNOPSIS
            Install dot NET 3.5 feature
         
        .DESCRIPTION
            A detailed description of the Install-dotNET3.5 function.
         
        .PARAMETER Force
            Skip check if dotNET 3.5 is already installed.
         
        .EXAMPLE
            PS C:\> Install-dotNET3.5
         
        .NOTES
            Additional information about the function.
    #>

    function Install-dotNET3.5
    {
        [CmdletBinding(SupportsShouldProcess = $true)]
        param
        (
            [switch]$Force
        )
        
        if (!(Test-Admin -ErrorAction SilentlyContinue))
        {
            return Write-Error -Message "Need to open Powershell with Admin privileges." -Category PermissionDenied
        }
        
        if ($pscmdlet.ShouldProcess("Target", "Operation"))
        {
            $dotNetName = "Windows feature .NET 3.5"
            $dotNet = (Get-WindowsOptionalFeature -FeatureName "NetFx3" -Online -ErrorAction SilentlyContinue).State
            
            if ($Force)
            {
                Write-Output "Installing optional $dotNetName package."
                Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All
            }
            elseif (![boolean]$dotNet)
            {
                Write-Output "Installing optional $dotNetName package."
                Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All
            }
            else
            {
                Write-Output "Optional $dotNetName already enabled."
            }
            
            if (![boolean]$dotNet)
            {
                Write-Error -Category NotEnabled -Message "$dotNetName failed to install, trying other installation method." -ErrorAction Continue
                $choco = Get-Command -Name "choco.exe" -ErrorAction SilentlyContinue
                
                if (![boolean]$choco)
                {
                    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
                    return & ([ScriptBlock]::Create((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')))
                }
                else
                {
                    Start-Process -FilePath "choco.exe" -ArgumentList "install dotnet3.5 -f -y" -NoNewWindow
                }
                
                if (![boolean]$choco)
                {
                    Start-Process -FilePath "DISM" -ArgumentList "/Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:D:\sources\sxs" -NoNewWindow
                }
            }
        }
    }