From a7b479e7fb7abad6c51f537953ad88b8ecc6ac77 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 2 Jan 2023 09:18:24 +0100 Subject: [PATCH] feature/auto-format-code --- Loader.ps1 | 10 +- PostInstall/PostInstall.ps1 | 459 +++++++++--------- PreInstall/Automatic-Shutdown.ps1 | 123 ++--- PreInstall/Clear-Proxy.ps1 | 341 ++++++------- .../CreateAutomaticShutdownScheduledTask.ps1 | 19 +- PreInstall/CreateClearProxyScheduledTask.ps1 | 59 +-- .../CreateOneHourWarningScheduledTask.ps1 | 39 +- PreInstall/NetworkRestore.ps1 | 95 ++-- PreInstall/OneHour.ps1 | 20 +- PreInstall/ShowDialog.ps1 | 140 +++--- PreInstall/TeamMachineSetup.ps1 | 153 +++--- PreInstall/WarningMessage.ps1 | 28 +- 12 files changed, 752 insertions(+), 734 deletions(-) diff --git a/Loader.ps1 b/Loader.ps1 index 11d7f15..41c18ad 100644 --- a/Loader.ps1 +++ b/Loader.ps1 @@ -1,5 +1,5 @@ cls - Write-Host -foregroundcolor red " +Write-Host -foregroundcolor red " ((////// #######////// ##########(/////. @@ -54,11 +54,11 @@ " Write-Output "Setting up Environment" $path = [Environment]::GetFolderPath("Desktop") -if((Test-Path -Path $path\ParsecTemp ) -eq $true){ - } +if ((Test-Path -Path $path\ParsecTemp ) -eq $true) { +} Else { - New-Item -Path $path\ParsecTemp -ItemType directory| Out-Null - } + New-Item -Path $path\ParsecTemp -ItemType directory | Out-Null +} Unblock-File -Path .\* copy-Item .\* -Destination $path\ParsecTemp\ -Force -Recurse | Out-Null diff --git a/PostInstall/PostInstall.ps1 b/PostInstall/PostInstall.ps1 index 0c89281..039868d 100644 --- a/PostInstall/PostInstall.ps1 +++ b/PostInstall/PostInstall.ps1 @@ -1,6 +1,6 @@ param ( [switch]$DontPromptPasswordUpdateGPU - ) +) $host.ui.RawUI.WindowTitle = "Parsec Cloud Preparation Tool" @@ -9,11 +9,11 @@ $host.ui.RawUI.WindowTitle = "Parsec Cloud Preparation Tool" Function ProgressWriter { param ( - [int]$percentcomplete, - [string]$status + [int]$percentcomplete, + [string]$status ) Write-Progress -Activity "Setting Up Your Machine" -Status $status -PercentComplete $PercentComplete - } +} $path = [Environment]::GetFolderPath("Desktop") $currentusersid = Get-LocalUser "$env:USERNAME" | Select-Object SID | ft -HideTableHeaders | Out-String | ForEach-Object { $_.Trim() } @@ -21,72 +21,72 @@ $currentusersid = Get-LocalUser "$env:USERNAME" | Select-Object SID | ft -HideTa #Creating Folders and moving script files into System directories function setupEnvironment { ProgressWriter -Status "Moving files and folders into place" -PercentComplete $PercentComplete - if((Test-Path -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Startup) -eq $true) {} Else {New-Item -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Startup -ItemType directory | Out-Null} - if((Test-Path -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown) -eq $true) {} Else {New-Item -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown -ItemType directory | Out-Null} - if((Test-Path -Path $env:ProgramData\ParsecLoader) -eq $true) {} Else {New-Item -Path $env:ProgramData\ParsecLoader -ItemType directory | Out-Null} - if((Test-Path C:\Windows\system32\GroupPolicy\Machine\Scripts\psscripts.ini) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\psscripts.ini -Destination C:\Windows\system32\GroupPolicy\Machine\Scripts} - if((Test-Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown\NetworkRestore.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\NetworkRestore.ps1 -Destination C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown} - if((Test-Path $env:ProgramData\ParsecLoader\clear-proxy.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\clear-proxy.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\CreateClearProxyScheduledTask.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\CreateClearProxyScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\Automatic-Shutdown.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\Automatic-Shutdown.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\CreateAutomaticShutdownScheduledTask.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\CreateAutomaticShutdownScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\GPU-Update.ico) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\GPU-Update.ico -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\CreateOneHourWarningScheduledTask.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\CreateOneHourWarningScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\WarningMessage.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\WarningMessage.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\Parsec.png) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\Parsec.png -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\ShowDialog.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\ShowDialog.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\OneHour.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\OneHour.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\TeamMachineSetup.ps1) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\TeamMachineSetup.ps1 -Destination $env:ProgramData\ParsecLoader} - if((Test-Path $env:ProgramData\ParsecLoader\parsecpublic.cer) -eq $true) {} Else {Move-Item -Path $path\ParsecTemp\PreInstall\parsecpublic.cer -Destination $env:ProgramData\ParsecLoader} - } + if ((Test-Path -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Startup) -eq $true) {} Else { New-Item -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Startup -ItemType directory | Out-Null } + if ((Test-Path -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown) -eq $true) {} Else { New-Item -Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown -ItemType directory | Out-Null } + if ((Test-Path -Path $env:ProgramData\ParsecLoader) -eq $true) {} Else { New-Item -Path $env:ProgramData\ParsecLoader -ItemType directory | Out-Null } + if ((Test-Path C:\Windows\system32\GroupPolicy\Machine\Scripts\psscripts.ini) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\psscripts.ini -Destination C:\Windows\system32\GroupPolicy\Machine\Scripts } + if ((Test-Path C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown\NetworkRestore.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\NetworkRestore.ps1 -Destination C:\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown } + if ((Test-Path $env:ProgramData\ParsecLoader\clear-proxy.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\clear-proxy.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\CreateClearProxyScheduledTask.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\CreateClearProxyScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\Automatic-Shutdown.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\Automatic-Shutdown.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\CreateAutomaticShutdownScheduledTask.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\CreateAutomaticShutdownScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\GPU-Update.ico) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\GPU-Update.ico -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\CreateOneHourWarningScheduledTask.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\CreateOneHourWarningScheduledTask.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\WarningMessage.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\WarningMessage.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\Parsec.png) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\Parsec.png -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\ShowDialog.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\ShowDialog.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\OneHour.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\OneHour.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\TeamMachineSetup.ps1) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\TeamMachineSetup.ps1 -Destination $env:ProgramData\ParsecLoader } + if ((Test-Path $env:ProgramData\ParsecLoader\parsecpublic.cer) -eq $true) {} Else { Move-Item -Path $path\ParsecTemp\PreInstall\parsecpublic.cer -Destination $env:ProgramData\ParsecLoader } +} function cloudprovider { #finds the cloud provider that this VM is hosted by $gcp = $( - try { - (Invoke-WebRequest -uri http://metadata.google.internal/computeMetadata/v1/ -Method GET -header @{'metadata-flavor'='Google'} -TimeoutSec 5) - } - catch { - } - ) + try { + (Invoke-WebRequest -uri http://metadata.google.internal/computeMetadata/v1/ -Method GET -header @{'metadata-flavor' = 'Google' } -TimeoutSec 5) + } + catch { + } + ) $aws = $( - Try { + Try { (Invoke-WebRequest -uri http://169.254.169.254/latest/meta-data/ -TimeoutSec 5) - } - catch { - } - ) + } + catch { + } + ) $paperspace = $( - Try { + Try { (Invoke-WebRequest -uri http://metadata.paperspace.com/meta-data/machine -TimeoutSec 5) - } - catch { - } - ) + } + catch { + } + ) $azure = $( - Try {(Invoke-Webrequest -Headers @{"Metadata"="true"} -Uri "http://169.254.169.254/metadata/instance/compute/userData?api-version=2021-01-01&format=text" -TimeoutSec 5)} - catch {} - ) + Try { (Invoke-Webrequest -Headers @{"Metadata" = "true" } -Uri "http://169.254.169.254/metadata/instance/compute/userData?api-version=2021-01-01&format=text" -TimeoutSec 5) } + catch {} + ) if ($GCP.StatusCode -eq 200) { "Google Cloud Instance" - } + } Elseif ($AWS.StatusCode -eq 200) { "Amazon AWS Instance" - } + } Elseif ($paperspace.StatusCode -eq 200) { "Paperspace Instance" - } + } Elseif ($azure.StatusCode -eq 200) { "Microsoft Azure Instance" - } + } Else { "Generic Instance" - } + } } @@ -267,14 +267,14 @@ Function TestCredential { ) try { Start-Process -FilePath cmd.exe /c -Credential ($Credential) - } + } Catch { If ($Error[0].Exception.Message) { - $Error[0].Exception.Message - Throw - } + $Error[0].Exception.Message + Throw } } +} function Set-AutoLogon { [CmdletBinding(SupportsShouldProcess)] @@ -285,13 +285,13 @@ function Set-AutoLogon { Try { if ($Credential.GetNetworkCredential().Domain) { $DefaultDomainName = $Credential.GetNetworkCredential().Domain - } + } elseif ((Get-WMIObject Win32_ComputerSystem).PartOfDomain) { $DefaultDomainName = "." - } + } else { $DefaultDomainName = "" - } + } if ($PSCmdlet.ShouldProcess(('User "{0}\{1}"' -f $DefaultDomainName, $Credential.GetNetworkCredential().Username), "Set Auto logon")) { Write-Verbose ('DomainName: {0} / UserName: {1}' -f $DefaultDomainName, $Credential.GetNetworkCredential().Username) @@ -304,12 +304,12 @@ function Set-AutoLogon { $LsaUtil.SetSecret($Credential.GetNetworkCredential().Password) "Auto Logon Configured" Remove-Variable Credential - } + } } Catch { $Error[0].Exception.Message Throw - } + } } @@ -318,45 +318,45 @@ Function GetInstanceCredential { $Credential = Get-Credential -Credential $null Try { TestCredential -Credential $Credential - } + } Catch { - Remove-Variable Credential - #$Error[0].Exception.Message - "Retry?" - $Retry = Read-Host "(Y/N)" - Switch ($Retry){ - Y { - GetInstanceCredential - } - N { - Return - } - } + Remove-Variable Credential + #$Error[0].Exception.Message + "Retry?" + $Retry = Read-Host "(Y/N)" + Switch ($Retry) { + Y { + GetInstanceCredential + } + N { + Return + } } } + } Catch { - if ($Credential) {Remove-Variable Credential} + if ($Credential) { Remove-Variable Credential } "You pressed cancel, retry?" $Cancel = Read-Host "(Y/N)" - Switch ($Cancel){ + Switch ($Cancel) { Y { GetInstanceCredential - } + } N { Return - } } } - if($credential) {Set-AutoLogon -Credential $Credential} } + if ($credential) { Set-AutoLogon -Credential $Credential } +} Function PromptUserAutoLogon { -param ( -[switch]$DontPromptPasswordUpdateGPU -) -$CloudProvider = CloudProvider + param ( + [switch]$DontPromptPasswordUpdateGPU + ) + $CloudProvider = CloudProvider If ($DontPromptPasswordUpdateGPU) { - } + } ElseIf ($CloudProvider -eq "Paperspace") { } Else { @@ -367,16 +367,15 @@ Do you want this computer to log on to Windows automatically? (N): If you plan to log into Windows with RDP then connect via Parsec, or have been told you don't need to set this up "@ -ForegroundColor Black -BackgroundColor Red $ReadHost = Read-Host "(Y/N)" - Switch ($ReadHost) - { + Switch ($ReadHost) { Y { GetInstanceCredential - } + } N { - } } } } +} @@ -392,49 +391,49 @@ function add-gpo-modifications { $GPO = $gptstring -match "gPCMachineExtensionNames" $add = '[{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{40B6664F-4972-11D1-A7CA-0000F87571E3}]' $replace = "$GPO" + "$add" - (Get-Content "C:\Windows\System32\GroupPolicy\gpt.ini").Replace("$GPO","$replace") | Set-Content "C:\Windows\System32\GroupPolicy\gpt.ini" + (Get-Content "C:\Windows\System32\GroupPolicy\gpt.ini").Replace("$GPO", "$replace") | Set-Content "C:\Windows\System32\GroupPolicy\gpt.ini" [int]$i = $gpoversion.trim("Version=") [int]$n = $gpoversion.trim("Version=") - $n +=2 + $n += 2 (Get-Content C:\Windows\System32\GroupPolicy\gpt.ini) -replace "Version=$i", "Version=$n" | Set-Content C:\Windows\System32\GroupPolicy\gpt.ini - } - else{ + } + else { write-output "Not Required" - } } +} #Adds Premade Group Policu Item if existing configuration doesn't exist -function addRegItems{ +function addRegItems { ProgressWriter -Status "Adding Registry Items and Group Policy" -PercentComplete $PercentComplete if (Test-Path ("C:\Windows\system32\GroupPolicy" + "\gpt.ini")) { add-gpo-modifications - } + } Else { Move-Item -Path $path\ParsecTemp\PreInstall\gpt.ini -Destination C:\Windows\system32\GroupPolicy -Force | Out-Null - } + } regedit /s $path\ParsecTemp\PreInstall\NetworkRestore.reg regedit /s $path\ParsecTemp\PreInstall\ForceCloseShutDown.reg New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null - } +} function Test-RegistryValue { # https://www.jonathanmedd.net/2014/02/testing-for-the-presence-of-a-registry-key-and-value.html param ( - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Path, + [parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()]$Path, - [parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()]$Value + [parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()]$Value ) try { Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null return $true - } + } catch { return $false - } + } } @@ -442,11 +441,11 @@ function Test-RegistryValue { #Create ParsecTemp folder in C Drive function create-directories { ProgressWriter -Status "Creating Directories (C:\ParsecTemp)" -PercentComplete $PercentComplete - if((Test-Path -Path C:\ParsecTemp) -eq $true) {} Else {New-Item -Path C:\ParsecTemp -ItemType directory | Out-Null} - if((Test-Path -Path C:\ParsecTemp\Apps) -eq $true) {} Else {New-Item -Path C:\ParsecTemp\Apps -ItemType directory | Out-Null} - if((Test-Path -Path C:\ParsecTemp\DirectX) -eq $true) {} Else {New-Item -Path C:\ParsecTemp\DirectX -ItemType directory | Out-Null} - if((Test-Path -Path C:\ParsecTemp\Drivers) -eq $true) {} Else {New-Item -Path C:\ParsecTemp\Drivers -ItemType Directory | Out-Null} - } + if ((Test-Path -Path C:\ParsecTemp) -eq $true) {} Else { New-Item -Path C:\ParsecTemp -ItemType directory | Out-Null } + if ((Test-Path -Path C:\ParsecTemp\Apps) -eq $true) {} Else { New-Item -Path C:\ParsecTemp\Apps -ItemType directory | Out-Null } + if ((Test-Path -Path C:\ParsecTemp\DirectX) -eq $true) {} Else { New-Item -Path C:\ParsecTemp\DirectX -ItemType directory | Out-Null } + if ((Test-Path -Path C:\ParsecTemp\Drivers) -eq $true) {} Else { New-Item -Path C:\ParsecTemp\Drivers -ItemType Directory | Out-Null } +} #disable IE security function disable-iesecurity { @@ -454,7 +453,7 @@ function disable-iesecurity { Set-Itemproperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -name IsInstalled -value 0 -force | Out-Null Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name IsInstalled -Value 0 -Force | Out-Null Stop-Process -Name Explorer -Force - } +} #download-files-S3 function download-resources { @@ -470,7 +469,7 @@ function download-resources { (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/parsec-cloud/Cloud-GPU-Updater/master/GPUUpdaterTool.ps1", "$env:ProgramData\ParsecLoader\GPUUpdaterTool.ps1") ProgressWriter -Status "Downloading Google Chrome" -PercentComplete $PercentComplete (New-Object System.Net.WebClient).DownloadFile("https://dl.google.com/tag/s/dl/chrome/install/googlechromestandaloneenterprise64.msi", "C:\ParsecTemp\Apps\googlechromestandaloneenterprise64.msi") - } +} #install-base-files-silently function install-windows-features { @@ -485,10 +484,10 @@ function install-windows-features { Install-WindowsFeature Net-Framework-Core | Out-Null ProgressWriter -Status "Cleaning up" -PercentComplete $PercentComplete Remove-Item -Path C:\ParsecTemp\DirectX -force -Recurse - } +} Function TeamMachineSetupScheduledTask { -$XML = @" + $XML = @" @@ -538,144 +537,144 @@ $XML = @" try { Get-ScheduledTask -TaskName "Setup Team Machine" -ErrorAction Stop | Out-Null Unregister-ScheduledTask -TaskName "Setup Team Machine" -Confirm:$false - } + } catch {} $action = New-ScheduledTaskAction -Execute 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument '-file %programdata%\ParsecLoader\TeamMachineSetup.ps1' - $trigger = New-ScheduledTaskTrigger -AtStartup + $trigger = New-ScheduledTaskTrigger -AtStartup Register-ScheduledTask -XML $XML -TaskName "Setup Team Machine" | Out-Null - } +} #set update policy function set-update-policy { ProgressWriter -Status "Disabling Windows Update" -PercentComplete $PercentComplete - if((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'DoNotConnectToWindowsUpdateInternetLocations') -eq $true) {Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "DoNotConnectToWindowsUpdateInternetLocations" -Value "1" | Out-Null} else {new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "DoNotConnectToWindowsUpdateInternetLocations" -Value "1" | Out-Null} - if((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'UpdateServiceURLAlternative') -eq $true) {Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "UpdateServiceURLAlternative" -Value "http://intentionally.disabled" | Out-Null} else {new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "UpdateServiceURLAlternative" -Value "http://intentionally.disabled" | Out-Null} - if((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'WUServer') -eq $true) {Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" -Value "http://intentionally.disabled" | Out-Null} else {new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" -Value "http://intentionally.disabled" | Out-Null} - if((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'WUSatusServer') -eq $true) {Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUSatusServer" -Value "http://intentionally.disabled" | Out-Null} else {new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUSatusServer" -Value "http://intentionally.disabled" | Out-Null} + if ((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'DoNotConnectToWindowsUpdateInternetLocations') -eq $true) { Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "DoNotConnectToWindowsUpdateInternetLocations" -Value "1" | Out-Null } else { new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "DoNotConnectToWindowsUpdateInternetLocations" -Value "1" | Out-Null } + if ((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'UpdateServiceURLAlternative') -eq $true) { Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "UpdateServiceURLAlternative" -Value "http://intentionally.disabled" | Out-Null } else { new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "UpdateServiceURLAlternative" -Value "http://intentionally.disabled" | Out-Null } + if ((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'WUServer') -eq $true) { Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" -Value "http://intentionally.disabled" | Out-Null } else { new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" -Value "http://intentionally.disabled" | Out-Null } + if ((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' -value 'WUSatusServer') -eq $true) { Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUSatusServer" -Value "http://intentionally.disabled" | Out-Null } else { new-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUSatusServer" -Value "http://intentionally.disabled" | Out-Null } Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name "AUOptions" -Value 1 | Out-Null - if((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' -value 'UseWUServer') -eq $true) {Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name "UseWUServer" -Value 1 | Out-Null} else {new-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name "UseWUServer" -Value 1 | Out-Null} - } + if ((Test-RegistryValue -path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' -value 'UseWUServer') -eq $true) { Set-itemproperty -path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name "UseWUServer" -Value 1 | Out-Null } else { new-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name "UseWUServer" -Value 1 | Out-Null } +} #set automatic time and timezone function set-time { ProgressWriter -Status "Setting computer time to automatic" -PercentComplete $PercentComplete Set-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters -Name Type -Value NTP | Out-Null Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate -Name Start -Value 00000003 | Out-Null - } +} #disable new network window function disable-network-window { ProgressWriter -Status "Disabling New Network Window" -PercentComplete $PercentComplete - if((Test-RegistryValue -path HKLM:\SYSTEM\CurrentControlSet\Control\Network -Value NewNetworkWindowOff)-eq $true) {} Else {new-itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Control\Network -name "NewNetworkWindowOff" | Out-Null} - } + if ((Test-RegistryValue -path HKLM:\SYSTEM\CurrentControlSet\Control\Network -Value NewNetworkWindowOff) -eq $true) {} Else { new-itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Control\Network -name "NewNetworkWindowOff" | Out-Null } +} #Enable Pointer Precision function enhance-pointer-precision { ProgressWriter -Status "Enabling enchanced pointer precision" -PercentComplete $PercentComplete Set-Itemproperty -Path 'HKCU:\Control Panel\Mouse' -Name MouseSpeed -Value 1 | Out-Null - } +} #enable Mouse Keys function enable-mousekeys { ProgressWriter -Status "Enabling mouse keys to assist with mouse cursor" -PercentComplete $PercentComplete set-Itemproperty -Path 'HKCU:\Control Panel\Accessibility\MouseKeys' -Name Flags -Value 63 | Out-Null - } +} #disable shutdown start menu function remove-shutdown { Write-Output "Disabling Shutdown Option in Start Menu" New-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name NoClose -Value 1 | Out-Null - } +} #Sets all applications to force close on shutdown function force-close-apps { ProgressWriter -Status "Setting Windows not to stop shutdown if there are unsaved apps" -PercentComplete $PercentComplete if (((Get-Item -Path "HKCU:\Control Panel\Desktop").GetValue("AutoEndTasks") -ne $null) -eq $true) { Set-ItemProperty -path "HKCU:\Control Panel\Desktop" -Name "AutoEndTasks" -Value "1" - } + } Else { New-ItemProperty -path "HKCU:\Control Panel\Desktop" -Name "AutoEndTasks" -Value "1" - } } +} #show hidden items function show-hidden-items { ProgressWriter -Status "Showing hidden files in Windows Explorer" -PercentComplete $PercentComplete set-itemproperty -path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name Hidden -Value 1 | Out-Null - } +} #show file extensions function show-file-extensions { ProgressWriter -Status "Showing file extensions in Windows Explorer" -PercentComplete $PercentComplete Set-itemproperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -name HideFileExt -Value 0 | Out-Null - } +} #disable logout start menu function disable-logout { ProgressWriter -Status "Disabling log out button on start menu" -PercentComplete $PercentComplete - if((Test-RegistryValue -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Value StartMenuLogOff )-eq $true) {Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name StartMenuLogOff -Value 1 | Out-Null} Else {New-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name StartMenuLogOff -Value 1 | Out-Null} - } + if ((Test-RegistryValue -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Value StartMenuLogOff ) -eq $true) { Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name StartMenuLogOff -Value 1 | Out-Null } Else { New-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name StartMenuLogOff -Value 1 | Out-Null } +} #disable lock start menu function disable-lock { ProgressWriter -Status "Disabling option to lock your Windows user profile" -PercentComplete $PercentComplete - if((Test-Path -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System) -eq $true) {} Else {New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies -Name Software | Out-Null} - if((Test-RegistryValue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Value DisableLockWorkstation) -eq $true) {Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableLockWorkstation -Value 1 | Out-Null } Else {New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableLockWorkstation -Value 1 | Out-Null} - } + if ((Test-Path -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System) -eq $true) {} Else { New-Item -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies -Name Software | Out-Null } + if ((Test-RegistryValue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Value DisableLockWorkstation) -eq $true) { Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableLockWorkstation -Value 1 | Out-Null } Else { New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name DisableLockWorkstation -Value 1 | Out-Null } +} #set wallpaper function set-wallpaper { ProgressWriter -Status "Setting the Parsec logo ass the computer wallpaper" -PercentComplete $PercentComplete - if((Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System) -eq $true) {} Else {New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies" -Name "System" | Out-Null} - if((Test-RegistryValue -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -value Wallpaper) -eq $true) {Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name Wallpaper -value "C:\ParsecTemp\parsec+desktop.png" | Out-Null} Else {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name Wallpaper -PropertyType String -value "C:\ParsecTemp\parsec+desktop.png" | Out-Null} - if((Test-RegistryValue -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -value WallpaperStyle) -eq $true) {Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name WallpaperStyle -value 2 | Out-Null} Else {New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name WallpaperStyle -PropertyType String -value 2 | Out-Null} + if ((Test-Path -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System) -eq $true) {} Else { New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies" -Name "System" | Out-Null } + if ((Test-RegistryValue -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -value Wallpaper) -eq $true) { Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name Wallpaper -value "C:\ParsecTemp\parsec+desktop.png" | Out-Null } Else { New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name Wallpaper -PropertyType String -value "C:\ParsecTemp\parsec+desktop.png" | Out-Null } + if ((Test-RegistryValue -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -value WallpaperStyle) -eq $true) { Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name WallpaperStyle -value 2 | Out-Null } Else { New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\System -Name WallpaperStyle -PropertyType String -value 2 | Out-Null } Stop-Process -ProcessName explorer - } +} #disable recent start menu items function disable-recent-start-menu { New-Item -path HKLM:\SOFTWARE\Policies\Microsoft\Windows -name Explorer New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer -PropertyType DWORD -Name HideRecentlyAddedApps -Value 1 - } +} #createshortcut -function Create-AutoShutdown-Shortcut{ +function Create-AutoShutdown-Shortcut { ProgressWriter -Status "Creating auto shutdown shortcut" -PercentComplete $PercentComplete $Shell = New-Object -ComObject ("WScript.Shell") $ShortCut = $Shell.CreateShortcut("$env:USERPROFILE\Desktop\Setup Auto Shutdown.lnk") - $ShortCut.TargetPath="powershell.exe" - $ShortCut.Arguments='-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\CreateAutomaticShutdownScheduledTask.ps1"' + $ShortCut.TargetPath = "powershell.exe" + $ShortCut.Arguments = '-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\CreateAutomaticShutdownScheduledTask.ps1"' $ShortCut.WorkingDirectory = "$env:ProgramData\ParsecLoader"; $ShortCut.WindowStyle = 0; $ShortCut.Description = "ClearProxy shortcut"; $ShortCut.Save() - } +} #createshortcut -function Create-One-Hour-Warning-Shortcut{ +function Create-One-Hour-Warning-Shortcut { ProgressWriter -Status "Creating one hour warning shortcut" -PercentComplete $PercentComplete $Shell = New-Object -ComObject ("WScript.Shell") $ShortCut = $Shell.CreateShortcut("$env:USERPROFILE\Desktop\Setup One Hour Warning.lnk") - $ShortCut.TargetPath="powershell.exe" - $ShortCut.Arguments='-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\CreateOneHourWarningScheduledTask.ps1"' + $ShortCut.TargetPath = "powershell.exe" + $ShortCut.Arguments = '-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\CreateOneHourWarningScheduledTask.ps1"' $ShortCut.WorkingDirectory = "$env:ProgramData\ParsecLoader"; $ShortCut.WindowStyle = 0; $ShortCut.Description = "OneHourWarning shortcut"; $ShortCut.Save() - } +} #Disables Server Manager opening on Startup function disable-server-manager { ProgressWriter -Status "Disabling Windows Server Manager from starting at startup" -PercentComplete $PercentComplete Get-ScheduledTask -TaskName ServerManager | Disable-ScheduledTask | Out-Null - } +} #AWS Clean up Desktop Items function clean-aws { remove-item -path "$path\EC2 Feedback.Website" Remove-Item -Path "$path\EC2 Microsoft Windows Guide.website" - } +} <# #Move extracts Razer Surround Files into correct location Function ExtractRazerAudio { @@ -689,9 +688,9 @@ Function ModidifyManifest { (Get-Content $InstallerManifest) -replace $regex, 'true' | Set-Content $InstallerManifest -Encoding UTF8 #> - #Audio Driver Install +#Audio Driver Install function AudioInstall { -<# + <# (New-Object System.Net.WebClient).DownloadFile("http://rzr.to/surround-pc-download", "C:\ParsecTemp\Apps\razer-surround-driver.exe") ExtractRazerAudio ModidifyManifest @@ -702,7 +701,7 @@ function AudioInstall { Set-Service -Name audiosrv -StartupType Automatic #> (New-Object System.Net.WebClient).DownloadFile("https://download.vb-audio.com/Download_CABLE/VBCABLE_Driver_Pack43.zip", "C:\ParsecTemp\Apps\VBCable.zip") - New-Item -Path "C:\ParsecTemp\Apps\VBCable" -ItemType Directory| Out-Null + New-Item -Path "C:\ParsecTemp\Apps\VBCable" -ItemType Directory | Out-Null Expand-Archive -Path "C:\ParsecTemp\Apps\VBCable.zip" -DestinationPath "C:\ParsecTemp\Apps\VBCable" $pathToCatFile = "C:\ParsecTemp\Apps\VBCable\vbaudio_cable64_win7.cat" $FullCertificateExportPath = "C:\ParsecTemp\Apps\VBCable\VBCert.cer" @@ -713,10 +712,10 @@ function AudioInstall { $VB.Cert = (Get-AuthenticodeSignature -filepath $VB.DriverFile).SignerCertificate; [System.IO.File]::WriteAllBytes($VB.CertName, $VB.Cert.Export($VB.ExportType)) Import-Certificate -CertStoreLocation Cert:\LocalMachine\TrustedPublisher -FilePath $VB.CertName | Out-Null - Start-Process -FilePath "C:\ParsecTemp\Apps\VBCable\VBCABLE_Setup_x64.exe" -ArgumentList '-i','-h' + Start-Process -FilePath "C:\ParsecTemp\Apps\VBCable\VBCABLE_Setup_x64.exe" -ArgumentList '-i', '-h' Set-Service -Name audiosrv -StartupType Automatic Start-Service -Name audiosrv - } +} #Creates shortcut for the GPU Updater tool function gpu-update-shortcut { @@ -725,88 +724,88 @@ function gpu-update-shortcut { ProgressWriter -Status "Creating GPU Updater icon on Desktop" -PercentComplete $PercentComplete $Shell = New-Object -ComObject ("WScript.Shell") $ShortCut = $Shell.CreateShortcut("$path\GPU Updater.lnk") - $ShortCut.TargetPath="powershell.exe" - $ShortCut.Arguments='-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\GPUUpdaterTool.ps1"' + $ShortCut.TargetPath = "powershell.exe" + $ShortCut.Arguments = '-ExecutionPolicy Bypass -File "C:\ProgramData\ParsecLoader\GPUUpdaterTool.ps1"' $ShortCut.WorkingDirectory = "$env:ProgramData\ParsecLoader"; $ShortCut.IconLocation = "$env:ProgramData\ParsecLoader\GPU-Update.ico, 0"; $ShortCut.WindowStyle = 0; $ShortCut.Description = "GPU Updater shortcut"; $ShortCut.Save() - } +} #Provider specific driver install and setup Function provider-specific { ProgressWriter -Status "Installing VB CAble Audio Driver if required and removing system information from appearing on Google Cloud Desktops" -PercentComplete $PercentComplete #Device ID Query - $gputype = Get-PnpDevice | Where-Object {($_.DeviceID -like 'PCI\VEN_10DE*' -or $_.DeviceID -like '*PCI\VEN_1002*') -and ($_.PNPClass -eq 'Display' -or $_.Name -like '*Video Controller')} | Select-Object InstanceID -ExpandProperty InstanceID + $gputype = Get-PnpDevice | Where-Object { ($_.DeviceID -like 'PCI\VEN_10DE*' -or $_.DeviceID -like '*PCI\VEN_1002*') -and ($_.PNPClass -eq 'Display' -or $_.Name -like '*Video Controller') } | Select-Object InstanceID -ExpandProperty InstanceID if ($gputype -eq $null) { - } + } Else { - if($gputype.substring(13,8) -eq "DEV_13F2") { + if ($gputype.substring(13, 8) -eq "DEV_13F2") { #AWS G3.4xLarge M60 AudioInstall - } - ElseIF($gputype.Substring(13,8) -eq "DEV_118A"){ + } + ElseIF ($gputype.Substring(13, 8) -eq "DEV_118A") { #AWS G2.2xLarge K520 AudioInstall - } - ElseIF($gputype.Substring(13,8) -eq "DEV_1BB1") { + } + ElseIF ($gputype.Substring(13, 8) -eq "DEV_1BB1") { #Paperspace P4000 - } - Elseif($gputype.Substring(13,8) -eq "DEV_1BB0") { + } + Elseif ($gputype.Substring(13, 8) -eq "DEV_1BB0") { #Paperspace P5000 - } - Elseif($gputype.substring(13,8) -eq "DEV_15F8") { + } + Elseif ($gputype.substring(13, 8) -eq "DEV_15F8") { #Tesla P100 - if((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) {remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe"} Else {} - if((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) {Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk"} Else {} + if ((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) { remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe" } Else {} + if ((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) { Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk" } Else {} AudioInstall - } - Elseif($gputype.substring(13,8) -eq "DEV_1BB3") { + } + Elseif ($gputype.substring(13, 8) -eq "DEV_1BB3") { #Tesla P4 - if((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) {remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe"} Else {} - if((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) {Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk"} Else {} + if ((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) { remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe" } Else {} + if ((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) { Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk" } Else {} AudioInstall - } - Elseif($gputype.substring(13,8) -eq "DEV_1EB8") { + } + Elseif ($gputype.substring(13, 8) -eq "DEV_1EB8") { #Tesla T4 - if((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) {remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe"} Else {} - if((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) {Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk"} Else {} + if ((Test-Path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe") -eq $true) { remove-item -path "C:\Program Files\Google\Compute Engine\tools\BGInfo.exe" } Else {} + if ((Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk") -eq $true) { Remove-Item -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\BGinfo.lnk" } Else {} AudioInstall - } - Elseif($gputype.substring(13,8) -eq "DEV_1430") { + } + Elseif ($gputype.substring(13, 8) -eq "DEV_1430") { #Quadro M2000 AudioInstall - } - Elseif($gputype.substring(13,8) -eq "DEV_7362") { + } + Elseif ($gputype.substring(13, 8) -eq "DEV_7362") { #AMD V520 AudioInstall } Else { - } } } +} #7Zip is required to extract the Parsec-Windows.exe File function Install7Zip { $url = Invoke-WebRequest -Uri https://www.7-zip.org/download.html - (New-Object System.Net.WebClient).DownloadFile("https://www.7-zip.org/$($($($url.Links | Where-Object outertext -Like "Download")[1]).OuterHTML.split('"')[1])" ,"C:\ParsecTemp\Apps\7zip.exe") + (New-Object System.Net.WebClient).DownloadFile("https://www.7-zip.org/$($($($url.Links | Where-Object outertext -Like "Download")[1]).OuterHTML.split('"')[1])" , "C:\ParsecTemp\Apps\7zip.exe") Start-Process C:\ParsecTemp\Apps\7zip.exe -ArgumentList '/S /D="C:\Program Files\7-Zip"' -Wait - } +} Function Server2019Controller { ProgressWriter -Status "Adding Xbox 360 Controller driver to Windows Server 2019" -PercentComplete $PercentComplete if ((gwmi win32_operatingsystem | % caption) -like '*Windows Server 2019*') { (New-Object System.Net.WebClient).DownloadFile("http://www.download.windowsupdate.com/msdownload/update/v3-19990518/cabpool/2060_8edb3031ef495d4e4247e51dcb11bef24d2c4da7.cab", "C:\ParsecTemp\Drivers\Xbox360_64Eng.cab") - if((Test-Path -Path C:\ParsecTemp\Drivers\Xbox360_64Eng) -eq $true) {} Else {New-Item -Path C:\ParsecTemp\Drivers\Xbox360_64Eng -ItemType directory | Out-Null} + if ((Test-Path -Path C:\ParsecTemp\Drivers\Xbox360_64Eng) -eq $true) {} Else { New-Item -Path C:\ParsecTemp\Drivers\Xbox360_64Eng -ItemType directory | Out-Null } cmd.exe /c "C:\Windows\System32\expand.exe C:\ParsecTemp\Drivers\Xbox360_64Eng.cab -F:* C:\ParsecTemp\Drivers\Xbox360_64Eng" | Out-Null cmd.exe /c '"C:\Program Files\Parsec\vigem\10\x64\devcon.exe" dp_add "C:\ParsecTemp\Drivers\Xbox360_64Eng\xusb21.inf"' | Out-Null - } } +} Function InstallParsec { Start-Process "C:\ParsecTemp\Apps\parsec-windows.exe" -ArgumentList "/silent", "/shared" -wait - } +} Function InstallParsecVDD { ProgressWriter -Status "Installing Parsec Virtual Display Driver" -PercentComplete $PercentComplete @@ -816,11 +815,11 @@ Function InstallParsecVDD { do { Start-Sleep -s 2 $iterator++ - } - Until (($null -ne ((Get-PnpDevice | Where-Object {$_.Name -eq "Parsec Virtual Display Adapter"}).DeviceID)) -or ($iterator -gt 7)) + } + Until (($null -ne ((Get-PnpDevice | Where-Object { $_.Name -eq "Parsec Virtual Display Adapter" }).DeviceID)) -or ($iterator -gt 7)) if (Get-process -name parsec-vdd -ErrorAction SilentlyContinue) { Stop-Process -name parsec-vdd -Force - } + } $configfile = Get-Content C:\ProgramData\Parsec\config.txt $configfile += "host_virtual_monitors = 1" $configfile += "host_privacy_mode = 1" @@ -835,45 +834,45 @@ function Install-Gaming-Apps { #if((Test-RegistryValue -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run -value "Parsec.App.0") -eq $true) {Set-ItemProperty -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run -Name "Parsec.App.0" -Value "C:\Program Files\Parsec\parsecd.exe" | Out-Null} Else {New-ItemProperty -path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run -Name "Parsec.App.0" -Value "C:\Program Files\Parsec\parsecd.exe" | Out-Null} Start-Process -FilePath "C:\Program Files\Parsec\parsecd.exe" Start-Sleep -s 1 - } +} #Disable Devices function disable-devices { ProgressWriter -Status "Disabling Microsoft Basic Display Adapter, Generic Non PNP Monitor and other devices" -PercentComplete $PercentComplete Start-Process -FilePath "C:\Program Files\Parsec\vigem\10\x64\devcon.exe" -ArgumentList '/r disable "HDAUDIO\FUNC_01&VEN_10DE&DEV_0083&SUBSYS_10DE11A3*"' - Get-PnpDevice | where {$_.friendlyname -like "Generic Non-PNP Monitor" -and $_.status -eq "OK"} | Disable-PnpDevice -confirm:$false - Get-PnpDevice | where {$_.friendlyname -like "Microsoft Basic Display Adapter" -and $_.status -eq "OK"} | Disable-PnpDevice -confirm:$false - Get-PnpDevice | where {$_.friendlyname -like "Google Graphics Array (GGA)" -and $_.status -eq "OK"} | Disable-PnpDevice -confirm:$false - Get-PnpDevice | where {$_.friendlyname -like "Microsoft Hyper-V Video" -and $_.status -eq "OK"} | Disable-PnpDevice -confirm:$false + Get-PnpDevice | where { $_.friendlyname -like "Generic Non-PNP Monitor" -and $_.status -eq "OK" } | Disable-PnpDevice -confirm:$false + Get-PnpDevice | where { $_.friendlyname -like "Microsoft Basic Display Adapter" -and $_.status -eq "OK" } | Disable-PnpDevice -confirm:$false + Get-PnpDevice | where { $_.friendlyname -like "Google Graphics Array (GGA)" -and $_.status -eq "OK" } | Disable-PnpDevice -confirm:$false + Get-PnpDevice | where { $_.friendlyname -like "Microsoft Hyper-V Video" -and $_.status -eq "OK" } | Disable-PnpDevice -confirm:$false Start-Process -FilePath "C:\Program Files\Parsec\vigem\10\x64\devcon.exe" -ArgumentList '/r disable "PCI\VEN_1013&DEV_00B8*"' Start-Process -FilePath "C:\Program Files\Parsec\vigem\10\x64\devcon.exe" -ArgumentList '/r disable "PCI\VEN_1D0F&DEV_1111*"' Start-Process -FilePath "C:\Program Files\Parsec\vigem\10\x64\devcon.exe" -ArgumentList '/r disable "PCI\VEN_1AE0&DEV_A002*"' - } +} #Cleanup function clean-up { ProgressWriter -Status "Deleting temporary files from C:\ParsecTemp" -PercentComplete $PercentComplete Remove-Item -Path C:\ParsecTemp\Drivers -force -Recurse Remove-Item -Path $path\ParsecTemp -force -Recurse - } +} #cleanup recent files function clean-up-recent { ProgressWriter -Status "Delete recently accessed files list from Windows Explorer" -PercentComplete $PercentComplete remove-item "$env:AppData\Microsoft\Windows\Recent\*" -Recurse -Force | Out-Null - } +} #Start GPU Update Tool Function StartGPUUpdate { param( - [switch]$DontPromptPasswordUpdateGPU + [switch]$DontPromptPasswordUpdateGPU ) if ($DontPromptPasswordUpdateGPU) { - } + } Else { - start-process powershell.exe -verb RunAS -argument "-file $env:ProgramData\ParsecLoader\GPUUpdaterTool.ps1" - } + start-process powershell.exe -verb RunAS -argument "-file $env:ProgramData\ParsecLoader\GPUUpdaterTool.ps1" } +} Write-Host -foregroundcolor red " ((////// #######////// @@ -928,40 +927,40 @@ Write-Host -foregroundcolor red " " #PromptUserAutoLogon -DontPromptPasswordUpdateGPU:$DontPromptPasswordUpdateGPU $ScripttaskList = @( -"setupEnvironment"; -"addRegItems"; -"create-directories"; -"disable-iesecurity"; -"download-resources"; -"install-windows-features"; -"force-close-apps"; -"disable-network-window"; -"disable-logout"; -"disable-lock"; -"show-hidden-items"; -"show-file-extensions"; -"enhance-pointer-precision"; -"enable-mousekeys"; -"set-time"; -"set-wallpaper"; -"Create-AutoShutdown-Shortcut"; -"Create-One-Hour-Warning-Shortcut"; -"disable-server-manager"; -"Install-Gaming-Apps"; -"disable-devices"; -"InstallParsecVDD"; -"Server2019Controller"; -"gpu-update-shortcut"; -"clean-up"; -"clean-up-recent"; -"provider-specific"; -"TeamMachineSetupScheduledTask" + "setupEnvironment"; + "addRegItems"; + "create-directories"; + "disable-iesecurity"; + "download-resources"; + "install-windows-features"; + "force-close-apps"; + "disable-network-window"; + "disable-logout"; + "disable-lock"; + "show-hidden-items"; + "show-file-extensions"; + "enhance-pointer-precision"; + "enable-mousekeys"; + "set-time"; + "set-wallpaper"; + "Create-AutoShutdown-Shortcut"; + "Create-One-Hour-Warning-Shortcut"; + "disable-server-manager"; + "Install-Gaming-Apps"; + "disable-devices"; + "InstallParsecVDD"; + "Server2019Controller"; + "gpu-update-shortcut"; + "clean-up"; + "clean-up-recent"; + "provider-specific"; + "TeamMachineSetupScheduledTask" ) foreach ($func in $ScripttaskList) { - $PercentComplete =$($ScriptTaskList.IndexOf($func) / $ScripttaskList.Count * 100) + $PercentComplete = $($ScriptTaskList.IndexOf($func) / $ScripttaskList.Count * 100) & $func $PercentComplete - } +} StartGPUUpdate -DontPromptPasswordUpdateGPU:$DontPromptPasswordUpdateGPU Start-ScheduledTask -TaskName "Setup Team Machine" @@ -972,6 +971,6 @@ Write-Host "2. Use GPU Updater to update your GPU Drivers!" -ForegroundColor bla Write-Host "You may want to change your Windows password to something simpler if the password your cloud provider gave you is super long" -ForegroundColor black -BackgroundColor Green Write-host "DONE!" -ForegroundColor black -BackgroundColor Green if ($DontPromptPasswordUpdateGPU) {} -Else {pause} +Else { pause } diff --git a/PreInstall/Automatic-Shutdown.ps1 b/PreInstall/Automatic-Shutdown.ps1 index 479f3bc..370efb6 100644 --- a/PreInstall/Automatic-Shutdown.ps1 +++ b/PreInstall/Automatic-Shutdown.ps1 @@ -43,94 +43,95 @@ namespace PInvoke.Win32 { '@ function AutomaticShutdown { - Add-Type -AssemblyName System.Windows.Forms + Add-Type -AssemblyName System.Windows.Forms - [System.Windows.Forms.Application]::EnableVisualStyles() - $form1 = New-Object System.Windows.Forms.Form - $label000000 = New-Object System.Windows.Forms.Label - $timer1 = New-Object System.Windows.Forms.Timer + [System.Windows.Forms.Application]::EnableVisualStyles() + $form1 = New-Object System.Windows.Forms.Form + $label000000 = New-Object System.Windows.Forms.Label + $timer1 = New-Object System.Windows.Forms.Timer $button = New-Object System.Windows.Forms.Button - $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState + $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState - $form1_Load = { - $script:countdown = [timespan]'00:10:00' # 10 minutes - $label000000.Text = "$countdown" - $timer1.Start() + $form1_Load = { + $script:countdown = [timespan]'00:10:00' # 10 minutes + $label000000.Text = "$countdown" + $timer1.Start() - } + } $button_logic = { - Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -windowstyle hidden -file $ENV:ProgramData\Automatic-Shutdown.ps1" - $form1.Close() + Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -windowstyle hidden -file $ENV:ProgramData\Automatic-Shutdown.ps1" + $form1.Close() } - $timer1_Tick = { - if ($countdown -lt [timespan]'00:00:02') {$timer1.Stop() - Stop-Computer + $timer1_Tick = { + if ($countdown -lt [timespan]'00:00:02') { + $timer1.Stop() + Stop-Computer } - Else{} - $script:countdown -= [timespan]'00:00:01' - $label000000.Text = "$countdown" + Else {} + $script:countdown -= [timespan]'00:00:01' + $label000000.Text = "$countdown" - } + } - $Form_StateCorrection_Load = - { - #Correct the initial state of the form to prevent the .Net maximized form issue - $form1.WindowState = $InitialFormWindowState - } + $Form_StateCorrection_Load = + { + #Correct the initial state of the form to prevent the .Net maximized form issue + $form1.WindowState = $InitialFormWindowState + } - $form1.SuspendLayout() + $form1.SuspendLayout() $form1.BringToFront() $Form1.ControlBox = $False - $form1.Controls.Add($label000000) - $form1.AutoScaleDimensions = '8, 17' - $form1.AutoScaleMode = 'Font' - $form1.BackColor = 'ActiveCaption' - $form1.ClientSize = '400, 200' - $form1.FormBorderStyle = 'Fixed3D' - $form1.Name = 'form1' - $form1.StartPosition = 'CenterScreen' - $form1.Text = 'Automatic Shutdown On Idle' - $form1.add_Load($form1_Load) - - $Button.Location = New-Object System.Drawing.Size(75,75) - $Button.Size = New-Object System.Drawing.Size(150,23) + $form1.Controls.Add($label000000) + $form1.AutoScaleDimensions = '8, 17' + $form1.AutoScaleMode = 'Font' + $form1.BackColor = 'ActiveCaption' + $form1.ClientSize = '400, 200' + $form1.FormBorderStyle = 'Fixed3D' + $form1.Name = 'form1' + $form1.StartPosition = 'CenterScreen' + $form1.Text = 'Automatic Shutdown On Idle' + $form1.add_Load($form1_Load) + + $Button.Location = New-Object System.Drawing.Size(75, 75) + $Button.Size = New-Object System.Drawing.Size(150, 23) $Button.Text = "Cancel Shutdown" $button.Add_click($button_logic) - $label000000.AutoSize = $True - $label000000.Font = 'Lucida Fax, 24pt, style=Bold' - $label000000.Location = '90, 25' - $label000000.Margin = '4, 0, 4, 0' - $label000000.Name = 'label000000' - $label000000.Size = '200, 46' - $label000000.TabIndex = 0 - $label000000.Text = '00:00:00' + $label000000.AutoSize = $True + $label000000.Font = 'Lucida Fax, 24pt, style=Bold' + $label000000.Location = '90, 25' + $label000000.Margin = '4, 0, 4, 0' + $label000000.Name = 'label000000' + $label000000.Size = '200, 46' + $label000000.TabIndex = 0 + $label000000.Text = '00:00:00' - $timer1.Interval = 1000 - $timer1.add_Tick($timer1_Tick) - $form1.ResumeLayout() + $timer1.Interval = 1000 + $timer1.add_Tick($timer1_Tick) + $form1.ResumeLayout() - $InitialFormWindowState = $form1.WindowState - $form1.add_Load($Form_StateCorrection_Load) + $InitialFormWindowState = $form1.WindowState + $form1.add_Load($Form_StateCorrection_Load) $Form1.Controls.Add($Button) - return $form1.ShowDialog() + return $form1.ShowDialog() } function idle { -$readfile = (Get-Content -Path $env:ProgramData\Autoshutdown.txt) - 10 -do { -[PInvoke.Win32.UserInput]::LastInput | Out-Null -[PInvoke.Win32.UserInput]::IdleTime | Out-Null -Start-Sleep -Seconds 1 -} -Until([PInvoke.Win32.UserInput]::Idletime.TotalMinutes -gt $readfile) -AutomaticShutdown + $readfile = (Get-Content -Path $env:ProgramData\Autoshutdown.txt) - 10 + do { + [PInvoke.Win32.UserInput]::LastInput | Out-Null + [PInvoke.Win32.UserInput]::IdleTime | Out-Null + Start-Sleep -Seconds 1 + } + Until([PInvoke.Win32.UserInput]::Idletime.TotalMinutes -gt $readfile) + AutomaticShutdown } idle \ No newline at end of file diff --git a/PreInstall/Clear-Proxy.ps1 b/PreInstall/Clear-Proxy.ps1 index 58eda36..765afd3 100644 --- a/PreInstall/Clear-Proxy.ps1 +++ b/PreInstall/Clear-Proxy.ps1 @@ -5,238 +5,248 @@ $size = (Get-PartitionSupportedSize -DiskNumber 0 -PartitionNumber 1) [System.Uint64]$maxpartitionsize = ($size.SizeMax).ToString() if ($($currentsize) -ge $($maxpartitionsize)) { -"Hard Drive already expanded" + "Hard Drive already expanded" } -Else -{ -Resize-Partition -DiskNumber 0 -PartitionNumber 1 -Size $size.SizeMax -"Successfully Increased Partition Size" +Else { + Resize-Partition -DiskNumber 0 -PartitionNumber 1 -Size $size.SizeMax + "Successfully Increased Partition Size" } function clear-proxy { -$value = Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -if ($value.ProxyEnable -eq 1) { -set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 0 | Out-Null -write-host "Disable proxy if required" -Start-Process "C:\Program Files\Internet Explorer\iexplore.exe" -Start-Sleep -s 5 -Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force} -Else {}} + $value = Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable + if ($value.ProxyEnable -eq 1) { + set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 0 | Out-Null + write-host "Disable proxy if required" + Start-Process "C:\Program Files\Internet Explorer\iexplore.exe" + Start-Sleep -s 5 + Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force + } + Else {} +} #fix gpu function EnableDisabledGPU { -$getdisabled = Get-WmiObject win32_pnpentity | Where-Object {$_.name -like '*NVIDIA*' -or $_.name -like '3D Video Controller' -and $_.status -like 'Error'} | Select-Object -ExpandProperty PNPDeviceID -if ($getdisabled -ne $null) {"Enabling GPU" -$var = $getdisabled.Substring(0,21) -$arguement = "/r enable"+ ' ' + "*"+ "$var"+ "*" -Start-Process -FilePath "C:\ParsecTemp\Devcon\devcon.exe" -ArgumentList $arguement -} -Else {"Device is enabled" -Start-Process -FilePath "C:\ParsecTemp\Devcon\devcon.exe" -ArgumentList '/m /r'} + $getdisabled = Get-WmiObject win32_pnpentity | Where-Object { $_.name -like '*NVIDIA*' -or $_.name -like '3D Video Controller' -and $_.status -like 'Error' } | Select-Object -ExpandProperty PNPDeviceID + if ($getdisabled -ne $null) { + "Enabling GPU" + $var = $getdisabled.Substring(0, 21) + $arguement = "/r enable" + ' ' + "*" + "$var" + "*" + Start-Process -FilePath "C:\ParsecTemp\Devcon\devcon.exe" -ArgumentList $arguement + } + Else { + "Device is enabled" + Start-Process -FilePath "C:\ParsecTemp\Devcon\devcon.exe" -ArgumentList '/m /r' + } } function installedGPUID { -#queries WMI to get DeviceID of the installed NVIDIA GPU -Try {(get-wmiobject -query "select DeviceID from Win32_PNPEntity Where (deviceid Like '%PCI\\VEN_10DE%') and (PNPClass = 'Display' or Name = '3D Video Controller')" | Select-Object DeviceID -ExpandProperty DeviceID).substring(13,8)} -Catch {return $null} + #queries WMI to get DeviceID of the installed NVIDIA GPU + Try { (get-wmiobject -query "select DeviceID from Win32_PNPEntity Where (deviceid Like '%PCI\\VEN_10DE%') and (PNPClass = 'Display' or Name = '3D Video Controller')" | Select-Object DeviceID -ExpandProperty DeviceID).substring(13, 8) } + Catch { return $null } } function driverVersion { -#Queries WMI to request the driver version, and formats it to match that of a NVIDIA Driver version number (NNN.NN) -Try {(Get-WmiObject Win32_PnPSignedDriver | where {$_.DeviceName -like "*nvidia*" -and $_.DeviceClass -like "Display"} | Select-Object -ExpandProperty DriverVersion).substring(7,6).replace('.','').Insert(3,'.')} -Catch {return $null} + #Queries WMI to request the driver version, and formats it to match that of a NVIDIA Driver version number (NNN.NN) + Try { (Get-WmiObject Win32_PnPSignedDriver | where { $_.DeviceName -like "*nvidia*" -and $_.DeviceClass -like "Display" } | Select-Object -ExpandProperty DriverVersion).substring(7, 6).replace('.', '').Insert(3, '.') } + Catch { return $null } } function osVersion { -#Requests Windows OS Friendly Name + #Requests Windows OS Friendly Name (Get-WmiObject -class Win32_OperatingSystem).Caption } -function requiresReboot{ -#Queries if system needs a reboot after driver installs -if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true } -if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true } -if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true } - try { - $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities" - $status = $util.DetermineIfRebootPending() - if(($status -ne $null) -and $status.RebootPending){ - return $true - } - }catch{} +function requiresReboot { + #Queries if system needs a reboot after driver installs + if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true } + if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true } + if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true } + try { + $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities" + $status = $util.DetermineIfRebootPending() + if (($status -ne $null) -and $status.RebootPending) { + return $true + } + } + catch {} - return $false + return $false } function validDriver { -#checks an important nvidia driver folder to see if it exits -test-path -Path "C:\Program Files\NVIDIA Corporation\NVSMI" + #checks an important nvidia driver folder to see if it exits + test-path -Path "C:\Program Files\NVIDIA Corporation\NVSMI" } Function webDriver { -#checks the latest available graphics driver from nvidia.com -if (($gpu.supported -eq "No") -eq $true) {"Sorry, this GPU (" + $gpu.name + ") is not yet supported by this tool." -Exit -} -Elseif (($gpu.Supported -eq "UnOfficial") -eq $true) { -if ($url.GoogleGRID -eq $null) {$URL.GoogleGRID = Invoke-WebRequest -uri https://cloud.google.com/compute/docs/gpus/add-gpus#installing_grid_drivers_for_virtual_workstations -UseBasicParsing} Else {} -$($($URL.GoogleGRID).Links | Where-Object href -like *server2016_64bit_international.exe*).outerHTML.Split('/')[6].split('_')[0] -} -Else { -$gpu.URL = "https://www.nvidia.com/Download/processFind.aspx?psid=" + $gpu.psid + "&pfid=" + $gpu.pfid + "&osid=" + $gpu.osid + "&lid=1&whql=1&lang=en-us&ctk=0" -$link = Invoke-WebRequest -Uri $gpu.URL -Method GET -UseBasicParsing -$link -match '([^<]+?)' | Out-Null -if (($matches[1] -like "*(*") -eq $true) {$matches[1].split('(')[1].split(')')[0]} -Else {$matches[1]} -} + #checks the latest available graphics driver from nvidia.com + if (($gpu.supported -eq "No") -eq $true) { + "Sorry, this GPU (" + $gpu.name + ") is not yet supported by this tool." + Exit + } + Elseif (($gpu.Supported -eq "UnOfficial") -eq $true) { + if ($url.GoogleGRID -eq $null) { $URL.GoogleGRID = Invoke-WebRequest -uri https://cloud.google.com/compute/docs/gpus/add-gpus#installing_grid_drivers_for_virtual_workstations -UseBasicParsing } Else {} + $($($URL.GoogleGRID).Links | Where-Object href -like *server2016_64bit_international.exe*).outerHTML.Split('/')[6].split('_')[0] + } + Else { + $gpu.URL = "https://www.nvidia.com/Download/processFind.aspx?psid=" + $gpu.psid + "&pfid=" + $gpu.pfid + "&osid=" + $gpu.osid + "&lid=1&whql=1&lang=en-us&ctk=0" + $link = Invoke-WebRequest -Uri $gpu.URL -Method GET -UseBasicParsing + $link -match '([^<]+?)' | Out-Null + if (($matches[1] -like "*(*") -eq $true) { $matches[1].split('(')[1].split(')')[0] } + Else { $matches[1] } + } } function GPUCurrentMode { -#returns if the GPU is running in TCC or WDDM mode -$nvidiaarg = "-i 0 --query-gpu=driver_model.current --format=csv,noheader" -$nvidiasmi = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" -try {Invoke-Expression "& `"$nvidiasmi`" $nvidiaarg"} -catch {$null} + #returns if the GPU is running in TCC or WDDM mode + $nvidiaarg = "-i 0 --query-gpu=driver_model.current --format=csv,noheader" + $nvidiasmi = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" + try { Invoke-Expression "& `"$nvidiasmi`" $nvidiaarg" } + catch { $null } } function queryOS { -#sets OS support -if (($system.OS_Version -like "*Windows 10*") -eq $true) {$gpu.OSID = '57' ; $system.OS_Supported = $false} -elseif (($system.OS_Version -like "*Windows 8.1*") -eq $true) {$gpu.OSID = "41"; $system.OS_Supported = $false} -elseif (($system.OS_Version -like "*Server 2016*") -eq $true) {$gpu.OSID = "74"; $system.OS_Supported = $true} -elseif (($system.OS_Version -like "*Server 2019*") -eq $true) {$gpu.OSID = "74"; $system.OS_Supported = $true} -Else {$system.OS_Supported = $false} + #sets OS support + if (($system.OS_Version -like "*Windows 10*") -eq $true) { $gpu.OSID = '57' ; $system.OS_Supported = $false } + elseif (($system.OS_Version -like "*Windows 8.1*") -eq $true) { $gpu.OSID = "41"; $system.OS_Supported = $false } + elseif (($system.OS_Version -like "*Server 2016*") -eq $true) { $gpu.OSID = "74"; $system.OS_Supported = $true } + elseif (($system.OS_Version -like "*Server 2019*") -eq $true) { $gpu.OSID = "74"; $system.OS_Supported = $true } + Else { $system.OS_Supported = $false } } function webName { -#Gets the unknown GPU name from a csv based on a deviceID found in the installedgpuid function + #Gets the unknown GPU name from a csv based on a deviceID found in the installedgpuid function (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/parsec-cloud/Cloud-GPU-Updater/master/Additional%20Files/GPUID.csv", $($system.Path + "\GPUID.CSV")) -Import-Csv "$($system.path)\GPUID.csv" -Delimiter ',' | Where-Object DeviceID -like *$($gpu.Device_ID)* | Select-Object -ExpandProperty GPUName + Import-Csv "$($system.path)\GPUID.csv" -Delimiter ',' | Where-Object DeviceID -like *$($gpu.Device_ID)* | Select-Object -ExpandProperty GPUName } function queryGPU { -#sets details about current gpu -if($gpu.Device_ID -eq "DEV_13F2") {$gpu.Name = 'NVIDIA Tesla M60'; $gpu.PSID = '75'; $gpu.PFID = '783'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes"} -ElseIF($gpu.Device_ID -eq "DEV_118A") {$gpu.Name = 'NVIDIA GRID K520'; $gpu.PSID = '94'; $gpu.PFID = '704'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes"} -ElseIF($gpu.Device_ID -eq "DEV_1BB1") {$gpu.Name = 'NVIDIA Quadro P4000'; $gpu.PSID = '73'; $gpu.PFID = '840'; $gpu.NV_GRID = $false; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes"} -Elseif($gpu.Device_ID -eq "DEV_1BB0") {$gpu.Name = 'NVIDIA Quadro P5000'; $gpu.PSID = '73'; $gpu.PFID = '823'; $gpu.NV_GRID = $false; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes"} -Elseif($gpu.Device_ID -eq "DEV_15F8") {$gpu.Name = 'NVIDIA Tesla P100'; $gpu.PSID = '103'; $gpu.PFID = '822'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial"} -Elseif($gpu.Device_ID -eq "DEV_1BB3") {$gpu.Name = 'NVIDIA Tesla P4'; $gpu.PSID = '103'; $gpu.PFID = '831'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial"} -Elseif($gpu.Device_ID -eq "DEV_1EB8") {$gpu.Name = 'NVIDIA Tesla T4'; $gpu.PSID = '110'; $gpu.PFID = '883'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial"} -Elseif($gpu.Device_ID -eq $null) {$gpu.Supported = "No"; $gpu.Name = "No Device Found"} -else{$gpu.Supported = "No"; $gpu.Name = webName} -} - -function checkGPUSupport{ -#quits if GPU isn't supported -If ($gpu.Supported -eq "No") { -$app.FailGPU -Exit -} -ElseIf ($gpu.Supported -eq "UnOfficial") { -$app.UnOfficialGPU -} -Else{} + #sets details about current gpu + if ($gpu.Device_ID -eq "DEV_13F2") { $gpu.Name = 'NVIDIA Tesla M60'; $gpu.PSID = '75'; $gpu.PFID = '783'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes" } + ElseIF ($gpu.Device_ID -eq "DEV_118A") { $gpu.Name = 'NVIDIA GRID K520'; $gpu.PSID = '94'; $gpu.PFID = '704'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes" } + ElseIF ($gpu.Device_ID -eq "DEV_1BB1") { $gpu.Name = 'NVIDIA Quadro P4000'; $gpu.PSID = '73'; $gpu.PFID = '840'; $gpu.NV_GRID = $false; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes" } + Elseif ($gpu.Device_ID -eq "DEV_1BB0") { $gpu.Name = 'NVIDIA Quadro P5000'; $gpu.PSID = '73'; $gpu.PFID = '823'; $gpu.NV_GRID = $false; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "Yes" } + Elseif ($gpu.Device_ID -eq "DEV_15F8") { $gpu.Name = 'NVIDIA Tesla P100'; $gpu.PSID = '103'; $gpu.PFID = '822'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial" } + Elseif ($gpu.Device_ID -eq "DEV_1BB3") { $gpu.Name = 'NVIDIA Tesla P4'; $gpu.PSID = '103'; $gpu.PFID = '831'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial" } + Elseif ($gpu.Device_ID -eq "DEV_1EB8") { $gpu.Name = 'NVIDIA Tesla T4'; $gpu.PSID = '110'; $gpu.PFID = '883'; $gpu.NV_GRID = $true; $gpu.Driver_Version = driverversion; $gpu.Web_Driver = webdriver; $gpu.Update_Available = ($gpu.Web_Driver -gt $gpu.Driver_Version); $gpu.Current_Mode = GPUCurrentMode; $gpu.Supported = "UnOfficial" } + Elseif ($gpu.Device_ID -eq $null) { $gpu.Supported = "No"; $gpu.Name = "No Device Found" } + else { $gpu.Supported = "No"; $gpu.Name = webName } +} + +function checkGPUSupport { + #quits if GPU isn't supported + If ($gpu.Supported -eq "No") { + $app.FailGPU + Exit + } + ElseIf ($gpu.Supported -eq "UnOfficial") { + $app.UnOfficialGPU + } + Else {} } function checkDriverInstalled { -#Tells user if no GPU driver is installed -if ($system.Valid_NVIDIA_Driver -eq $False) { -$app.NoDriver -} -Else{} + #Tells user if no GPU driver is installed + if ($system.Valid_NVIDIA_Driver -eq $False) { + $app.NoDriver + } + Else {} } function prepareEnvironment { -#prepares working directory -$test = Test-Path -Path $system.path -if ($test -eq $true) { -Remove-Item -path $system.Path -Recurse -Force | Out-Null -New-Item -ItemType Directory -Force -Path $system.path | Out-Null} -Else { -New-Item -ItemType Directory -Force -Path $system.path | Out-Null -} + #prepares working directory + $test = Test-Path -Path $system.path + if ($test -eq $true) { + Remove-Item -path $system.Path -Recurse -Force | Out-Null + New-Item -ItemType Directory -Force -Path $system.path | Out-Null + } + Else { + New-Item -ItemType Directory -Force -Path $system.path | Out-Null + } } function startUpdate { -#Gives user an option to start the update, and sends messages to the user - prepareEnvironment - downloaddriver - InstallDriver - rebootlogic + #Gives user an option to start the update, and sends messages to the user + prepareEnvironment + downloaddriver + InstallDriver + rebootlogic } function setnvsmi { -#downloads script to set GPU to WDDM if required + #downloads script to set GPU to WDDM if required (New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/parsec-cloud/Cloud-GPU-Updater/master/Additional%20Files/NVSMI.ps1", $($system.Path) + "\NVSMI.ps1") -Unblock-File -Path "$($system.Path)\NVSMI.ps1" + Unblock-File -Path "$($system.Path)\NVSMI.ps1" } -function setnvsmi-shortcut{ -#creates startup shortcut that will start the script downloaded in setnvsmi -Write-Output "Create NVSMI shortcut" -$Shell = New-Object -ComObject ("WScript.Shell") -$ShortCut = $Shell.CreateShortcut("$env:PROGRAMDATA\Microsoft\Windows\Start Menu\Programs\Startup\NVSMI.lnk") -$ShortCut.TargetPath="powershell.exe" -$ShortCut.Arguments='-WindowStyle hidden -ExecutionPolicy Bypass -File "C:\ParsecTemp\Drivers\NVSMI.ps1"' -$ShortCut.WorkingDirectory = "C:\ParsecTemp\Drivers"; -$ShortCut.WindowStyle = 0; -$ShortCut.Description = "Create NVSMI shortcut"; -$ShortCut.Save() +function setnvsmi-shortcut { + #creates startup shortcut that will start the script downloaded in setnvsmi + Write-Output "Create NVSMI shortcut" + $Shell = New-Object -ComObject ("WScript.Shell") + $ShortCut = $Shell.CreateShortcut("$env:PROGRAMDATA\Microsoft\Windows\Start Menu\Programs\Startup\NVSMI.lnk") + $ShortCut.TargetPath = "powershell.exe" + $ShortCut.Arguments = '-WindowStyle hidden -ExecutionPolicy Bypass -File "C:\ParsecTemp\Drivers\NVSMI.ps1"' + $ShortCut.WorkingDirectory = "C:\ParsecTemp\Drivers"; + $ShortCut.WindowStyle = 0; + $ShortCut.Description = "Create NVSMI shortcut"; + $ShortCut.Save() } function DownloadDriver { -if (($gpu.supported -eq "UnOfficial") -eq $true) { + if (($gpu.supported -eq "UnOfficial") -eq $true) { (New-Object System.Net.WebClient).DownloadFile($($($URL.GoogleGRID).links | Where-Object href -like *server2016_64bit_international.exe*).href, "C:\ParsecTemp\Drivers\GoogleGRID.exe") -} -Else { -#downloads driver from nvidia.com -$Download.Link = Invoke-WebRequest -Uri $gpu.url -Method Get -UseBasicParsing | select @{N='Latest';E={$($_.links.href -match"www.nvidia.com/download/driverResults.aspx*")[0].substring(2)}} -$download.Direct = Invoke-WebRequest -Uri $download.link.latest -Method Get -UseBasicParsing | select @{N= 'Download'; E={"http://us.download.nvidia.com" + $($_.links.href -match "/content/driverdownload*").split('=')[1].split('&')[0]}} + } + Else { + #downloads driver from nvidia.com + $Download.Link = Invoke-WebRequest -Uri $gpu.url -Method Get -UseBasicParsing | select @{N = 'Latest'; E = { $($_.links.href -match "www.nvidia.com/download/driverResults.aspx*")[0].substring(2) } } + $download.Direct = Invoke-WebRequest -Uri $download.link.latest -Method Get -UseBasicParsing | select @{N = 'Download'; E = { "http://us.download.nvidia.com" + $($_.links.href -match "/content/driverdownload*").split('=')[1].split('&')[0] } } (New-Object System.Net.WebClient).DownloadFile($($download.direct.download), $($system.Path) + "\NVIDIA_" + $($gpu.web_driver) + ".exe") -} + } } function installDriver { -#installs driver silently with /s /n arguments provided by NVIDIA -$DLpath = Get-ChildItem -Path $system.path -Include *exe* -Recurse | Select-Object -ExpandProperty Name -Start-Process -FilePath "$($system.Path)\$dlpath" -ArgumentList "/s /n" -Wait } + #installs driver silently with /s /n arguments provided by NVIDIA + $DLpath = Get-ChildItem -Path $system.path -Include *exe* -Recurse | Select-Object -ExpandProperty Name + Start-Process -FilePath "$($system.Path)\$dlpath" -ArgumentList "/s /n" -Wait +} #setting up arrays below $url = @{} $download = @{} $app = @{} -$gpu = @{Device_ID = installedGPUID} -$system = @{Valid_NVIDIA_Driver = ValidDriver; OS_Version = osVersion; OS_Reboot_Required = RequiresReboot; Date = get-date; Path = "C:\ParsecTemp\Drivers"} +$gpu = @{Device_ID = installedGPUID } +$system = @{Valid_NVIDIA_Driver = ValidDriver; OS_Version = osVersion; OS_Reboot_Required = RequiresReboot; Date = get-date; Path = "C:\ParsecTemp\Drivers" } function rebootLogic { -#checks if machine needs to be rebooted, and sets a startup item to set GPU mode to WDDM if required -if ($system.OS_Reboot_Required -eq $true) { - if ($GPU.NV_GRID -eq $false) - { - start-sleep -s 10 - Restart-Computer -Force} + #checks if machine needs to be rebooted, and sets a startup item to set GPU mode to WDDM if required + if ($system.OS_Reboot_Required -eq $true) { + if ($GPU.NV_GRID -eq $false) { + start-sleep -s 10 + Restart-Computer -Force + } ElseIf ($GPU.NV_GRID -eq $true) { - setnvsmi - setnvsmi-shortcut - start-sleep -s 10 - Restart-Computer -Force} - Else{} -} -Else { + setnvsmi + setnvsmi-shortcut + start-sleep -s 10 + Restart-Computer -Force + } + Else {} + } + Else { if ($gpu.NV_GRID -eq $true) { - setnvsmi - setnvsmi-shortcut - start-sleep -s 10 - Restart-Computer -Force} + setnvsmi + setnvsmi-shortcut + start-sleep -s 10 + Restart-Computer -Force + } ElseIf ($gpu.NV_GRID -eq $false) { } - Else{} -} + Else {} + } } #remove Windows Proxy @@ -251,21 +261,22 @@ querygpu checkGPUSupport querygpu -if(($gpu.supported -eq "Yes") -or ($gpu.supported -eq "UnOfficial")) {} +if (($gpu.supported -eq "Yes") -or ($gpu.supported -eq "UnOfficial")) {} Else { -Write-host "There is no GPU or it is unsupported" -Exit + Write-host "There is no GPU or it is unsupported" + Exit } if ($gpu.driver_version -eq $null) { -write-host "No Driver" -startUpdate + write-host "No Driver" + startUpdate } -Else{"Continue"} +Else { "Continue" } if ($gpu.current_mode -eq "TCC") { -write-host "Change Driver Mode" -setnvsmi -setnvsmi-shortcut -shutdown /r -t 0} + write-host "Change Driver Mode" + setnvsmi + setnvsmi-shortcut + shutdown /r -t 0 +} Else {} diff --git a/PreInstall/CreateAutomaticShutdownScheduledTask.ps1 b/PreInstall/CreateAutomaticShutdownScheduledTask.ps1 index a396778..54700d3 100644 --- a/PreInstall/CreateAutomaticShutdownScheduledTask.ps1 +++ b/PreInstall/CreateAutomaticShutdownScheduledTask.ps1 @@ -1,31 +1,32 @@ # Self-elevate the script if required if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { - if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { - $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments - Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine - Exit - } + if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments + Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine + Exit + } } Write-Host "This sets your machine to shutdown if Windows detects it as idle for X minutes. This is intended to save you money if you ever forget to shut your machine down. You will get a warning message pop up 10 minutes before shutdown" -Do {[int]$read = read-host "How much time should the system idle for before shutting down? Time in Minutes - Minimum 20"} +Do { [int]$read = read-host "How much time should the system idle for before shutting down? Time in Minutes - Minimum 20" } while ($read -lt "20") $read | Out-File $env:Programdata\ParsecLoader\Autoshutdown.txt $readfile = Get-Content -Path $env:Programdata\ParsecLoader\Autoshutdown.txt $time = $readfile - 10 $span = new-timespan -minutes $time -try {Get-ScheduledTask -TaskName "Automatically Shutdown on Idle" -ErrorAction Stop | Out-Null -Unregister-ScheduledTask -TaskName "Automatically Shutdown on Idle" -Confirm:$false +try { + Get-ScheduledTask -TaskName "Automatically Shutdown on Idle" -ErrorAction Stop | Out-Null + Unregister-ScheduledTask -TaskName "Automatically Shutdown on Idle" -Confirm:$false } catch {} $action = New-ScheduledTaskAction -Execute 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument '-executionpolicy bypass -windowstyle hidden -file %programdata%\ParsecLoader\automatic-shutdown.ps1' -$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME +$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Automatically Shutdown on Idle" -Description "This script runs at startup and monitors for idle" -RunLevel Highest diff --git a/PreInstall/CreateClearProxyScheduledTask.ps1 b/PreInstall/CreateClearProxyScheduledTask.ps1 index fca8c0a..1d49cab 100644 --- a/PreInstall/CreateClearProxyScheduledTask.ps1 +++ b/PreInstall/CreateClearProxyScheduledTask.ps1 @@ -1,50 +1,51 @@ # Self-elevate the script if required if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { - if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { - $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments - Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine - Exit - } + if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments + Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine + Exit + } } function Setup { -#requests user approve potential cloud run time charges for using the tool -Write-Output "This creates a scheduled task that + #requests user approve potential cloud run time charges for using the tool + Write-Output "This creates a scheduled task that automatically disables Windows Proxies and re-enables and installs the GPU driver if a user accidentally deletes it. Both of these stop Parsec working. Runs on Startup. If the user does uninstall the driver, the machine may reboot automatically. No warranty given or implied." -$ReadHost = Read-Host "Install the scheduled task? (Y/N)" - Switch ($ReadHost) - { - Y { - Write-output "Creating Task" - CreateScheduledTask | Out-Null - Write-output "Done" - Pause - Exit - } - N{ - Write-Output "The upgrade script will now exit" - Pause - Exit} - } + $ReadHost = Read-Host "Install the scheduled task? (Y/N)" + Switch ($ReadHost) { + Y { + Write-output "Creating Task" + CreateScheduledTask | Out-Null + Write-output "Done" + Pause + Exit + } + N { + Write-Output "The upgrade script will now exit" + Pause + Exit + } + } } Function CreateScheduledTask { -try {Get-ScheduledTask -TaskName "Recover GPU Driver and Remove Proxy" -ErrorAction Stop | Out-Null -Unregister-ScheduledTask -TaskName "Recover GPU Driver and Remove Proxy" -Confirm:$false -} -catch {} + try { + Get-ScheduledTask -TaskName "Recover GPU Driver and Remove Proxy" -ErrorAction Stop | Out-Null + Unregister-ScheduledTask -TaskName "Recover GPU Driver and Remove Proxy" -Confirm:$false + } + catch {} -$action = New-ScheduledTaskAction -Execute 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument '-file %programdata%\ParsecLoader\clear-proxy.ps1' + $action = New-ScheduledTaskAction -Execute 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument '-file %programdata%\ParsecLoader\clear-proxy.ps1' -$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME + $trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME -Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Recover GPU Driver and Remove Proxy" -Description "This task reinstalls or re-enables the GPU and clears any Windows Proxies" -RunLevel Highest + Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Recover GPU Driver and Remove Proxy" -Description "This task reinstalls or re-enables the GPU and clears any Windows Proxies" -RunLevel Highest } setup \ No newline at end of file diff --git a/PreInstall/CreateOneHourWarningScheduledTask.ps1 b/PreInstall/CreateOneHourWarningScheduledTask.ps1 index ba2bf17..3e2f737 100644 --- a/PreInstall/CreateOneHourWarningScheduledTask.ps1 +++ b/PreInstall/CreateOneHourWarningScheduledTask.ps1 @@ -1,10 +1,10 @@ # Self-elevate the script if required if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { - if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { - $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments - Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine - Exit - } + if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments + Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine + Exit + } } Write-Host "This script sets your machine to warn you 5 minutes before your machine bills you for an hour, @@ -13,41 +13,42 @@ This is useful if your Machine bills per hour, like AWS" $confirmation = Read-Host "Are you Sure You Want To Proceed: Y/N" Switch ($confirmation) { Y { - } + } N { Exit - } } +} try { Get-ScheduledTask -TaskName "One Hour Warning Message" -ErrorAction Stop | Out-Null $ModifyOrRemove = "You already have the script installed, remove it?" - Switch ($ModifyOrRemove) { - N { - } - Y { - Unregister-ScheduledTask -TaskName "One Hour Warning Message" -Confirm:$false - "The warning message has been removed" - Pause - Exit} + Switch ($ModifyOrRemove) { + N { + } + Y { + Unregister-ScheduledTask -TaskName "One Hour Warning Message" -Confirm:$false + "The warning message has been removed" + Pause + Exit } } +} catch { - } +} try { Get-ScheduledTask -TaskName "One Hour Warning Message" -ErrorAction Stop | Out-Null Unregister-ScheduledTask -TaskName "One Hour Warning Message" -Confirm:$false - } +} catch { - } +} $action = New-ScheduledTaskAction -Execute 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument '-executionpolicy bypass -windowstyle hidden -file %programdata%\ParsecLoader\WarningMessage.ps1' -$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME +$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "One Hour Warning Message" -Description "This will warn you 5 minutes before you're billed for another hour" -RunLevel Highest diff --git a/PreInstall/NetworkRestore.ps1 b/PreInstall/NetworkRestore.ps1 index c7f52e8..6c6090d 100644 --- a/PreInstall/NetworkRestore.ps1 +++ b/PreInstall/NetworkRestore.ps1 @@ -1,70 +1,73 @@ function Remove-Razer-Startup { -if (((Get-Item -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run).GetValue("Razer Synapse") -ne $null) -eq $true) -{Remove-ItemProperty -path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" -Name "Razer Synapse" -"Removed Startup Item from Razer Synapse"} -Else {"Razer Startup Item not present"} + if (((Get-Item -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run).GetValue("Razer Synapse") -ne $null) -eq $true) { + Remove-ItemProperty -path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" -Name "Razer Synapse" + "Removed Startup Item from Razer Synapse" + } + Else { "Razer Startup Item not present" } } Remove-Razer-Startup function checkGPUstatus { -$getdisabled = Get-WmiObject win32_videocontroller | Where-Object {$_.name -like '*NVIDIA*' -and $_.status -like 'Error'} | Select-Object -ExpandProperty PNPDeviceID -if ($getdisabled -ne $null) {"Enabling GPU" -$var = $getdisabled.Substring(0,21) -$arguement = "/r enable"+ ' ' + "*"+ "$var"+ "*" -Start-Process -FilePath "C:\ParsecTemp\Apps\devcon.exe" -ArgumentList $arguement -} -Else {"Device is enabled"} + $getdisabled = Get-WmiObject win32_videocontroller | Where-Object { $_.name -like '*NVIDIA*' -and $_.status -like 'Error' } | Select-Object -ExpandProperty PNPDeviceID + if ($getdisabled -ne $null) { + "Enabling GPU" + $var = $getdisabled.Substring(0, 21) + $arguement = "/r enable" + ' ' + "*" + "$var" + "*" + Start-Process -FilePath "C:\ParsecTemp\Apps\devcon.exe" -ArgumentList $arguement + } + Else { "Device is enabled" } } function DriverInstallStatus { -$checkdevicedriver = Get-WmiObject win32_videocontroller | Where-Object {$_.PNPDeviceID -like '*VEN_10DE*'} -if ($checkdevicedriver.name -eq "Microsoft Basic Display Adapter") {Write-output "Driver not installed" -} -Else {checkGPUStatus} + $checkdevicedriver = Get-WmiObject win32_videocontroller | Where-Object { $_.PNPDeviceID -like '*VEN_10DE*' } + if ($checkdevicedriver.name -eq "Microsoft Basic Display Adapter") { + Write-output "Driver not installed" + } + Else { checkGPUStatus } } DriverInstallStatus function check-nvidia { -$nvidiasmiarg = "-i 0 --query-gpu=driver_model.current --format=csv,noheader" -$nvidiasmidir = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" -$nvidiasmiresult = Invoke-Expression "& `"$nvidiasmidir`" $nvidiasmiarg" -$nvidiadriverstatus = if($nvidiasmiresult -eq "WDDM") -{"GPU Driver status is good" + $nvidiasmiarg = "-i 0 --query-gpu=driver_model.current --format=csv,noheader" + $nvidiasmidir = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" + $nvidiasmiresult = Invoke-Expression "& `"$nvidiasmidir`" $nvidiasmiarg" + $nvidiadriverstatus = if ($nvidiasmiresult -eq "WDDM") { + "GPU Driver status is good" + } + ElseIf ($nvidiasmiresult -eq "TCC") { + Write-Output "The GPU has incorrect mode TCC set - setting WDDM" + $nvidiasmiwddm = "-g 0 -dm 0" + $nvidiasmidir = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" + Invoke-Expression "& `"$nvidiasmidir`" $nvidiasmiwddm" + } + Else {} + $nvidiadriverstatus } -ElseIf($nvidiasmiresult -eq "TCC") -{Write-Output "The GPU has incorrect mode TCC set - setting WDDM" -$nvidiasmiwddm = "-g 0 -dm 0" -$nvidiasmidir = "c:\program files\nvidia corporation\nvsmi\nvidia-smi" -Invoke-Expression "& `"$nvidiasmidir`" $nvidiasmiwddm"} -Else{} -$nvidiadriverstatus} check-nvidia #set ip and dns to dhcp -function set-dhcp -{ -$global:interfaceindex = Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object ifindex -ExpandProperty ifindex -$Global:interfacename = Get-NetIPInterface -InterfaceIndex $interfaceindex -AddressFamily IPv4 | select interfacealias -ExpandProperty interfacealias -$Global:setdhcp = "netsh interface ip set address '$interfacename' dhcp" -$Global:setdnsdhcp = "netsh interface ip set dns '$interfacename' dhcp" -Invoke-expression -command "$setdhcp" -Invoke-expression -command "$setdnsdhcp" +function set-dhcp { + $global:interfaceindex = Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object ifindex -ExpandProperty ifindex + $Global:interfacename = Get-NetIPInterface -InterfaceIndex $interfaceindex -AddressFamily IPv4 | select interfacealias -ExpandProperty interfacealias + $Global:setdhcp = "netsh interface ip set address '$interfacename' dhcp" + $Global:setdnsdhcp = "netsh interface ip set dns '$interfacename' dhcp" + Invoke-expression -command "$setdhcp" + Invoke-expression -command "$setdnsdhcp" } #enable adapter if required -function Enable-Adapter -{ -Get-NetAdapter |? status -NE Enabled | Enable-NetAdapter +function Enable-Adapter { + Get-NetAdapter | ? status -NE Enabled | Enable-NetAdapter } -$getdisabledadapters = Get-NetAdapter |? status -ne enabled +$getdisabledadapters = Get-NetAdapter | ? status -ne enabled #query device and perform required fix -$networkadapterstatus = if($getdisabledadapters -ne $null) -{"no adapter found - enabling disabled adapters and setting dhcp" -enable-adapter -set-dhcp +$networkadapterstatus = if ($getdisabledadapters -ne $null) { + "no adapter found - enabling disabled adapters and setting dhcp" + enable-adapter + set-dhcp } -else -{"Resetting DHCP" -set-dhcp +else { + "Resetting DHCP" + set-dhcp } $networkadapterstatus diff --git a/PreInstall/OneHour.ps1 b/PreInstall/OneHour.ps1 index 45475fb..a6b04dc 100644 --- a/PreInstall/OneHour.ps1 +++ b/PreInstall/OneHour.ps1 @@ -1,16 +1,16 @@ function OneHour { -Write-Output "Launched" | Out-File C:\ParsecTemp\Launched.txt -$Seconds = Get-Content $env:programdata\ParsecLoader\Time.txt -$Count = 0 -do { -$Count++ -Start-Sleep -s 1 -$Count -} -Until($Count -ge $Seconds) + Write-Output "Launched" | Out-File C:\ParsecTemp\Launched.txt + $Seconds = Get-Content $env:programdata\ParsecLoader\Time.txt + $Count = 0 + do { + $Count++ + Start-Sleep -s 1 + $Count + } + Until($Count -ge $Seconds) -Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\ShowDialog.ps1" + Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\ShowDialog.ps1" } diff --git a/PreInstall/ShowDialog.ps1 b/PreInstall/ShowDialog.ps1 index 5640c0c..19aed7a 100644 --- a/PreInstall/ShowDialog.ps1 +++ b/PreInstall/ShowDialog.ps1 @@ -1,73 +1,73 @@ Function ShowDialog { -Add-Type -AssemblyName System.Windows.Forms -$Screen = [System.Windows.Forms.Screen]::PrimaryScreen - $form1_Load = { - $script:countdown = [timespan]'00:55:00' - $Text.Text = "YOUR CLOUD COMPUTER HAS BEEN ON FOR " ,$countdown.Minutes, " MINUTES " ,$countdown.Seconds, " SECONDS." - $timer1.Start() - } + Add-Type -AssemblyName System.Windows.Forms + $Screen = [System.Windows.Forms.Screen]::PrimaryScreen + $form1_Load = { + $script:countdown = [timespan]'00:55:00' + $Text.Text = "YOUR CLOUD COMPUTER HAS BEEN ON FOR " , $countdown.Minutes, " MINUTES " , $countdown.Seconds, " SECONDS." + $timer1.Start() + } - $timer1_Tick = { + $timer1_Tick = { if ($script:countdown -ge [timespan]'00:59:59') { - $timer1.Stop() - $Form.Close() + $timer1.Stop() + $Form.Close() } - Else{} - $script:countdown += [timespan]'00:00:01' - $Text.Text = "YOUR CLOUD COMPUTER HAS BEEN ON FOR " ,$countdown.Minutes, " MINUTES " ,$countdown.Seconds, " SECONDS." - } + Else {} + $script:countdown += [timespan]'00:00:01' + $Text.Text = "YOUR CLOUD COMPUTER HAS BEEN ON FOR " , $countdown.Minutes, " MINUTES " , $countdown.Seconds, " SECONDS." + } -$SubMessage = "Stop your computer now if you don't want to pay another hour of game time." -$timer1 = New-Object System.Windows.Forms.Timer -$Form = New-Object system.Windows.Forms.Form -$Form.BackColor = "#25253f" -$form.AutoScale = 1 -$Form.TopMost = $true -$Form.Width = $Screen.Bounds.Width -$Form.Height = 200 -$Form.FormBorderStyle = '0' -$Form.StartPosition = 'Manual' -$Form.Top = 0 -$form.AutoScale = -$Form.Left = ($Screen.Bounds.Width - $Form.Width)/2 -$form.add_Load($form1_Load) + $SubMessage = "Stop your computer now if you don't want to pay another hour of game time." + $timer1 = New-Object System.Windows.Forms.Timer + $Form = New-Object system.Windows.Forms.Form + $Form.BackColor = "#25253f" + $form.AutoScale = 1 + $Form.TopMost = $true + $Form.Width = $Screen.Bounds.Width + $Form.Height = 200 + $Form.FormBorderStyle = '0' + $Form.StartPosition = 'Manual' + $Form.Top = 0 + $form.AutoScale = + $Form.Left = ($Screen.Bounds.Width - $Form.Width) / 2 + $form.add_Load($form1_Load) -$image = [System.Drawing.Image]::FromFile("$ENV:ProgramData\ParsecLoader\Parsec.png") -$pictureBox = new-object Windows.Forms.PictureBox -$pictureBox.Width = 100 -$pictureBox.Height = 100 -$picturebox.SizeMode = "StretchImage" -$pictureBox.Image = $image -$TextImage = $($($Form.Width - $Text.Width) / 10) * $(5.25 - 2) -$picturebox.location = New-Object System.Drawing.Point($TextImage,25) -$form.controls.add($pictureBox) -$Text = New-Object system.windows.Forms.Label -$Text.Text = '00:00:00' -$Text.TextAlign = 'MiddleLeft' -$Text.Height = 50 -$Text.Width = $Screen.Bounds.Width / 4.25 -$TextX = (($Form.Width - $Text.Width) / 10) * 5.25 -$Text.Location = New-Object System.Drawing.Point($TextX,25) -$Text.Font = "Rubik,11,style=Bold" -$Text.ForeColor = "#CDCDCD" -$Form.controls.Add($Text) -$TextMessage = New-Object system.windows.Forms.Label -$TextMessage.Text = $SubMessage -$TextMessage.TextAlign = 'MiddleLeft' -$TextMessage.Height = 80 -$TextMessage.Width = $Screen.Bounds.Width / 4.25 -$TextXMessage = (($Form.Width - $Text.Width) / 10) * 6 -$TextMessage.Location = New-Object System.Drawing.Point($TextX,50) -$TextMessage.Font = "Rubik,11" -$TextMessage.ForeColor = "#CDCDCD" -$timer1.Interval = 1000 -$timer1.add_Tick($timer1_Tick) -$form.ResumeLayout() + $image = [System.Drawing.Image]::FromFile("$ENV:ProgramData\ParsecLoader\Parsec.png") + $pictureBox = new-object Windows.Forms.PictureBox + $pictureBox.Width = 100 + $pictureBox.Height = 100 + $picturebox.SizeMode = "StretchImage" + $pictureBox.Image = $image + $TextImage = $($($Form.Width - $Text.Width) / 10) * $(5.25 - 2) + $picturebox.location = New-Object System.Drawing.Point($TextImage, 25) + $form.controls.add($pictureBox) + $Text = New-Object system.windows.Forms.Label + $Text.Text = '00:00:00' + $Text.TextAlign = 'MiddleLeft' + $Text.Height = 50 + $Text.Width = $Screen.Bounds.Width / 4.25 + $TextX = (($Form.Width - $Text.Width) / 10) * 5.25 + $Text.Location = New-Object System.Drawing.Point($TextX, 25) + $Text.Font = "Rubik,11,style=Bold" + $Text.ForeColor = "#CDCDCD" + $Form.controls.Add($Text) + $TextMessage = New-Object system.windows.Forms.Label + $TextMessage.Text = $SubMessage + $TextMessage.TextAlign = 'MiddleLeft' + $TextMessage.Height = 80 + $TextMessage.Width = $Screen.Bounds.Width / 4.25 + $TextXMessage = (($Form.Width - $Text.Width) / 10) * 6 + $TextMessage.Location = New-Object System.Drawing.Point($TextX, 50) + $TextMessage.Font = "Rubik,11" + $TextMessage.ForeColor = "#CDCDCD" + $timer1.Interval = 1000 + $timer1.add_Tick($timer1_Tick) + $form.ResumeLayout() -$Form.controls.Add($TextMessage) + $Form.controls.Add($TextMessage) $width = 200 $okBtn = New-Object System.Windows.Forms.Button @@ -81,10 +81,10 @@ $Form.controls.Add($TextMessage) $okBtn.ForeColor = "#25253f" $okBtnX = ($Form.Width / 2) - $width - 25 $okBtnY = $Form.Height - $okBtn.Height - 25 - $okBtn.Location = New-Object System.Drawing.Point($okBtnX,$okBtnY) + $okBtn.Location = New-Object System.Drawing.Point($okBtnX, $okBtnY) $okBtn.Add_Click({ - $Form.Close() - }) + $Form.Close() + }) $Form.Controls.Add($okBtn) $cancelBtn = New-Object System.Windows.Forms.Button $cancelBtn.Text = 'Remind me in 1 hour' @@ -97,21 +97,21 @@ $Form.controls.Add($TextMessage) $cancelBtn.ForeColor = "#25253f" $cancelBtnX = ($Form.Width / 2) $cancelBtnY = $Form.Height - $cancelBtn.Height - 25 - $cancelBtn.Location = New-Object System.Drawing.Point($cancelBtnX,$cancelBtnY) + $cancelBtn.Location = New-Object System.Drawing.Point($cancelBtnX, $cancelBtnY) $cancelBtn.Add_Click({ - [int]3300 + ([int]3599 - [int]$script:countdown.TotalSeconds) | Out-File $env:programdata\ParsecLoader\Time.txt + [int]3300 + ([int]3599 - [int]$script:countdown.TotalSeconds) | Out-File $env:programdata\ParsecLoader\Time.txt -Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\OneHour.ps1" + Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\OneHour.ps1" -$form.Close() + $form.Close() - }) + }) $Form.Controls.Add($cancelBtn) -[void]$Form.ShowDialog() + [void]$Form.ShowDialog() -$Form.Dispose() + $Form.Dispose() } ShowDialog \ No newline at end of file diff --git a/PreInstall/TeamMachineSetup.ps1 b/PreInstall/TeamMachineSetup.ps1 index 6bb335b..9109e37 100644 --- a/PreInstall/TeamMachineSetup.ps1 +++ b/PreInstall/TeamMachineSetup.ps1 @@ -5,23 +5,22 @@ $MeEndpoint = "https://kessel-api.parsecgaming.com/me" $userBinPath = "C:\ProgramData\Parsec\user.bin" $configtxtdir = 'C:\ProgramData\Parsec\config.txt' -Class Post -{ -[String]$name -[String]$peer_id -[int]$team_group_id -[int]$user_id -[string]$user_email -[string]$key -[string]$team_id -[bool]$is_guest_access = $false - - [void] Fill(){ +Class Post { + [String]$name + [String]$peer_id + [int]$team_group_id + [int]$user_id + [string]$user_email + [string]$key + [string]$team_id + [bool]$is_guest_access = $false + + [void] Fill() { $config = fetchUserData foreach ($line in $config) { - $this."$($line.split("=")[0])" = $($line.split("=")[1]) - $this.peer_id = $(PeerIDGetter) - if (!$this.name) {$this.name = $env:COMPUTERNAME} + $this."$($line.split("=")[0])" = $($line.split("=")[1]) + $this.peer_id = $(PeerIDGetter) + if (!$this.name) { $this.name = $env:COMPUTERNAME } } } } @@ -29,49 +28,49 @@ Class Post function fetchUserData { $metadata = $( - try { - (Invoke-WebRequest -uri http://metadata.google.internal/computeMetadata/v1/instance/attributes/parsec -Method GET -header @{'metadata-flavor'='Google'} -TimeoutSec 5) - $stream = "bytes" - } - catch { - } - Try { + try { + (Invoke-WebRequest -uri http://metadata.google.internal/computeMetadata/v1/instance/attributes/parsec -Method GET -header @{'metadata-flavor' = 'Google' } -TimeoutSec 5) + $stream = "bytes" + } + catch { + } + Try { (Invoke-WebRequest -uri http://metadata.paperspace.com/meta-data/machine -TimeoutSec 5) - $stream = "bytes" - } - catch { - } - Try { + $stream = "bytes" + } + catch { + } + Try { (Invoke-WebRequest -Uri "http://169.254.169.254/latest/user-data?" -TimeoutSec 5) - $stream = "bytes" - } - catch { - } - Try { - Invoke-Webrequest -Headers @{"Metadata"="true"} -Uri "http://169.254.169.254/metadata/instance/compute/userData?api-version=2021-01-01&format=text" -TimeoutSec 5 - $stream = "base64" - } - Catch { - } - ) + $stream = "bytes" + } + catch { + } + Try { + Invoke-Webrequest -Headers @{"Metadata" = "true" } -Uri "http://169.254.169.254/metadata/instance/compute/userData?api-version=2021-01-01&format=text" -TimeoutSec 5 + $stream = "base64" + } + Catch { + } + ) if ($metadata.StatusCode -eq 200) { if (($metadata.Content.Length) -gt 1) { if ($stream -eq "bytes") { [System.Text.Encoding]::ASCII.GetString($metadata.content).split(':') - } + } elseif ($stream -eq "base64") { [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($metadata.Content)).split(':') - } } + } else { #no userdata found, exiting... Exit - } } + } else { #no userdata found, exiting... Exit - } + } } @@ -80,40 +79,40 @@ Function PeerIDGetter { foreach ($configline in $configfile) { if ($configline -like 'app_host_peer_id*') { $peerid = $configline.Split(' = ')[-1] - } } - if ($peerid -eq $NULL) {$peerid = $NULL} - return $peerid } + if ($peerid -eq $NULL) { $peerid = $NULL } + return $peerid +} Function WritePeerID { -Param( -$peer_id -) + Param( + $peer_id + ) $configfile = Get-Content $configtxtdir $File = Foreach ($configline in $configfile) { if ($configline -like 'app_host_peer_id*') { - } - Else {$configline} - } + } + Else { $configline } + } $file += "app_host_peer_id=$peer_id" $file | Out-File $configtxtdir -Encoding ascii - } +} Function WriteHostname { -Param( -$host_name -) + Param( + $host_name + ) $configfile = Get-Content $configtxtdir $File = Foreach ($configline in $configfile) { if ($configline -like 'host_name*') { - } - Else {$configline} - } + } + Else { $configline } + } $file += "host_name=$host_name" $file | Out-File $configtxtdir -Encoding ascii - } +} Function SessionIDFromUserBin { @@ -124,48 +123,48 @@ Function SessionIDFromUserBin { $decryptuserBin = [System.Security.Cryptography.ProtectedData]::Unprotect($binbyte, $null, $scope) $parseuserbin = [System.Text.Encoding]::ASCII.GetString($decryptuserBin) return $parseuserbin.Split('"')[-2] - } + } Else { return 0 - } } +} Function SessionIDToUserBin { -Param ( -[string]$session -) + Param ( + [string]$session + ) $userBinJson = @{ - "session_id" = $session - } | ConvertTo-Json + "session_id" = $session + } | ConvertTo-Json $scope = [System.Security.Cryptography.DataProtectionScope]::LocalMachine $input = [System.Text.UTF8Encoding]::UTF8.GetBytes($userBinJson) $userBin = [System.Security.Cryptography.ProtectedData]::Protect($input, $null, $scope) Set-Content $userBinPath -Value $userBin -Encoding Byte - } +} Function PostTeamEndpoint { -param ( -[post]$Params -) + param ( + [post]$Params + ) $body = $Params | Select-Object * -ExcludeProperty key, team_id $TeamEndpointHeaders = @{ - "Content-Type" = "application/json" - "X-Machine-Key" = $params.key - } + "Content-Type" = "application/json" + "X-Machine-Key" = $params.key + } $TeamEndpointRequest = Invoke-RestMethod -Uri $TeamEndoint -Method POST -Headers $TeamEndpointHeaders -Body ($body | ConvertTo-Json) return $TeamEndpointRequest } Function GenerateMeData { -param( -[string]$Session -) + param( + [string]$Session + ) $SessionHeader = @{ "Authorization" = "Bearer $Session" } - $array = (Invoke-RestMethod -Uri $MeEndpoint -Method GET -Headers $SessionHeader).data + $array = (Invoke-RestMethod -Uri $MeEndpoint -Method GET -Headers $SessionHeader).data $array } diff --git a/PreInstall/WarningMessage.ps1 b/PreInstall/WarningMessage.ps1 index 8b303f4..17cc8d9 100644 --- a/PreInstall/WarningMessage.ps1 +++ b/PreInstall/WarningMessage.ps1 @@ -1,19 +1,21 @@  $CountSinceStart = 0 -Function CountSinceStart {$MinutesSinceStart = [int]3240 - $($(get-date) - $(Get-EventLog -LogName System -InstanceId 12 -Newest 1).TimeGenerated).TotalSeconds -If ($MinutesSinceStart -lt 0) { -$MinutesSinceStart = 0} -Else{} +Function CountSinceStart { + $MinutesSinceStart = [int]3240 - $($(get-date) - $(Get-EventLog -LogName System -InstanceId 12 -Newest 1).TimeGenerated).TotalSeconds + If ($MinutesSinceStart -lt 0) { + $MinutesSinceStart = 0 + } + Else {} -Do { -$CountSinceStart++ -Start-Sleep -s 1 -} -Until -( -$CountSinceStart -ge $MinutesSinceStart -) -Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\ShowDialog.ps1" + Do { + $CountSinceStart++ + Start-Sleep -s 1 + } + Until + ( + $CountSinceStart -ge $MinutesSinceStart + ) + Start-Process powershell.exe -ArgumentList "-windowstyle hidden -executionpolicy bypass -file $env:programdata\ParsecLoader\ShowDialog.ps1" }