#Write-Host "`n - Retrieving Ambitions Technology Group's Functions -" Set-ExecutionPolicy Bypass -Scope Process -Force #Adds fancy checkmark :D $greenCheck = @{ Object = [Char]8730 ForegroundColor = 'Green' NoNewLine = $true } $progressPreference = 'Continue' # Check PowerShell version to handle certificate validation appropriately if ($PSVersionTable.PSVersion.Major -lt 6) { # PowerShell 5.1 and below - Use the original method If (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type) { $certCallback = @" using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class ServerCertificateValidationCallback { public static void Ignore() { if(ServicePointManager.ServerCertificateValidationCallback ==null) { ServicePointManager.ServerCertificateValidationCallback += delegate ( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; } } } "@ Add-Type $certCallback [ServerCertificateValidationCallback]::Ignore() } #Enable SSL/TLS for PS 5.1 Try { # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192) [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 } Catch { Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3+.' } } else { # PowerShell 6+ (including 7) - No need to use ServicePointManager # Modern PowerShell versions handle TLS appropriately by default # and have -SkipCertificateCheck parameter for Invoke-WebRequest } $FunctionsFolder = $ENV:SystemDrive + '\Ambitions\Functions' New-Item -ItemType Directory -Force -Path $FunctionsFolder | Out-Null #Imports functions from Github - Use appropriate method based on PS version If ($PSVersionTable.PSEdition -like "Desktop") { # PowerShell 5.1 and below $FunctionURLs = (Invoke-WebRequest https://github.com/AmbitionsTechnologyGroup/ATG-PS-Functions/raw/master/Functions/URL-List.csv -UseBasicParsing -Headers @{"Cache-Control"="no-cache"}).Content | ConvertFrom-Csv -Delimiter "," } Else { # PowerShell 6+ (including 7) $FunctionURLs = (Invoke-WebRequest https://github.com/AmbitionsTechnologyGroup/ATG-PS-Functions/raw/master/Functions/URL-List.csv -UseBasicParsing -SkipCertificateCheck -Headers @{"Cache-Control"="no-cache"}).Content | ConvertFrom-Csv -Delimiter "," } $Global:DestinationFiles = @() $FunctionURLs | ForEach-Object { $DestinationFiles += $FunctionsFolder + "\" + $_.Verb + ".psm1" } #Import existing functions first Function Update-ATGPS { $DestinationFiles | ForEach-Object { If (Test-Path $_ -ErrorAction SilentlyContinue) { Import-Module $_ -Global -Force } } } Update-ATGPS If (Get-Module -Name "ATG-PS*") { #Write-Host "Functions quickloaded. Loading updated scripts in background." if ($PSVersionTable.PSVersion.Major -lt 6) { # PowerShell 5.1 and below Start-Job -ScriptBlock {Invoke-WebRequest http://download.ambitionsgroup.com/Scripts/Update-ATGPS.txt -UseBasicParsing -Headers @{"Cache-Control"="no-cache"} | Invoke-Expression} | Out-Null } else { # PowerShell 6+ (including 7) Start-Job -ScriptBlock {Invoke-WebRequest http://download.ambitionsgroup.com/Scripts/Update-ATGPS.txt -UseBasicParsing -SkipCertificateCheck -Headers @{"Cache-Control"="no-cache"} | Invoke-Expression} | Out-Null } } Else { #Write-Host "Quickload not found. Loading Functions." if ($PSVersionTable.PSVersion.Major -lt 6) { # PowerShell 5.1 and below Start-Job -ScriptBlock {Invoke-WebRequest http://download.ambitionsgroup.com/Scripts/Update-ATGPS.txt -UseBasicParsing -Headers @{"Cache-Control"="no-cache"} | Invoke-Expression} | Receive-Job -AutoRemoveJob -Wait } else { # PowerShell 6+ (including 7) Start-Job -ScriptBlock {Invoke-WebRequest http://download.ambitionsgroup.com/Scripts/Update-ATGPS.txt -UseBasicParsing -SkipCertificateCheck -Headers @{"Cache-Control"="no-cache"} | Invoke-Expression} | Receive-Job -AutoRemoveJob -Wait } $DestinationFiles | ForEach-Object { If (Test-Path $_ -ErrorAction SilentlyContinue) { Import-Module $_ -Global -Force } } } #Gives status If (Get-Module -Name "ATG-PS*" -ErrorAction SilentlyContinue){ <#Write-Host -NoNewLine " ";Write-Host @greenCheck;Write-Host -NoNewLine " Functions successfully loaded ";Write-Host @greenCheck;Write-Host "`n - 'Get-ATGPS' will give a list of custom functions -`n"#> } Else { Write-Host "Functions were not successfully loaded. Kindly let Payden know. He's a cool guy. Also, are you running as admin?" }