[Solved] Powershell REST examples \ Paramter during runtime?


I want to connect to Salesforce as Source system via REST, using the PowerShell connector. Do you have any sample scripts? It is hard to understand how to shift one return (access token) to the next function inside the XML.

(edit) OK, found something. In the <Initialization> Tab, I place this script

<CustomCommand Name="get-SixtForceAccesstoken">
					<!-- Den Kram sollten wir im GitHub haben, so dass man das anpassen und rauskopieren kann -->
						[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]

						[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]

						[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]

						[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
					$postParams = [ordered]@{
						grant_type    = "refresh_token";
						client_id     = "$ClientId";
						client_secret = "$ClientSecret";
						refresh_token = "$RefreshToken";

					$uri = $SFBaseURL + "services/oauth2/token"
					try {
						$request = Invoke-RestMethod -Uri $uri -Method POST -Body $postParams -ErrorAction Stop
					catch {
						$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
						$request = $streamReader.ReadToEnd() | ConvertFrom-Json

					$global:instance_url = $request.instance_url # <---- Here to set Global Variable
					$global:access_token = $request.access_token
					return $request.access_token

Run it then

					<Item Command="Import-SFModule" Order="1">
						<SetParameter Param="_PathToPSModule" Source="ConnectionParameter" Value="PathToPSModule" />
					<Item Command="get-SixtForceAccesstoken" Order="2">
						<SetParameter Param="SFBaseURL" Source="ConnectionParameter" Value="SFBaseURL" />
						<SetParameter Param="ClientId" Source="ConnectionParameter" Value="ClientId" />
						<SetParameter Param="ClientSecret" Source="ConnectionParameter" Value="ClientSecret" />
						<SetParameter Param="RefreshToken" Source="ConnectionParameter" Value="RefreshToken" />

To have the Token and Instance URL in place.

<Item Command="Set-SFObject" Order="1">
                            <SetParameter Param="instance_url" Source="GlobalVariable" Value="instance_url" />
                            <SetParameter Param="access_token" Source="GlobalVariable" Value="access_token" />
                            <SetParameter Param="ObjectClass" Source="FixedValue" Value="User" />
                            <SetParameter Param="IsActive" Source="FixedValue" Value="false" />

But when I want to browse the user, I only recive this error.

Error loading system objects of class User (all) (User_Master).
A parameter cannot be found that matches parameter name 'instance_url'.

Any Idea what I´m doing wrong?

Edit2: After a couple of tries, I was able to query all users in the Target system and do a query on every single ID :)
If anyone struggles in the same situation, you need to set the variable in the first snippet as $global:xxxx Then all the other scripts can consume it.

Best, Denny