• About me…
  • VMware
  • Powershell
  • DIY

ConfigMgr.nl

VMware, PowerShell, Automation, and more…

  • About me…
  • VMware
  • Powershell
  • DIY

Testing Script Runtime Service for vSphere – part 2

1 februari 2021 PowerCli Powershell VMware No Comments

In the first part of this blog, I installed the Script Runtime Service and checked if it was installed correctly.
In this second part, I will give you a walkthrough of how to run a simple script.

In order to successfully run a script, you must have some understanding of how the service works. Every user has his own runspace. This runspace is a PowerShell instance running in a dedicated container as a Kubernetes pod on the Kubernetes cluster.

To run a script you request Script Execution. Script Execution is an SRS resource that represents a script that you request to run in a runspace. The whole process looks like this:

  1. logon
  2. create runspace
  3. run script
  4. retrieve output
  5. remove runspace
  6. logout

Logon

SRS uses vCenter Server SSO so any vSphere user that can authenticate in vCenter Server SSO can access the SRS feature. When the authentication is successful the service returns an X-SRS-API-KEY token in the response headers. This token must be used for subsequent API calls. Just add the token to the headers.

Create runspace

When you create a runspace, you can request to create a PowerCLI connection to all linked vCenter Servers. To request a PowerCLI connection specify run_vc_connection_script on the create runspace API call. The status and id of the created runspace can be found in the content property of the returned object. Because a runspace is not immediately available you have to check the status before you continue with the next step.

Run script

Now that you have created a runspace, you can use that runspace to run your script. The only thing you need is the ID of the runspace and a name for your script (or code). Because the calls are asynchronous you have to check the status of the script periodically.

Retrieve output

When your script is finished you have to get the output of the script. Output is referenced by the ID of the script.

Besides script output, there are also five streams that are collected for script execution: Information, Error, Warning, Debug, and Verbose. Streams give information that the script has been produced during the execution.

Remove runspace

When you are done with the runspace you can delete it. The only thing you need is the ID of the runspace.

Logout

And finally, when you are all done, you can terminate your session by logging out.

When you code these steps in PowerShell it looks like this:

Once again I refer to @LucD’s blog if you want to see more advanced code on how to run your PowerShell code on SRS.

powercliscriptsrsvCentervcsavSphere

Reporting on your Windows Server backup

The system has insufficient locker space for the image profile

Geef een reactie Antwoord annuleren

Deze website gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.

Meest recente berichten

  • Handy one-liners
  • The system has insufficient locker space for the image profile
  • Testing Script Runtime Service for vSphere – part 2
  • Reporting on your Windows Server backup
  • Testing Script Runtime Service for vSphere – part 1

Jeroen BurenFollow

Jeroen Buren
jeroen_burenJeroen Buren@jeroen_buren·
15 apr

Had some spare time... So I did the HCI Master Specialist Exam and nailed it ;-) #vExpert #VMware #HCI

Reply on Twitter 1382574365389258752Retweet on Twitter 1382574365389258752Like on Twitter 138257436538925875220Twitter 1382574365389258752
jeroen_burenJeroen Buren@jeroen_buren·
15 apr

Join VMware's global event on May 5th & 6th to see their strategy for the new distributed workforce. There will be 13 technical sessions on @WorkspaceONE and @vmwarehorizon, @VMwareSDWAN, @vmw_carbonblack, and more! https://www.vmware.com/anywhere-workspace-event.html?src=so_6075a9bbde44b&cid=7012H000001l6vL #AnywhereWorkspace

Reply on Twitter 1382569804020744192Retweet on Twitter 1382569804020744192Like on Twitter 13825698040207441922Twitter 1382569804020744192
jeroen_burenJeroen Buren@jeroen_buren·
10 apr

Go #XRP Go... To infinity and beyond!

Reply on Twitter 1380903963772469253Retweet on Twitter 1380903963772469253Like on Twitter 13809039637724692531Twitter 1380903963772469253
jeroen_burenJeroen Buren@jeroen_buren·
10 apr

En weer 3 minuten kou geleden...

Reply on Twitter 1380801147368304640Retweet on Twitter 1380801147368304640Like on Twitter 13808011473683046401Twitter 1380801147368304640
jeroen_burenJeroen Buren@jeroen_buren·
5 apr

Het wordt nu toch echt lente!! 😂 #SpringTime

Reply on Twitter 1379101934813114375Retweet on Twitter 1379101934813114375Like on Twitter 13791019348131143754Twitter 1379101934813114375
Load More...

Categorieën

Proudly powered by WordPress | Theme: Doo by ThemeVS.