boilerplate/getresponses.ps1
################################################ # # INPUT # ################################################ [CmdletBinding()] Param( [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)] [String]$SettingsFile = "" ) #----------------------------------------------- # DEBUG SWITCH #----------------------------------------------- $debug = $false If ( $PSBoundParameters["Debug"].IsPresent -eq $true ) { $debug = $true } ################################################ # # NOTES # ################################################ <# bla bla #> ################################################ # # PATH # ################################################ #----------------------------------------------- # CHECKING PS AND OS #----------------------------------------------- Write-Verbose "Check PowerShell and Operating system" -Verbose # Check if this is Pwsh Core $isCore = ($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop') Write-Verbose -Message "Using PowerShell version $( $PSVersionTable.PSVersion.ToString() ) and $( $PSVersionTable.PSEdition ) edition" -Verbose # Check the operating system, if Core if ($isCore -eq $true) { $os = If ( $IsWindows -eq $true ) { "Windows" } elseif ( $IsLinux -eq $true ) { "Linux" } elseif ( $IsMacOS -eq $true ) { "MacOS" } else { throw "Unknown operating system" } } else { # [System.Environment]::OSVersion.VersionString() # [System.Environment]::Is64BitOperatingSystem $os = "Windows" } Write-Verbose -Message "Using OS: $( $os )" -Verbose #----------------------------------------------- # ADD MODULE PATH, IF NOT PRESENT #----------------------------------------------- $modulePath = @( [System.Environment]::GetEnvironmentVariable("PSModulePath") -split ";" ) + @( "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles") )\WindowsPowerShell\Modules" "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles(x86)") )\WindowsPowerShell\Modules" "$( [System.Environment]::GetEnvironmentVariable("USERPROFILE") )\Documents\WindowsPowerShell\Modules" "$( [System.Environment]::GetEnvironmentVariable("windir") )\system32\WindowsPowerShell\v1.0\Modules" ) # Add the 64bit path, if present. In 32bit the ProgramFiles variables only returns the x86 path If ( [System.Environment]::GetEnvironmentVariables().keys -contains "ProgramW6432" ) { $modulePath += "$( [System.Environment]::GetEnvironmentVariable("ProgramW6432") )\WindowsPowerShell\Modules" } # Add pwsh core path If ( $isCore -eq $true ) { If ( [System.Environment]::GetEnvironmentVariables().keys -contains "ProgramW6432" ) { $modulePath += "$( [System.Environment]::GetEnvironmentVariable("ProgramW6432") )\powershell\7\Modules" } $modulePath += "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles") )\powershell\7\Modules" $modulePath += "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles(x86)") )\powershell\7\Modules" } # Add all paths # Using $env:PSModulePath for only temporary override $Env:PSModulePath = @( $modulePath | Sort-Object -unique ) -join ";" #----------------------------------------------- # ADD SCRIPT PATH, IF NOT PRESENT #----------------------------------------------- #$envVariables = [System.Environment]::GetEnvironmentVariables() $scriptPath = @( [System.Environment]::GetEnvironmentVariable("Path") -split ";" ) + @( "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles") )\WindowsPowerShell\Scripts" "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles(x86)") )\WindowsPowerShell\Scripts" "$( [System.Environment]::GetEnvironmentVariable("USERPROFILE") )\Documents\WindowsPowerShell\Scripts" ) # Add the 64bit path, if present. In 32bit the ProgramFiles variables only returns the x86 path If ( [System.Environment]::GetEnvironmentVariables().keys -contains "ProgramW6432" ) { $scriptPath += "$( [System.Environment]::GetEnvironmentVariable("ProgramW6432") )\WindowsPowerShell\Scripts" } # Add pwsh core path If ( $isCore -eq $true ) { If ( [System.Environment]::GetEnvironmentVariables().keys -contains "ProgramW6432" ) { $scriptPath += "$( [System.Environment]::GetEnvironmentVariable("ProgramW6432") )\powershell\7\Scripts" } $scriptPath += "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles") )\powershell\7\Scripts" $scriptPath += "$( [System.Environment]::GetEnvironmentVariable("ProgramFiles(x86)") )\powershell\7\Scripts" } # Using $env:Path for only temporary override $Env:Path = @( $scriptPath | Sort-Object -unique ) -join ";" ################################################ # # CHECKS # ################################################ #----------------------------------------------- # CHECK INPUT #----------------------------------------------- If ( $PsCmdlet.ParameterSetName -eq "JobIdInput" ) { If ( $SettingsFile -eq "" ) { throw "Please define a settings file" } else { $settingsfileLocation = $SettingsFile } } else { $settingsfileLocation = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($params.settingsFile) } #----------------------------------------------- # CHANGE PATH #----------------------------------------------- # Set current location to the settings files directory $settingsFileItem = Get-Item $settingsfileLocation Set-Location $settingsFileItem.DirectoryName ################################################ # # SETTINGS # ################################################ #----------------------------------------------- # IMPORT MODULE #----------------------------------------------- If ($debug -eq $true) { Import-Module "AptecoPSFramework" -Verbose } else { Import-Module "AptecoPSFramework" } #----------------------------------------------- # SET SETTINGS #----------------------------------------------- # Set the settings If ( $useJob -eq $true -and $ProcessId -ne "") { Import-Settings -Path $settingsfileLocation -ProcessId $ProcessId } else { Import-Settings -Path $settingsfileLocation } # Get all settings $s = Get-Settings #----------------------------------------------- # SET DEBUG MODE #----------------------------------------------- Set-DebugMode -DebugMode $debug ################################################ # # PROGRAM # ################################################ #----------------------------------------------- # GET MESSAGES #----------------------------------------------- # Added try/catch again because of extras.xml wrapper try { # Do the upload $return = Get-Response # Return the values, if succeeded $return } catch { throw $_ Exit 1 } |