Skip to content

Commit

Permalink
Merge pull request #5191 from kc284/ps51
Browse files Browse the repository at this point in the history
CP-45579: Restored support for building the PowerShell module against…
  • Loading branch information
kc284 authored Oct 16, 2023
2 parents 4a3a3b3 + 75eb28e commit 9039796
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 4 deletions.
163 changes: 163 additions & 0 deletions ocaml/sdk-gen/powershell/README_51.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
XenServer PowerShell Module
===========================

Copyright (c) 2013-2023 Cloud Software Group, Inc. All Rights Reserved.

The XenServer PowerShell Module is a complete SDK for XenServer,
exposing the XenServer API as Windows PowerShell cmdlets.

The XenServer PowerShell Module includes a cmdlet for each API call,
so API documentation and examples written for other languages will apply equally
well to PowerShell. In particular, the SDK Guide and the Management API Guide
are ideal for developers wishing to use this module.

This module is free software. You can redistribute and modify it under the
terms of the BSD 2-Clause license. See LICENSE.txt for details.


Reference
---------

For XenServer documentation see https://docs.xenserver.com

The XenServer Management API Reference is available at
https://docs.xenserver.com/en-us/xenserver/8/developer/management-api

The XenServer Software Development Kit Guide is available at
https://docs.xenserver.com/en-us/xenserver/8/developer/sdk-guide

A number of examples to help you get started with the SDK is available at
https://github.com/xenserver/xenserver-samples

For community content, blogs, and downloads, visit
https://www.xenserver.com/blogs and https://www.citrix.com/community/

To network with other developers using XenServer visit
https://discussions.citrix.com/forum/101-hypervisor-formerly-xenserver/


Prerequisites
-------------

This library requires .NET Framework 4.5 or greater and PowerShell 5.1 or greater.


Dependencies
------------

The XenServer PowerShell Module is dependent upon the following libraries:

- Newtonsoft JSON.NET by James Newton-King (see https://www.newtonsoft.com/).
JSON.NET is licensed under the MIT license; see LICENSE.Newtonsoft.Json.txt
for details. A patched version of the library (Newtonsoft.Json.CH.dll) is
shipped with the XenServer PowerShell Module.

- XenServer.NET by Cloud Software Group, Inc.
XenServer.NET is a complete SDK for XenServer, exposing the XenServer
API as .NET classes. It is written in C#.


Folder Structure
----------------

This archive contains the following folders that are relevant to PowerShell users:

- XenServerPowerShell\XenServerPSModule: this is the XenServer PowerShell
Module
- XenServerPowerShell\src: contains the C# source code for the XenServer
cmdlets shipped as a Visual Studio project.


Getting Started
---------------

1. Extract the contents of this archive.

Note that 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
archive before extracting its contents. To unblock the archive, right-click
on it and launch the Properties dialog. Click the Unblock button, then the
Apply or OK button.

2. Navigate to the extracted XenServerPowerShell directory and copy the whole
folder XenServerPSModule into your PowerShell modules directory.

- On Windows this will normally be $env:UserProfile\Documents\WindowsPowerShell\Modules
for per-user configuration, or $env:windir\system32\WindowsPowerShell\v1.0\Modules for
system-wide configuration.

For more information see PowerShell's documentation on module paths:

PS> Get-Help about_PSModulePath

3. Open a PowerShell prompt as administrator.

To do this, open the Windows Start menu by clicking the Start icon, find
the item PowerShell, right click it and select Run as administrator.

4. Determine the current execution policy:

PS> Get-ExecutionPolicy

If the current policy is Restricted, you need to set it to RemoteSigned:

PS> Set-ExecutionPolicy RemoteSigned

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

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 to RemoteSigned, as above.

If the current policy is RemoteSigned, ByPass, or Unrestricted there is
nothing to do.

5. Exit the privileged instance of PowerShell.

6. Open a PowerShell prompt as a regular user (click Start > PowerShell)
and import the XenServer PowerShell Module:

PS> Import-Module XenServerPSModule

7. If you wish to load specific environment settings when the XenServer
PowerShell module is loaded, create the file XenServerProfile.ps1 and put it
in the folder containing your $PROFILE file for per-user configuration, or
in $PSHOME for system-wide configuration.

- On Windows these will normally be $env:UserProfile\Documents\WindowsPowerShell
for per-user configuration, or $env:windir\system32\WindowsPowerShell\v1.0 for
system-wide configuration.

8. For an overview of the XenServer PowerShell Module type:

PS> Get-Help about_XenServer

You can obtain a list of all available cmdlets by typing:

PS> Get-Command -Module XenServerPSModule

For help with a specific command use:

PS> Get-Help [CommandName]

9. Here is a quick example of opening a session and making a call to a server:

PS> Connect-XenServer -Url https://<servername>
PS> Get-XenVM
PS> Disconnect-XenServer


Building and Debugging the Source Code
--------------------------------------

1. Open the project XenServerPowerShell.csproj in Visual Studio 2022. You should
now be ready to build the source code.

2. If in Debug mode, clicking Start will launch a PowerShell 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 XenServerPSModule). You should now be ready to debug the cmdlets.
2 changes: 1 addition & 1 deletion ocaml/sdk-gen/powershell/autogen/XenServerPSModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CompanyName = 'Cloud Software Group, Inc'
Copyright = 'Copyright (c) 2013-2023 Cloud Software Group, Inc. All rights reserved.'

# Requirements
PowerShellVersion = '7.2'
PowerShellVersion = '@PS_VERSION@'
PowerShellHostName = ''
PowerShellHostVersion = ''
ProcessorArchitecture = 'None'
Expand Down
9 changes: 9 additions & 0 deletions ocaml/sdk-gen/powershell/autogen/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
(action (copy %{deps} %{targets}))
)

(rule
(targets README_51.txt)
(deps
../README_51.dist
)
(action (copy %{deps} %{targets}))
)

(alias
(name generate)
(deps
LICENSE.txt
README.txt
README_51.txt
(source_tree .)
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.0.0</Version>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net45</TargetFrameworks>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)|$(OS)' == 'Debug|AnyCPU|Windows_NT'">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)|$(OS)' == 'Debug|AnyCPU|Windows_NT' And '$(TargetFramework)' == 'net6.0'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\PowerShell\7\pwsh.exe</StartProgram>
<StartArguments>-NoLogo -NoExit -Command "Import-Module '.\XenServerPowerShell.dll'"</StartArguments>
</PropertyGroup>
<ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)|$(OS)' == 'Debug|AnyCPU|Windows_NT' And '$(TargetFramework)' == 'net45'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
<StartArguments>-NoLogo -NoExit -Command "Import-Module '.\XenServerPowerShell.dll'"</StartArguments>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Management.Automation" Version="7.2.6" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="XenServer">
<SpecificVersion>False</SpecificVersion>
Expand Down

0 comments on commit 9039796

Please sign in to comment.