I'm trying to get this PowerShell command to run when the AVD session host is provisioned. I can manually run it on the AVD host and it runs without error but I want to make it a scripted action. I can't seem to get it to work right as a scripted action when host VM is CREATED. Start-Process -FilePath "C:\Program Files (x86)\TerminalWorks\TSPrint Server\PrintManagment.exe" /import:"C:\Support\TSPrint\TSPrinters-Export.xml" I created 2 account level secure variables: TSPrintManagerEXE = C:\Program Files (x86)\TerminalWorks\TSPrint Server\PrintManagment.exe In my Scripted action I have the following command: I suspect the values in my variables may need double or single quotes but I can't seem to figure it out. |
Scripted Action Variables
Welcome to the community, Alan Dawson 🙂!
I know I struggled with variables in scripted actions and was able to figure a few things out (see Troubleshooting Scripted Actions? – Nerdio Help Center (getnerdio.com)) that may help you.
From the look of your script, I'm not sure you need to use variables for that, but I don't fault you for wanting to try them out. 🙂
Try doing the following:
- Output the variable to the scripted action so you can see what it's doing
Example: Write-Output "Secure variable is $($SecureVars.TSPrintManagerEXE)" - Change your variable to TSPrintManagerArgs = "C:\Support\TSPrint\TSPrinters-Export.xml"
And change your Script to Start-Process $SecureVars.TSPrintManagerEXE /import: $SecureVars.TSPrintManagerArgs
If you're interested in doing more of a deep-dive into Scripted Actions, I know Nerdio was doing some one-day Advanced Training Camps where they covered a single-topic (i.e. Scripted Actions, Nerdio API, etc.) and deep-dived into it.
I'm not seeing any listed (in my limited searching), but I could be missing them.
Carl Long, do you know if your team is still offering those this year?
DStephenson - Thank you again for always being such an active voice here in the community! We just finished our last Scripted Actions camp for 2024 but we will be bringing these back next year and we are also looking at ways to convert those camps to Digital Learning Paths. More details will start to emerge in the next few months around 2025 event dates and Learning Paths.
Thanks for the pointers Dave. I followed your suggested steps and this is the results in the Add Host job details log:
Secure variable is C:\Program Files (x86)\TerminalWorks\TSPrint Server\PrintManagment.exe
Secure variable is "C:\Support\TSPrint\TSPrinters-Export.xml"
I ended up just using a single line command to execute this process. Here is the command in case anyone else is trying to figure out the quotes placement for the -ArgumentList portion of the PowerShell command. I added this line to my Windows Scripted Action in NMM and it works just fine. Those are single quotes before the /import and at the end of the statement.
Start-Process -FilePath "C:\Program Files (x86)\TerminalWorks\TSPrint Server\PrintManagment.exe" -ArgumentList '/import:"C:\Support\TSPrint\TSPrint-exported-printers.xml" /log:"C:\Support\TSPrint\TSPrinters-Import.log"'
Thanks for everyone's input on this.
Excellent! Glad it worked out for you.
Please sign in to leave a comment.
Comments (5 comments)