{"id":18195757,"url":"https://github.com/imcf/psytricks","last_synced_at":"2026-03-02T22:02:23.811Z","repository":{"id":157176710,"uuid":"627821696","full_name":"imcf/psytricks","owner":"imcf","description":"PowerShell-Python-Citrix vodoo. :alien: :dizzy_face:","archived":false,"fork":false,"pushed_at":"2025-05-09T08:47:31.000Z","size":273,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-22T16:54:04.498Z","etag":null,"topics":["citrix","cvad","poetry","powershell","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/psytricks/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-14T09:19:44.000Z","updated_at":"2025-05-09T08:47:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"578aef2d-7e77-4b01-a943-73fc153d7e82","html_url":"https://github.com/imcf/psytricks","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/imcf/psytricks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcf%2Fpsytricks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcf%2Fpsytricks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcf%2Fpsytricks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcf%2Fpsytricks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcf","download_url":"https://codeload.github.com/imcf/psytricks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcf%2Fpsytricks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007483,"owners_count":26084313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["citrix","cvad","poetry","powershell","python"],"created_at":"2024-11-03T08:04:48.171Z","updated_at":"2025-10-11T14:07:30.347Z","avatar_url":"https://github.com/imcf.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSytricks\n\n![PyPI](https://img.shields.io/pypi/v/psytricks)\n![PyPI - License](https://img.shields.io/pypi/l/psytricks)\n![pdoc](https://img.shields.io/badge/docs-pdoc-brightgreen.svg)\n![black](https://img.shields.io/badge/code%20style-black-000000.svg)\n\n`P`ower`S`hell P`y`thon Ci`tri`x Tri`cks` - pun intended.\n\n![logo](https://raw.githubusercontent.com/imcf/psytricks/main/resources/images/logo.png)\n\nThis package provides an abstraction layer allowing Python code to interact with\na [Citrix Virtual Apps and Desktops (CVAD)][www_cvad] stack, i.e. to fetch\nstatus information and trigger actions on machines and sessions. Since CVAD only\nprovides a *PowerShell Snap-In* to do so, a core component written in `Windows\nPowerShell` (note: **not** `PowerShell Core` as snap-ins are not supported\nthere) is required.\n\nPSyTricks ships with two options for the PowerShell layer:\n\n* A wrapper script that is launched as a subprocess from the Python code. It\n  doesn't require any further setup beyond the package installation but\n  performance, well, slow.\n* A (zero-authentication) `REST` (see the note below on this) service providing\n  several `GET` and `POST` endpoints to request status information or perform\n  actions. Performance is *much* better compared to the wrapper script, but\n  obviously this requires the code to be running as a service in an appropriate\n  permission context.\n\nNOTE: this `RESTful` claim is actually not entirely true. Or basically not at\nall, it would be better called an `HTTP-JSON-RPC-API`. We'll still be using the\nterm `REST` for it as this is basically what people nowadays think of when they\nare coming across this label. Sorry, [Roy T. Fielding][www_rtf].\n\n## 🤯 Are you serious?\n\nCalling PowerShell as a subprocess from within Python? 😳\n\nTo convert results to JSON and pass them back, just to parse it again in Python.\nReally? 🧐\n\nOr, not sure if that's any better, implementing an HTTP REST API in plain\nPowerShell?!? 🫣\n\n### ✅ Yes. We. Are\n\n*And the package name was chosen to reflect this.*\n\nTo be very clear: performance of the wrapper script is abysmal, but this is *not\nat all* an issue for us. Abysmal, as in: for every wrapped call a full (new)\nPowerShell process needs to be instantiated, usually taking something like 1-2\nseconds. ⏳\n\nThe REST interface provides a much better performance, at the cost of some\nadditional setup. If you're happy to take on this approach, the package offers a\nvery smooth ride. 🎢🎡\n\n## 🛠🚧 Installation\n\n### Prerequisites\n\nAs mentioned above, the *Citrix Broker PowerShell Snap-In* is required to be\ninstalled on the machine that will run the wrapper script, since its commands\nare being used to communicate with the CVAD stack. This is also the reason why\nthis package will work on ***Windows PowerShell only*** as snap-ins are not\nsupported on other PowerShell editions. Please note this also implies that the\nlatest usable PowerShell version is 5.1 as newer ones have dropped support for\nsnap-ins (but that's a different problem that Citrix will have to solve at some\npoint).\n\nTo install the snap-in, look for an MSI package like this in the `Delivery\nController` or `XenDesktop` installation media and install it as usual:\n\n* `Broker_PowerShellSnapIn_x64.msi`\n\n### Installing the 🐍 package\n\nIn case you're planning to use `psytricks` via the subprocess approach\n(discouraged but less components to set up), you will have to install the\npackage itself on the Windows machine having the above mentioned *Snap-In*\ninstalled. For the `REST` approach (recommended) only the PowerShell service\ndescribed in the section below has to run on that machine - the Python package\ncan be installed on any computer that is able to talk to the `REST` service.\n\nFor installing `psytricks` please create and activate a `venv`, then run:\n\n```bash\npip install psytricks\n```\n\nNOTE: this will also register the `psytricks` CLI tool although that one is\nmostly meant for testing and demonstration purposes, otherwise the `*-Broker*`\ncommands provided by the PowerShell snap-in could be used directly.\n\n### Setting up the REST service\n\nThe easiest way for installing the REST service is to use [WinSW (Windows\nService Wrapper)][www_winsw] but you may choose anything you like to launch the\nserver process like NSSM, Scheduled Tasks 📅, homegrown dark magic 🪄🔮 or\nothers.\n\nTo go with **WinSW** simply download the bundled version provided with each\n[PSyTricks release][www_releases]. Just look for the `.zip` asset having `REST`\nand `WinSW` in its name.\n\nUnzip the downloaded file to the desired target location, e.g.\n`%PROGRAMDATA%\\PSyTricks`, then copy / rename `restricks-server.example.xml` to\n`restricks-server.xml` and open it in an editor.\n\nAdapt the entries in the `\u003cserviceaccount\u003e` section to match your requirements\nand make sure to update the hostname passed via the `-AdminAddress` parameter in\nthe `\u003cstartarguments\u003e` section. It needs to point to your Citrix Delivery\nController, just in case that's not obvious.\n\nNext step is to install and start the service:\n\n```PowerShell\ncd C:\\ProgramData\\PSyTricks\nrestricks-server.exe install\nStart-Service RESTricksServer\n```\n\nIn case the service doesn't start up, check the Windows Event Log and the `.log`\nfiles created by WinSW in the service directory.\n\nOnce the service has started, you can monitor its actions by live-watching the\nlog file:\n\n```PowerShell\nGet-Content -Wait C:\\ProgramData\\PSyTricks\\restricks-server.log\n```\n\nTada! That's it, the service is now ready to take HTTP requests (from\n`localhost`)! 🎉\n\nPlease be aware that the REST interface doesn't do **any authentication** on\npurpose, meaning everything / everyone that can access it will be able to run\nall requests! We're using it in combination with an SSH tunnel but essentially\nanything that controls who / what can access the service will do the job.\n\n## 🎪 What does it provide?\n\nTo interact with CVAD, a wrapper object needs to be\ninstantiated and instructed how to communicate with the stack.\n\n### Using the REST service - *recommended*\n\nAfter setting up the REST service as described above and making sure to be able\nto connect to it (firewall rules, ssh tunnel, ...), a\n`psytricks.wrapper.ResTricksWrapper` object can be used while passing the URL\nunder which the REST service is reachable, e.g.\n\n```Python\nfrom psytricks.wrapper import ResTricksWrapper\n\nwrapper = ResTricksWrapper(base_url=\"http://localhost:8080/\")\n```\n\n### Using the subprocess wrapper - *use with caution*\n\n(This is only recommended for testing or if for some reason you don't want /\ncan't set up the REST service.)\n\nTo create a wrapper object using the subprocess variant, a\n`psytricks.wrapper.PSyTricksWrapper` with the address of the *Delivery\nController* to connect to has to be instantiated, for example:\n\n```Python\nfrom psytricks.wrapper import PSyTricksWrapper\n\nwrapper = PSyTricksWrapper(deliverycontroller=\"cdc01.vdi.example.xy\")\n```\n\n### Fetching status information\n\nThe wrapper object can then be used to e.g. retrieve information on the machines\ncontrolled (\"brokered\") by Citrix:\n\n```Python\nmachines = wrapper.get_machine_status()\n\nfor machine in machines:\n    print(f\"[{machine[\"DNSName\"]}] is in power state '{machine[\"PowerState\"]}'\")\nprint(f\"Got status details on {len(machines)} machines.\")\n```\n\n### Performing actions\n\nTo restart a machine, use something like this:\n\n```Python\nwrapper.perform_poweraction(machine=\"vm23.vdi.example.xy\", action=\"restart\")\n```\n\nFor placing a machine in *Maintenance Mode* use:\n\n```Python\nwrapper.set_maintenance(machine=\"vm42.vdi.example.xy\", disable=False)\n```\n\n[www_cvad]: https://docs.citrix.com/en-us/citrix-virtual-apps-desktops\n[www_winsw]: https://github.com/winsw/winsw\n[www_releases]: https://github.com/imcf/psytricks/releases\n[www_rtf]: https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcf%2Fpsytricks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcf%2Fpsytricks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcf%2Fpsytricks/lists"}