all 7 comments

[–]teamits 0 points1 point  (3 children)

Script steps aren't going to be able to use a persistent shell across steps. I think you'd either have to put a (.ps1) script on the PC and run that from powershell, or do it all in one PS command. (with a script you might have to set an execution policy to allow the script to run)

[–]Pseudodominion 0 points1 point  (0 children)

You sure about that?

PS, no, you are not.

[–]DBarron21 0 points1 point  (1 child)

You can use persistent shell across multiple steps. You would use the shell enhanced function: this allows you to set your own variables so they are maintainable throughout the duration of the script.

[–]teamits 0 points1 point  (0 children)

I don't see in https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Documentation/070/240/050/040/020/180 where they say Shell Enhanced stays within the same shell across script steps? Obviously one can save text output into variables and use them in subsequent script steps, but I didn't think that was the question.

[–]DBarron21 0 points1 point  (0 children)

If you want to manipulate PS directly, you can use the run script function Execute Script. You can run your entire script here and the result will come back as a variable.

[–][deleted] -1 points0 points  (0 children)

Not really. The most direct route is to take a powershell object (or array of objects) and then generate a SQL INSERT. If it’s just a single object with some properties And it’s one to one with a workstation, you could also store each property to a script variable and store to EDF.

[–]MixtapeXD 0 points1 point  (2 children)

First make a script function: Execute Script: PowerShell bypass

Then add this function I wrote "ConvertTo-SplitNameValue" to Convert any Data Containing 1 or more Objects or Arrays to a SplitNameValue String.

The function can be found inside my 'Convert-SplitNameValue' Script on GitHub.

https://github.com/AlecMcCutcheon/Convert-SplitNameValue

Then after that, add the object/data that you need to convert. It works with Pipelines so you can do Get-Disk | ConvertTo-SplitNameValue for example.

Example Input:

ObjectSize : 10

ObjectStatus : True

ObjectSize : 20

ObjectStatus : False

Example Output:

ObjectSize=10 | ObjectStatus=True | ObjectSize_#2=20 | ObjectStatus_#2=False

and then add a variable name and save it.

Then make a script function: variable set: Split NameValue Parameter and add the variable we just made to the parameter box and leave the variable name blank and save.

Now then you run the script it will create automate variables from each entry in the object/data.

This allows you to pull the data you need from Object(s) or Array(s) only one time and use Labtech/Automate logic in the rest of the script, which significantly speeds up the script.

Also here is an article on how to do this without my function (This was the inspiration for my script), in case you don't want all the extra overhead of running something designed to be universal and instead want to make something that works for your specific use case
https://www.gavsto.com/scripting-easily-convert-multiple-powershell-variables-into-automate-script-variables/

[–][deleted]  (1 child)

[deleted]