Functions/Functions.ps1

function Disable-Firewall {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Disables the local firewall

    .EXAMPLE
    Disable-Firewall
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param (
    )
    Write-Host "Disabling Firewall" -ForegroundColor Green
    Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False
}

function Disable-PasswordPeek {
    <#
.SYNOPSIS
-Taylor Lee
Modified 06262019
.DESCRIPTION
Disables Password peaking in windows password prompts. Especially useful if providing remote support and needing to type in admin credentials.
#>


    [CmdletBinding()]
    Param (
    )
    
    reg.exe ADD "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\CredUI" /v DisablePasswordReveal /t REG_DWORD /d 1 /f
}

function Disable-ShakeToMinimize {
    <#
    .Synopsis
    -Taylor Lee
    Modified 05172019

    .Description
    This function disables the annoying shake to minimize Windows feature
    #>

    [CmdletBinding()]
    param (
    )

    reg.exe add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /f /v "DisallowShaking" /t reg_dword /d 1

}

function Disable-Standby {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 06252019

    .DESCRIPTION
    Disables standby, sleep, and hibernate

    .EXAMPLE
    Disable-Standby
    #>

    [CmdletBinding()]
    param (
    )
    Write-Host "disabling standby" -ForegroundColor Green
    powercfg.exe -change -standby-timeout-ac 0
    powercfg.exe -change -standby-timeout-dc 0
    powercfg.exe -change -hibernate-timeout-ac 0
    powercfg.exe -change -hibernate-timeout-dc 0
    powercfg.exe -change -monitor-timeout-ac 15
    powercfg.exe -change -monitor-timeout-dc 15
    powercfg.exe -change -disk-timeout-ac 0
    powercfg.exe -change -disk-timeout-dc 0
    #Lid Close do nothing
    powercfg.exe -SETACVALUEINDEX SCHEME_CURRENT 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 000
    powercfg.exe -SETDCVALUEINDEX SCHEME_CURRENT 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 000

    #Power Button do Nothing
    powercfg.exe -setacvalueindex SCHEME_CURRENT 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 000
    powercfg.exe -setdcvalueindex SCHEME_CURRENT 4f971e89-eebd-4455-a8de-9e59040e7347 7648efa3-dd9c-4e3e-b566-50f929386280 000
    powercfg.exe -h off
    Remove-Item c:\hiberfile.sys -Force -ErrorAction SilentlyContinue
}

function Enable-Firewall {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Disables the local firewall

    .EXAMPLE
    Disable-Firewall
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param (
    )
    Write-Host "Enabling Firewall" -ForegroundColor Green
    Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled True
}

function Enable-RSATFeatures {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 06242019

    .DESCRIPTION
    Enables Remote Server Administration Tools On Windows 10 PC's.
    #>


    #Install RSAT Features
    Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability -Online

    #Upate the help after
    Update-Help
}

function Get-ChocoOutdated {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 06052019

    .DESCRIPTION
    Gets outdated choco packages

    .EXAMPLE
    Get-ChocoOutdated
    #>


    choco.exe outdated --ignore-unfound
}

function Join-Domain {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Joins pc to a domain

    .EXAMPLE
    Join-Domain -domain company.com
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]$domain
    )
    Add-Computer -DomainName $domain -Credential $credentials
}

function Install-Chocolatey {
    <#
    .DESCRIPTION
    Installs Chocolatey

    .EXAMPLE
    Install-Chocolatey
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute( `
            "PSAvoidUsingInvokeExpression", `
            "", `
            Justification = "Using Chocolatey-provided call")]
    param()

    try {
        choco -v | Out-Null
        Write-Host 'Chocolatey already installed.' -ForegroundColor Green
        return
    }
    catch {
        $downloadUrl = 'https://chocolatey.org/install.ps1'
        Write-Output 'Installing Chocolatey...'
        Set-ExecutionPolicy Bypass -Scope Process -Force; `
            Invoke-Expression `
        ((New-Object System.Net.WebClient).DownloadString($downloadUrl))
    }
}

function Install-ChocoPackages {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 06052019

    .DESCRIPTION
    Install one or Multiple Choclatey Packages

    .EXAMPLE
    Install a single application

    Install-ChocoPackages -install firefox

    .EXAMPLE
    Install Multiple Applications.

    Install-ChocoPackages -install firefox, chrome, nmap
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]$Install
    )

    #Start Transcipt
    $username = $env:UserName
    Start-Transcript "c:\users\$username\desktop\Choco Install.txt" -append

    #Install Choco Packages
    Write-Host 'Installing Software with Chocolatey...' -ForegroundColor Green
    choco install -y -r $Install

    #Stop Transcript
    Stop-Transcript
}

function Invoke-ChocoUpgrade {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 06062019

    .DESCRIPTION
    Upgrade choco packages

    .EXAMPLE
    Invoke-ChocoUpgrade
    #>


    [CmdletBinding()]
    param (
    )
    choco upgrade all
}


function Remove-Shortcuts {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Removes desktop shortcuts

    .EXAMPLE
    Remove-Shortcuts
    #>

    [CmdletBinding()]
    param (
    )
    Write-Host 'Deleting desktop icons...' -ForegroundColor Green
    Remove-Item C:\Users\*\Desktop\*.lnk -Force
}

function Remove-StoreApps {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Removes sponsered Windows store apps and some microsoft apps

    -Microsot Apps Removed
        "Microsoft.BingNews"
        "Microsoft.BingWeather"
        "Microsoft.MicrosoftSolitaireCollection"
        "Microsoft.Office.OneNote"
        "Microsoft.Office.Sway"
        "Microsoft.RemoteDesktop"
        "Microsoft.WindowsCamera"
        "*Skype*"

    .EXAMPLE
    Remove-StoreApps
    #>

    [CmdletBinding(SupportsShouldProcess)]

    Param (
    )

    $CrapApps = @(

        #Unnecessary Windows 10 AppX Apps
        "Microsoft.BingNews"
        "Microsoft.BingWeather"
        "Microsoft.MicrosoftSolitaireCollection"
        "Microsoft.Office.OneNote"
        "Microsoft.Office.Sway"
        "Microsoft.RemoteDesktop"
        "Microsoft.WindowsCamera"
        "*Skype*"

        #Sponsored Windows 10 AppX Apps
        "*EclipseManager*"
        "*ActiproSoftwareLLC*"
        "*AdobeSystemsIncorporated.AdobePhotoshopExpress*"
        "*Duolingo-LearnLanguagesforFree*"
        "*PandoraMediaInc*"
        "*CandyCrush*"
        "*Wunderlist*"
        "*Flipboard*"
        "*Twitter*"
        "*Facebook*"
        "*Spotify*"
        "*Minecraft*"
        "*Royal Revolt*"

    )

    foreach ($Crap in $CrapApps) {
        Get-AppxPackage -Name $Crap | Remove-AppxPackage -ErrorAction SilentlyContinue
        Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Debloat | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
        Write-Output "Removing $Crap if exists."
    }

    Write-Host "Adding Registry key to prevent bloatware apps from returning" -ForegroundColor Green
    $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
    $registryOEM = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"
    If (!(Test-Path $registryPath)) {
        New-Item $registryPath
    }
    Set-ItemProperty $registryPath DisableWindowsConsumerFeatures -Value 1

    If (!(Test-Path $registryOEM)) {
        New-Item $registryOEM
    }
    Set-ItemProperty $registryOEM  ContentDeliveryAllowed -Value 0
    Set-ItemProperty $registryOEM  OemPreInstalledAppsEnabled -Value 0
    Set-ItemProperty $registryOEM  PreInstalledAppsEnabled -Value 0
    Set-ItemProperty $registryOEM  PreInstalledAppsEverEnabled -Value 0
    Set-ItemProperty $registryOEM  SilentInstalledAppsEnabled -Value 0
    Set-ItemProperty $registryOEM  SystemPaneSuggestionsEnabled -Value 0
}

function Remove-Tiles {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Removes all start menu tiles

    .EXAMPLE
    Remove-Tiles
    #>

    [CmdletBinding()]
    param (
    )
    (New-Object -Com Shell.Application).
    NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').
    Items() |
    ForEach-Object { $_.Verbs() } |
    Where-Object { $_.Name -match 'Un.*pin from Start' } |
    ForEach-Object { $_.DoIt() }
}

function Set-UAC {

    <#
    .Synopsis
    -Taylor Lee
    Modified 07062019

    .Description
    This function can Enable/Disable UserAccountControl entirely or just the Prompt Behaviour

    .Example
    Disabled UAC Prompting for Admins, but keeps UAC enabled

    Set-UACState -DisablePrompt

    .Example
    Disabled UAC Entirely

    Set-UACState -Disable

    .Example
    Enable UAC Entirely

    Set-UACState -Enable
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = 'Disable')][switch]$Disable,
        [Parameter(Mandatory = $true, ParameterSetName = 'DisablePrompt')][switch]$DisablePrompt,
        [Parameter(Mandatory = $true, ParameterSetName = 'Enable')][switch]$Enable
    )

    if ($Disable) {
        reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v "ConsentPromptBehaviorAdmin" /t reg_dword /d 0
        reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v "EnableLUA" /t reg_dword /d 0
    }

    if ($DisablePrompt) {
        reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v "ConsentPromptBehaviorAdmin" /t reg_dword /d 0
    }

    if ($Enable) {
        reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v "ConsentPromptBehaviorAdmin" /t reg_dword /d 2
        reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v "EnableLUA" /t reg_dword /d 1
    }
}

function Show-ChocoInstalls {
    <#
    .SYNOPSIS
    -Taylor Lee
    Modified 05262019

    .DESCRIPTION
    Show Installed Chocolatey packages

    .EXAMPLE
    Show-ChocoInstalls
    #>

    [CmdletBinding()]
    param (
    )
    choco.exe list --local-only
}