Getting Started with PowerShell
The XenServer-SDK directory contains the following folders that are relevant to PowerShell users:
-
XenServerPowerShell-
PowerShell_7: The XenServer SDK for PowerShell 7.-
XenServerPSModule: The XenServer PowerShell module for PowerShell 7. -
src: C# source code for the XenServer PowerShell cmdlets.
-
-
PowerShell_51: The XenServer SDK for PowerShell 5.1.-
XenServerPSModule: The XenServer PowerShell module for PowerShell 5.1. -
src: C# source code for the XenServer PowerShell cmdlets.
-
-
RPC protocol
The PowerShell SDK supports the JSON-RPC v2.0 protocol.
Platform supported
XenServer® SDK for PowerShell 7:
- Windows
- Linux
This library requires .NET 8.0 and PowerShell 7.4 or greater.
XenServer SDK for PowerShell 5.1:
- Windows
This library requires .NET Framework 4.5 and PowerShell 5.1.
Library
XenServerPSModule
Note:
This module is generally, but not fully, backwards compatible. To interact with hosts running older versions of XenServer or Citrix Hypervisor™, it is advisable to use the module of the same version as the host.
Dependencies
- Newtonsoft JSON.NET by James Newton-King.
- XenServer.NET, the C# SDK for XenServer.
Installation
First, extract the contents of the SDK ZIP file.
Note:
Some web browsers may mark the SDK ZIP file as “blocked” during the download. To import the module successfully you will need to unblock the SDK ZIP file before extracting its contents. To unblock the SDK ZIP file, right-click on it and launch the Properties dialog. Click the Unblock button, then the Apply or OK button.
XenServer SDK for PowerShell 7:
-
Navigate to the extracted
XenServer-SDK\XenServerPowerShell\PowerShell_7directory and copy the whole folderXenServerPSModuleinto your PowerShell modules directory.- On Windows this will normally be
$env:UserProfile\Documents\PowerShell\Modulesfor per-user configuration, or$env:ProgramFiles\PowerShell\7\Modulesfor system-wide configuration. - On Linux this will be
~/.local/share/powershell/Modulesfor per-user configuration, or/usr/local/share/powershell/Modulesfor system-wide configuration.
For more information see PowerShell’s documentation on module paths:
Get-Help about_PSModulePath <!--NeedCopy--> - On Windows this will normally be
-
Open a PowerShell 7 prompt as administrator.
To do this, open the Windows Start menu by clicking the Start icon, find the item PowerShell 7, right-click it and select Run as administrator.
-
Determine the current execution policy:
Get-ExecutionPolicy <!--NeedCopy-->If the current policy is
Restricted, you need to set it toRemoteSigned:Set-ExecutionPolicy RemoteSigned <!--NeedCopy-->You should understand the security implications of this change. If you are unsure, see PowerShell’s documentation on execution policies:
Get-Help about_Execution_Policies <!--NeedCopy-->If the current policy is
AllSigned, you will be able to use the XenServer PowerShell module, but it will be inconvenient because this policy requires even scripts that you write on the local computer to be signed. You may want to change it toRemoteSigned, as above.If the current policy is
RemoteSigned,ByPass, orUnrestrictedthere is nothing to do. -
Exit the privileged instance of PowerShell.
-
Open a PowerShell 7 prompt as a regular user (click Start > PowerShell 7) and import the XenServer PowerShell module:
Import-Module XenServerPSModule <!--NeedCopy--> -
If you wish to load specific environment settings when the XenServer PowerShell module is loaded, create the file
XenServerProfile.ps1and put it in the folder containing your$PROFILEfile for per-user configuration, or in$PSHOMEfor system-wide configuration.-
On Windows these will normally be
$env:UserProfile\Documents\PowerShellfor per-user configuration, or$env:ProgramFiles\PowerShell\7for system-wide configuration. -
On Linux these will be
~/.config/powershellfor per-user configuration, or/opt/microsoft/powershell/7for system-wide configuration.
-
XenServer SDK for PowerShell 5.1:
-
Navigate to the extracted
XenServer-SDK\XenServerPowerShell\PowerShell_51directory and copy the whole folderXenServerPSModuleinto your PowerShell modules directory.- On Windows this will normally be
$env:UserProfile\Documents\WindowsPowerShell\Modulesfor per-user configuration, or$env:windir\system32\WindowsPowerShell\v1.0\Modulesfor system-wide configuration.
For more information see PowerShell’s documentation on module paths:
PS> Get-Help about_PSModulePath - On Windows this will normally be
-
Open a PowerShell 5.1 prompt as administrator.
To do this, open the Windows Start menu by clicking the Start icon, find the item PowerShell 5.1, right click it and select Run as administrator.
-
Determine the current execution policy:
PS> Get-ExecutionPolicy <!--NeedCopy-->If the current policy is
Restricted, you need to set it toRemoteSigned:PS> Set-ExecutionPolicy RemoteSigned <!--NeedCopy-->You should understand the security implications of this change. If you are unsure, see PowerShell’s documentation on execution policies:
PS> Get-Help about_Execution_Policies <!--NeedCopy-->If the current policy is
AllSigned, you will be able to use the XenServer PowerShell module, but it will be inconvenient because this policy requires even scripts that you write on the local computer to be signed. You may want to change it toRemoteSigned, as above.If the current policy is
RemoteSigned,ByPass, orUnrestrictedthere is nothing to do. -
Exit the privileged instance of PowerShell.
-
Open a PowerShell 5.1 prompt as a regular user (click Start > PowerShell) and import the XenServer PowerShell Module:
PS> Import-Module XenServerPSModule <!--NeedCopy--> -
If you wish to load specific environment settings when the XenServer PowerShell module is loaded, create the file
XenServerProfile.ps1and put it in the folder containing your$PROFILEfile for per-user configuration, or in$PSHOMEfor system-wide configuration.- On Windows these will normally be
$env:UserProfile\Documents\WindowsPowerShellfor per-user configuration, or$env:windir\system32\WindowsPowerShell\v1.0for system-wide configuration.
- On Windows these will normally be
Getting help
For an overview of the XenServer PowerShell module, type:
Get-Help about_XenServer
<!--NeedCopy-->
You can obtain a list of all available cmdlets by running:
Get-Command -Module XenServerPSModule
<!--NeedCopy-->
For help with a specific command use:
Get-Help [CommandName]
<!--NeedCopy-->
See Using the XenServer PowerShell module for an overview of the module cmdlets and their structure, and a number of walk-throughs on how to perform certain specialized tasks.
Building and debugging the source code
Open the project XenServerPowerShell.csproj in Visual Studio 2022. You should now be ready to build the source code.
If in Debug mode, clicking Start will launch a PowerShell 7 prompt as an external process and import the compiled XenServerPowerShell.dll as a module (without, however, processing the scripts, types, and formats shipped within the XenServer PowerShell module). You should now be ready to debug the cmdlets.
Examples
Examples on the usage of the XenServer Powershell module can be found at XenServer PowerShell Module usage examples on GitHub.