write-host "Install-WHAM profile v1.2" $FolderPath = $profile | Split-Path -Parent $WHAMModule = "$FolderPath\WHAM.psm1" $Functions = @" Function Start-WHAM{ <# .SYNOPSIS Launch / download WHAM and its dependancies .DESCRIPTION Function to control the download and execution of WHAM. By default the function will cache all WHAM files to `$env:tmp and execute it from there. The cache will last for 24 hours If you run the function and the cache is already present, it will just run WHAM (unless cache is over 24 hours old) .PARAMETER Download Description: Forces a fresh download of WHAM to `$ENV:tmp Example use: Start-WHAM -Download .PARAMETER DC Description: Specify the DC to download WHAM. Without this param we default to the closest one via the DC key Example use: Start-WHAM -DC ORD .PARAMETER NoRun Description: Will not launch WHAM - useful just to cache files and work with `$env:tmp directly Example use: Start-WHAM -NoRun -Download .PARAMETER Dev Description: Runs WHAM in DEV mode, downloads from DEV location, doesnt log to AppStats and turns on verbose output Example use: Start-WHAM -Dev .PARAMETER CustomWHAMParams Description: Pass through a blob of WHAM params. I wouldnt really do this, use -NoRun then browse to `$env:tmp and interact with Wham_controller.ps1 directly Example use: Start-WHAM -CustomWHAMParams @{Devices="502664,502667"} .EXAMPLE Full command: Start-WHAM -DC ORD -Download -NoRun Description: Download WHAM to `$env:tmp from the ORD media server but dont run .EXAMPLE Full command: Start-WHAM -Dev Description: Launch WHAM in dev mode .NOTES Author: Martin Howlett Date: 17/09/2015 Version: 1.0 #> Param( [Parameter()][switch]`$Download, [Parameter()][switch]`$NoRun, [Parameter()][switch]`$Dev, [Parameter()]`$CustomWHAMParams, [Parameter()]`$DC ) if(`$dev){ write-host "Dev mode selected" -foregroundcolor Yellow `$DevPath = "/Dev" }else{ `$DevPath = "" } #check if the file doesnt exist or is older then 24 hours, if it is we will download it again if(-NOT `$download){ if(-NOT (Test-Path `$env:tmp\wham_controller.ps1)){ `$download = `$true }else{ `$Date = `$(Get-Date).AddDays(-1) If((Get-Item `$env:tmp\wham_controller.ps1 | Select-Object LastWriteTime).LastWriteTime -lt `$Date){ `$download = `$true } } } IF(`$download){ #delete old stuff Get-ChildItem `$ENV:tmp | where-object {(`$_.Name -like "*.ps*1")} | Remove-Item -Force #get new stuff `$WebClient = New-Object System.Net.WebClient Invoke-Expression (`$WebClient.DownloadString("http://bit.ly/1NHSEL3")) `$Modules = @( "Media/ScriptRepository/Powershell`$DevPath/WHAM/Modules/WHAM_Data_Module.psm1", "Media/ScriptRepository/Powershell`$DevPath/WHAM/Modules/WHAM_Template_Module.psm1", "Media/ScriptRepository/Powershell`$DevPath/WHAM/Modules/WHAM_Execution_Module.psm1", "Media/ScriptRepository/Powershell`$DevPath/WHAM/PSEXEC.exe", "Media/ScriptRepository/Powershell`$DevPath/WHAM/WHAM_Controller.ps1", "Media/ScriptRepository/Powershell`$DevPath/Shared_Modules/Logging_Module.psm1", "Media/ScriptRepository/Powershell`$DevPath/Shared_Modules/Questions_Module.psm1", "Media/ScriptRepository/Powershell`$DevPath/Shared_Modules/Media_Server_Functions.psm1", "Media/ScriptRepository/Powershell`$DevPath/CTKCore/CTKCore.psm1", "Media/ScriptRepository/Powershell`$DevPath/BBCode/BBCode.psm1" ) `$Params = @{} `$Params.Add("URLPath", "") #add a DC if we specify one If (`$DC){`$Params.Add("DC", `$DC)} write-host "Downloading modules, please wait..." -foregroundcolor cyan foreach(`$module in `$modules){ `$params.Urlpath = `$module Download-MediaServerFile @Params write-verbose "`$(`$params.Urlpath)" } } if(-NOT `$NoRun){ #Run WHAM normally or with custom params if specified if(`$CustomWHAMParams){ & `$env:tmp\wham_controller.ps1 @CustomWHAMParams }else{ if(`$dev){ & `$env:tmp\wham_controller.ps1 -runlocal -showmenu -dev }else{ & `$env:tmp\wham_controller.ps1 -runlocal -showmenu } } } } "@ if(-NOT (Test-Path $profile)){ New-Item -ItemType File -Path $profile -Force | Out-Null $UpdateProfile = $true } If(Test-Path $WHAMModule){ Remove-Item $WHAMModule -Force } New-Item -ItemType File -Path $WHAMModule -Force | Out-Null foreach ($line in $Functions){ [IO.File]::WriteAllText("$WHAMModule","`r`n$line"),[Text.Encoding]::ASCII | Out-Null } $ProfileContents = Get-Content $profile $Content = $ProfileContents | Where-Object {$_ -like "*\WHAM.psm1*"} If (-NOT $Content){ Add-Content -Path $profile -Value "`$FolderPath = `$profile | Split-Path -Parent ; Import-Module `$FolderPath\WHAM.psm1" }