Jump to content
Welcome to our new Citrix community!
  • 0

Powershell Core / 6 and Citrix Snapins


Jason Edelen1709160707

Question

I've heard that Microsoft is phasing out Powershell in favor of Powershell Core.  there will be no more versions or features of the existing Powershell and all new development will gear towards Powershell Core / 6 and above.  One thing I found is that they are not using Snapins in the new powershell.  Snapins are supposed to be replaced by modules.  Does anyone know if this is something that Citrix is working on?

 

You cannot use Add-PSSnapin citrix* to load the cmdlets for Citrix in Powershell Core.  The Add-PSSnapin cmdlet is missing from that version and above.

Link to comment

13 answers to this question

Recommended Posts

  • 0

I've still not managed to make it work on Powershell 6 or 7 (Powershell Core).

 

It seems the module is just a wrapper around the snap-ins. So ultimately what fails with the loading is that Snap-Ins are not supported anymore on Powershell Core.

 

But if i'm wrong and anyone can make those modules work on Powershell Core that would be a great help to reply to this thread.
Because Microsoft is not going to bring back support to those Snap-Ins and it's a blocking point when you move to .NET Core/Powershell Core.

xendesktopmoduleimport.PNG

Link to comment
  • 0

Both PowerShell v6 and v7 are based on .NET Core (rather than .NET Framework as in previous versions). I would like to start by saying that PowerShell Core (as these new versions are called) is NOT widely adopted and majority of scripts requires PowerShell 5.1 version. As far as I can say, this includes ALL products from Citrix (including not only CVAD, but also Optimizer and others).

 

On surface, it might look that only problem are snap-ins, but that’s not correct. Some of the .NET features that are missing are support for AD interaction and support for WCF – both technologies that are critical part of FMA architecture.

 

This means that v6/v7 (or newer) will not work with CVAD unless there are significant changes to the existing code. Since broad support (and adoption) of v6/v7 is very low right now, I don't expect support for PowerShell Core anytime soon - for PowerShell modules that is.

This comment is related to traditional PowerShell cmdlets - you can use REST API from PowerShell Core instead (if you are Citrix Cloud customer): https://developer.cloud.com/virtual-apps-and-desktops/

Link to comment
  • 0

Thanks for the answer.

Got the same from twitter.

 

I would have like another option to use CVAD APIs but it seems i'll need to continue using some workaround to get it working.

I'm not a Citrix Cloud Customer but a Citrix on Premise. I don't have access to the REST API but i would love to have access to another way (a RESTful API) than the snap-ins to execute actions on CVAD than powershell.

Link to comment
  • 0

Hello,

 

There are no REST API available for Citrix On-Premise.

Only way you can interact with CVAD to do automation is through their Powershell SDK (Only working for Powershell 5 / .NET up to 4.8)

 

Since I'm using C#/.NET Core to create automation tools for my company I found a workaround :

 

Citrix CVAD SDK is only targeting Powershell 5 and .NET (up to 4.8) :

Problem : since Powershell Core (6/7) is based on .NET Core (or .NET 5 now) we can't start a Powershell Core host within our C# program to add the modules/snapin because .NET is not compatible with .NET Core.

Solution : I start from a Powershell Core host a remote powershell 5 session on my brokers and execute my commands there.

 

I would love to see something more user friendly like a REST API with a OpenAPI specification (Swagger) would be a nice tool to use for future developments.

Link to comment
  • 0
On 7/30/2021 at 11:55 PM, Diego Medjdoub said:

Hello,

 

There are no REST API available for Citrix On-Premise.

Only way you can interact with CVAD to do automation is through their Powershell SDK (Only working for Powershell 5 / .NET up to 4.8)

 

Since I'm using C#/.NET Core to create automation tools for my company I found a workaround :

 

Citrix CVAD SDK is only targeting Powershell 5 and .NET (up to 4.8) :

Problem : since Powershell Core (6/7) is based on .NET Core (or .NET 5 now) we can't start a Powershell Core host within our C# program to add the modules/snapin because .NET is not compatible with .NET Core.

Solution : I start from a Powershell Core host a remote powershell 5 session on my brokers and execute my commands there.

 

I would love to see something more user friendly like a REST API with a OpenAPI specification (Swagger) would be a nice tool to use for future developments.

This is interesting.Can you please share me how to host remote PowerShell 5 session on brokers from powershell core. Any sample code using C# will be highly appreciated. I have been struggling almost an year to execute citrix commands from my dot net core project. Any help will be appreciated.

Link to comment
  • 0

Because we also have to transfer all our scripting to Powerpoint 7, i use things like:

 

import-module "Citrix.broker.commands" -UseWindowsPowerShell

 

This makes an 'implicit remote' to a local session in WindowsPowershell. Most of the functionality seems to work well. The only problem i found so far is when returned objects have child-objects. E.g.:

get-BrokerAccessPolicyRule and get-BrokerEntitlementPolicyRule return objects which have an attribute 'IncludedUsers'. This should be an array of user objects, but instead, if gives an array of strings with the type-name of these objects.

This looks like a problem of the serialization in WindowsPowershell: if i take the output of these commandlets in WindowsPowershell 5.1 (with correct data) and pipe it to ConvertTo-Xml, it doesn't include the user objects either.

 

Actually, i am surprised that there is so much .Net dependency in the API. I would expect that the Powershell Api doesn't do any smart things but only communicates with a servers.

 

 

 

 

Link to comment
  • 0

For now, my quick-and-dirty solution is:

 

 

$RemoteBrokerSession = New-PSSession -ComputerName $BrokerServerName

 

function ExecuteOnBroker{

    param (

        [Parameter(Mandatory=$true, ValueFromPipeline=$false, Position=0,HelpMessage="the command to execute")] [String]$commandName,

        [Parameter(Mandatory=$false, ValueFromPipeline=$false, Position=1,HelpMessage="Optional: a hashtable with parameters")] [hashtable]$parameters

    )

    $script = "[System.Management.Automation.PSSerializer]::Serialize(("

    $script += $CommandName

    $parameters.getEnumerator()|ForEach-Object{ $script += " -" + $_.name + " " + $_.value}

    $script += "),10)"

    $scriptBlock = [scriptblock]::create($script)

    $clixml = invoke-command  -Session $RemoteBrokerSession -ScriptBlock $scriptBlock

    Return [System.Management.Automation.PSSerializer]::DeSerialize($clixml)

}

 

The Serialize method of a remote PSSerializer get all output of the executed cvad commandlet and serializes it to a depth of 10

and then a local Deserialize method converts this back into generic PsObject objects, which are similar (but not identical) to what the commandlet would have returned.

The normal remote command execution serializes to a depth of 2 and could miss child-objects in the returned data.

 

and of course, in the 'finally' part of the script:  remove-pssession -Session $RemoteBrokerSession

 

There seems to be a problem with parameter splatting in remote commands so i simply wrote them out into a string.

With some more effort, we (or Citrix) could make a module with proxies for all cvad commandlets. Then, the commandlets could have proper parameters and types.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...