ELM-WinTools.psm1

Function Add-RebootTask {

    If (Get-ScheduledTask -TaskName "*Weekly Reboot*") {

        Write-Error "A scheduled reboot already exists!" -ErrorAction Stop
        
        } 

    $MachineType = (Get-WmiObject -Class Win32_ComputerSystem).Model

    $RandomMins = Get-Random -Minimum 30 -Maximum 59

    if ($MachineType -eq "Virtual Machine") {

    schtasks /create /tn �Weekly Reboot - VM� /tr �shutdown /r /t 0� /sc weekly /d mon /st 03:$($RandomMins):00 /ru �System�
    schtasks /query /tn "Weekly Reboot - VM"

    } else {

    schtasks /create /tn �Weekly Reboot - Host� /tr �shutdown /r /t 0� /sc weekly /d mon /st 04:$($RandomMins):00 /ru �System�
    schtasks /query /tn "Weekly Reboot - Host"

    }


}
function Clear-Folder {

    [cmdletbinding(SupportsShouldProcess=$True)]
    
    param (
        [Parameter(Position=0,mandatory=$true)]
        [string] $TargetDirectory
        )

    $EmptyDir = "$env:TEMP\empty_temp"

    # create a empty temp folder for robocopy later
    if (!(Test-Path $EmptyDir)) {
    New-Item -Path $EmptyDir -ItemType Directory
    }

    # warn
    Write-Warning "You are about to erase everything in $TargetDirectory are you sure you want to continue" -WarningAction Inquire
    Write-Warning "Are you ABSOLUTELY certain?" -WarningAction Inquire

    # use robocopy to mirror the empty directory over the top of the target directory
    robocopy $EmptyDir $TargetDirectory /MIR

    # remove empty temp folder and target folder
    Remove-Item $EmptyDir,$TargetDirectory -Force -Recurse

}
Function Update-BootImage {
    <#
    .SYNOPSIS
        This function updates the boot image on a deployment server and automatically imports it in to WDS
      
      
    .NOTES
        Name: Update-BootImage
        Author: Elliott Marter
      
      
    .EXAMPLE
        Update-BootImage -DeploymentShare D:\DeploymentShare
      
      
    .LINK
        https://www.powershellgallery.com/profiles/elliottmarter -
    #>

     
        [CmdletBinding()]
        param(
            [Parameter(
                Mandatory = $true,
                Position = 0
                )]
            [string[]]  $DeploymentShare
        )
     
        BEGIN {

            if (!(test-path $DeploymentShare)) {

            throw "Could not find $DeploymentShare please check again..."

            }

            # Import MDT Toolkit
            Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"

            # Get all exisiting boot images and remove them
            Get-WdsBootImage | Remove-WdsBootImage

        }
     
        PROCESS {

            $DSItem = Get-Item $DeploymentShare
            $DSItem
            
            $DSName = $DSItem.name
            $DSName
            
            $DSPath = $DSItem.fullname
            $DSPath

            New-PSDrive -Name $DSName -PSProvider MDTProvider -Root $DSPath -Verbose
            
            Update-MDTDeploymentShare -Path "$($DSName):" -Verbose
            
            Import-WdsBootImage -NewImageName $DSName -NewDescription $DSName -Path "$DSPath\Boot\LiteTouchPE_x64.wim" -Verbose 
            
            Get-PSDrive -Name $DSName | Remove-PSDrive -Verbose
            
        }
     
        END {}
    }