Skip to content

rcfmartin/PSXO

Repository files navigation

PSXO

A PowerShell wrapper for the Xen Orchestra API.

This module provides PowerShell cmdlets for interacting with Xen Orchestra. It primarily uses the JSON-RPC API, with some cmdlets also utilizing the REST API where appropriate.

Install Dependencies

Install-Module InvokeBuild,PSDepend,Sampler -SkipPublisherCheck

Build The Module

The built module will be in the otuput folder

./build.ps1

Examples

Session

The session object needs to be passed to all cmdlets.

Create a session

$Session = New-XoSession -Uri "https://xo.example.com" -Token "<Your Token>"

Get all sessions

Get-XoSession

Remove Sessions

Get-XoSession | Remove-XoSession

Remove a specific session

Remove-XoSession -Session $Session

Hosts

Get all Hosts

Get-XoHost -Session $Session

Get Hosts by Name

Get-XoHost -Session $Session -Name "MyHost"

Get Hosts by Id

Get-XoHost -Session $Session -Id "7d5550g5-527e-445b-1f7a-34d9ca0b7242"

Enable Host

Enable-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Disable Host

Disable-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Detach host

Disconnect-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Emergency Shutdown Host

Invoke-XoHostEmergencyShutdown -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Remove Host from the XAPI database

Remove-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get host bios info

Get-XoHostBiosInfo -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get Host block device

Get-XoHostBlockDevice -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get Host IPMI Sensor

Get-XoHostIpmiSensor -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get host mdadm RAID health information

Get-XoHostMdadmHealth -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get host scheduler granularity

Get-XoHostSchedulerGranularity -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get host smart ctl health

Get-XoHostSmartCtlHealth -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Restart Host

Restart-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Restart Host Agent

Restart-XoHostAgent -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Update Host properties

Update-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111" -NameDescription "Primary Host"

Set Host to maintenance Mode

Invoke-XoHostMaintenanceMode -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Start Host

Start-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Stop Host

Stop-XoHost -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Virtual Machines

Get all VMs

This cmdlet returns the Type VM by default.

Get-XoVirtualMachine -Session $Session

Get VM by Name

Get-XoVirtualMachine -Session $Session -Name "My VM"

Get VM by Id

Get-XoVirtualMachine -Session $Session -Id "7d5550g5-527e-445b-1f7a-34d9ca0b7242"

Create a new VM

New-XoVirtualMachine -Session $Session -NameLabel "My New VM" -Template "4fb83780-2a39-2c1a-b185-734740d2962d" -Tag "VeryImportantTag"

Update a VM

You can use 2GB,1MB,1TB,etc.. as powershell converts the value for you.

Update-XoVirtualMachine -Session $Session -Id "7d5550g5-527e-445b-1f7a-34d9ca0b7242" -NameDescription "Updated Vm Name" -Cpus 2 -Memory 2GB

Convert VM to template

ConvertTo-XoVirtualMachineTemplate -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Copy VM

Copy-XoVirtualMachine -Session $Session -Id "7d5550g5-527e-445b-1f7a-34d9ca0b7242" -Name "My New VM" -FullCopy:$true -Wait

Mound ISO to VM

Mount-XoVirtualMachineCD -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f" -CdId "21054190-afgt-14b6-ac10-558fgrc9b34g"

Dismount ISO from VM

Dismount-XoVirtualMachineCD -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Delete VM

Remove-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f" -DeleteDisks:$true

Restart VM

Restart-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Restore VM From Snapshot

Restore-XoVirtualMachineFromSnapshot -Session $Session -SnapshotId "06754190-adbf-46a9-ab00-558ffcc9a22f"

Start VM

Start-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Start VM on specific Host

Start-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f" -HostId "1235a452-84c6-4191-af66-3bc6e484ae09"

Stop VM

Stop-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Suspend VM

Suspend-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Resume VM

Resume-XoVirtualMachine -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

VM Snapshots

Take a snapshot

Id is the target VM Id

New-XoSnapshot -Session $Session -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Get Snapshots

Get-XoSnapshot -Session $Session

Delete Snapshot

Remove-XoSnapshot -Session $Session -SnapshotId "06754190-adbf-46a9-ab00-558ffcc9a22f"

Users

Get Users

Get-XoUser -Session $Session

Get user by Email

Get-XoUser -Session $Session -Email "admin@admin.com"

Create new User

$password = $(ConvertTo-SecureString -String "MySecurePassword" -Force -AsPlainText)
New-XoUser -Session $Session -Email "admin@admin.com" -Password $password

Create new Admin User

$password = $(ConvertTo-SecureString -String "MySecurePassword" -Force -AsPlainText)
New-XoUser -Session $Session -Email "admin@admin.com" -IsAdmin -Password $password

Update User

$password = $(ConvertTo-SecureString -String "MySecurePassword" -Force -AsPlainText)
Update-XoUser -Session $Session -Email "admin@admin.com" -Password $password

Update Admin User

Update-XoUser -Session $Session -Email "admin@admin.com" -IsAdmin

Remove User

Remove-XoUser -Session $Session-Id "06754190-adbf-46a9-ab00-558ffcc9a22f"
Get-XoUser -Session $Session -Email "admin@admin.com" | Remove-XoUser -Session $Session

Tags

Add tag to an object

Add-XoTag -Session $Session -Tag "Critical" -Id "06754190-adbf-46a9-ab00-558ffcc9a22f" -Color "#000000"

Add tag using the Helper function for the colors

$Color = $(Get-XoTagColor -TagColorId black).Color
Add-XoTag -Session $Session -Tag "Critical" -Id "06754190-adbf-46a9-ab00-558ffcc9a22f" -Color "$($Color)"

Get Tags

Get-XoTag -Session $Session
Get-XoTag -Session $Session -Tag "Critical"

Update Tag

Update-XoTag -Session $Session-Tag "Critical" -Color "#0000ff"

Update Tag using the Helper function for the colors

$Color = $(Get-XoTagColor -TagColorId black).Color
Update-XoTag -Session $Session -Tag "Critical" -Color "$($Color)"

Remove Tag from object

Remove-XoTag -Session $Session -Tag"Critical" -Id "06754190-adbf-46a9-ab00-558ffcc9a22f"

Get an Extensive List of colors to use with tags

Get-XoTagColor

Tasks

Get all tasks

Get-XoTask -Session $Session

Group

Create a new group

New-XoGroup -Session $Session -Name "MyGroup"

Delete a group

Remove-XoGroup -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Get all groups

Get-XoGroup -Session $Session

Get group by name

Get-XoGroup -Session $Session -Name "MyGroup"

Get group by Id

Get-XoGroup -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111"

Update Group Name

Update-XoGroup -Session $Session -Name "MyNewGroupName"

Add users to group

Add-XoGroupUser -Session $Session$ -Id "9ace51e1-dfbd-4617-8db3-88f28974e111" -UserId "06754190-adbf-46a9-ab00-558ffcc9a22f"

Add-XoGroupUser -Session $Session$ -Id "9ace51e1-dfbd-4617-8db3-88f28974e111" -UserId "06754190-adbf-46a9-ab00-558ffcc9a22f","12354190-adbf-46a9-ab00-558ffcc9a21g"

Remove Users From Group

Remove-XoGroupUser -Session $Session -Id "9ace51e1-dfbd-4617-8db3-88f28974e111" -UserId "06754190-adbf-46a9-ab00-558ffcc9a22f"

ACL

Get ACL

Get-XoAcl -Session $Session

Add ACL

Where object is te target object (VM, Network, Storage,Etc...) and subject is the user or group

New-XoAcl -Session $Session -Subject "8054b324-3c01-4g6a-5b0a-3e8ccdb8c454" -Object "cbdb27va-0ad1-972d-9532-dcg6b7rf95fd" -Action "admin"

Remove ACL

Remove-XoAcl -Session $Session -Subject "8054b336-3c07-4f6f-8b0a-3e8ccdb8c454" -Object "cbdb37be-0ad2-972a-9537-ccc6a7ff95fd" -Action "admin"

Remotes

Get Remotes

Get-XoRemote -Session $Session

Test Remotes

Test-XoRemote -Session $Session -Id "85eccfa2-5657-4709-9feb-391aaab5c6dd"

Create New Remote

New-XoRemote -Session $Session -Name "test" -Url "nfs://10.0.0.99:/mnt/MyShares/test"

Update Remotes

Update-XoRemote -Session $Session -Name "New Remote Name"

Remove Remotes

Remove-XoRemote -Session $Session -Id "8054b336-3c07-4f6f-8b0a-3e8ccdb8c454"

Server

Get servers

Get-XoServer -Session $Session

Enable Server

Enable-XoServer -Session $Session -Id "8054b336-3c07-4f6f-8b0a-3e8ccdb8c454"

Disable Server

Disable-XoServer -Session $Session -Id "8054b336-3c07-4f6f-8b0a-3e8ccdb8c454"

Remove Server

Remove-XoServer -Session $Session -Id "8054b336-3c07-4f6f-8b0a-3e8ccdb8c454"

Add server

$secure = ConvertTo-SecureString -String "password" -AsPlainText -Force
$Creds = [pscredential]::new("username",$secure)
Add-XoServer -Session $Session -Server 10.0.1.10 -Credential $Creds -LabelName "Xen01" -AllowUnauthorizedCerts:$true

Update Server

Update-XoServer -Session $Session -Id "19ee9e08-75a3-4aa0-a21b-208e6d779a92" -LabelName "Xen03"

Roles

Get all roles

Get-XoRole -Session $Session

SR

Get all SRs

Get-XoSr -Session $Session

Get SR by Name

Get-XoSr -Session $Session -Name "MySR"

Get SR by Id

Get-XoSr -Session $Session -Id "19ee9e08-75a3-4aa0-a21b-208e6d779a92"

Add NFS SR

$MyHost = Get-XoHost -Session $Session -Name "xen01"
Register-XoSrNfs -Session $Session -HostId $MyHost.Id -Name "MyShare Test" -Descritpion "Test File Share" -Server "10.0.0.9" -ServerPath "/mnt/FileShares/test"

Forget SR

Unregister-XoSr -Session $Session -Id "19ee9e08-75a3-4aa0-a21b-208e6d779a92" -Confirm:$false

Remove SR

Remove-XoSr -Session $Session -Id "19ee9e08-75a3-4aa0-a21b-208e6d779a92"

Enable SR Maintenance Mode

Enable-XoSrMaintenanceMode -Session $Session -Id "a933cb47-fbf7-42a5-af39-abac9fc3feca"

Disable SR Maintenance Mode

Disable-XoSrMaintenanceMode -Session $Session -Id "a933cb47-fbf7-42a5-af39-abac9fc3feca"

Scan SR

Start-XoSrScan -Session $Session -Id "a933cb47-fbf7-42a5-af39-abac9fc3feca"

Rename SR

Rename-XoSr -Session $Session Id "a933cb47-fbf7-42a5-af39-abac9fc3feca" -Name "MySR Test" -Descritpion "Test SR"

Schedule

Get Schedules

Get-XoSchedule -Session $Session

Get Schedule by Name

Get-XoSchedule -Session $Session -Name "Daily"

Create new Schedule

New-XoSchedule -Session $Session -Cron "0 0 * * *" -Name "Test"

Remove Schedule

Remove-XoSchedule -Session $Session -Id "a933cb47-fbf7-42a5-af39-abac9fc3feca"

Update Schedule

Update-XoSchedule -Session $Session Id "a933cb47-fbf7-42a5-af39-abac9fc3feca" -Name "New Name"

Pool

Get Missing patches

Get-XoPoolMissingPatch -Session $Session -HostId "9ace51e1-dfbd-4617-8db3-88f28974e111"

Set Default SR

Set-XoPoolDefaultSr -Session $Session -SrId "83c69122-1efc-8224-f7d4-c645e86936bc"

Set Pool Master

Set-XoPoolMaster -Session $Session -HostId "9ace51e1-dfbd-4617-8db3-88f28974e111"

About

Xen Orchestra Powershell module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors