StoreFront

StoreFront SDK

Citrix StoreFront 提供基于多个 Microsoft Windows PowerShell 2.0 模块的 SDK。通过 SDK,可以执行能够通过 StoreFront MMC 控制台完成的任务,也可以执行单独通过控制台无法完成的任务。

注意:

PowerShell SDK 与 PowerShell 6 或更高版本不兼容。

有关 SDK 参考,请参阅 StoreFront SDK

使用 SDK

SDK 由多个 PowerShell 管理单元组成,在安装和配置各种 StoreFront 组件时,安装向导会自动安装这些管理单元。

访问并运行 cmdlet:

  1. 以管理员身份启动 PowerShell 命令行提示符或 Windows PowerShell ISE

    必须在 StoreFront 服务器上使用多个本地管理员组运行 shell 或脚本。

  2. 要在脚本内使用 SDK cmdlet,应在 PowerShell 中设置执行策略。

    有关 PowerShell 执行策略的详细信息,请参阅 Microsoft 文档。

  3. 在 Windows PowerShell 控制台中使用 Add -Module 命令将需要的模块添加到 PowerShell 环境中。例如,键入:

    Import-Module Citrix.StoreFront

    要导入所有 cmdlet,请键入:

    Get-Module -ListAvailable | Where-Object { $_.Name.StartsWith("Citrix.StoreFront") } | Import-Module

导入后,可以访问 cmdlet 及其关联帮助。

SDK 入门

要创建脚本,请执行以下步骤:

  1. 以所提供的 StoreFront 安装到 %ProgramFiles%\Citrix\Receiver StoreFront\PowerShellSDK\Examples 文件夹中的其中一个 SDK 为例。
  2. 为帮助您自定义自己的脚本,请查看示例脚本以了解每个部分的作用。有关详细信息,请参阅示例用例,其中详细解释了脚本所进行的操作。
  3. 转换并修改示例脚本,将其转变成更适用的脚本。为此,您需要:
    • 使用 PowerShell ISE 或类似的工具编辑脚本。
    • 使用变量分配要重复使用或修改的值。
    • 删除任何不需要的命令。
    • 请注意,可以通过前缀 STF 标识 StoreFront cmdlet。
    • 使用 Get-Help cmdlet 可提供 cmdlet 名称,使用 -Full 参数可获取特定命令的相关详细信息。

示例

注意:

创建脚本时,为确保始终获得最新的增强功能和修复,Citrix 建议您按照本主题中所述的步骤进行操作,而不要复制粘贴示例脚本。

示例 说明
创建简单部署 脚本:创建包含 StoreFront Controller 并且配置了一台 XenDesktop 服务器的简单部署。
创建远程访问部署 脚本:在以前的脚本基础上构建,以添加对部署的远程访问。
创建具有最佳启动网关的远程访问部署 脚本:在以前的脚本基础上构建,以添加首选最佳启动网关,从而实现更加卓越的用户体验。

示例:创建简单部署

下例显示了如何创建配置了一个 XenDesktop 控制器的简单部署。

在开始之前,请务必按照 SDK 入门中详述的步骤操作。可以使用介绍的方法对此示例进行自定义,以生成能够自动执行 StoreFront 部署的脚本。

注意:

为确保始终获得最新的增强功能和修复程序,Citrix 建议您按照本文档中所述的过程进行操作,而不是复制粘贴示例脚本。

了解脚本

本部分内容介绍由 StoreFront 生成的脚本的各部分的作用。这将有助于您自定义自己的脚本。

  • 请设置错误处理要求并导入所需的 StoreFront 模块。在较新的 PowerShell 版本中,不需要导入。

     Param(
         [Parameter(Mandatory=$true)]
         [Uri]$HostbaseUrl,
         [long]$SiteId = 1,
         [ValidateSet("XenDesktop","XenApp","AppController","VDIinaBox")]
         [string]$Farmtype = "XenDesktop",
         [Parameter(Mandatory=$true)]
         [string[]]$FarmServers,
         [string]$StoreVirtualPath = "/Citrix/Store",
         [bool]$LoadbalanceServers = $false,
         [int]$Port = 80,
         [int]$SSLRelayPort = 443,
         [ValidateSet("HTTP","HTTPS","SSL")]
         [string]$TransportType = "HTTP"
         )
         # Import StoreFront modules. Required for versions of PowerShell earlier than 3.0 that do not support autoloading
         Import-Module Citrix.StoreFront
         Import-Module Citrix.StoreFront.Stores
         Import-Module Citrix.StoreFront.Authentication
         Import-Module Citrix.StoreFront.WebReceiver
     <!--NeedCopy-->
    
  • 根据提供的 $StoreVirtualPath 自动创建身份验证和 Citrix Receiver for Web 服务的虚拟路径。$StoreVirtualPath$StoreIISpath 等效,因为虚拟路径始终是 IIS 中的路径。因此,在 Powershell 中,它们具有一个值,例如“/Citrix/Store”、“/Citrix/StoreWeb”或“/Citrix/StoreAuth”。

     # Determine the Authentication and Receiver virtual path to use based of the Store
     $authenticationVirtualPath = "$($StoreIISPath.TrimEnd('/'))Auth"
     $receiverVirtualPath = "$($StoreVirtualPath.TrimEnd('/'))Web"
     <!--NeedCopy-->
    
  • 准备创建新部署(如果尚不存在)以添加所需的 StoreFront Service。-Confirm:$false 不要求确认部署可以继续进行。

     # Determine if the deployment already exists
     $existingDeployment = Get-STFDeployment
     if(-not $existingDeployment)
     {
         # Install the required StoreFront components
         Add-STFDeployment -HostBaseUrl $HostbaseUrl -SiteId $SiteId -Confirm:$false
     }
     elseif($existingDeployment.HostbaseUrl -eq $HostbaseUrl)
     {
         # The deployment exists but it is configured to the desired hostbase url
         Write-Output "A deployment has already been created with the specified hostbase url on this server and will be used."
     }
     else
     {
         Write-Error "A deployment has already been created on this server with a different host base url."
     }
     <!--NeedCopy-->
    
  • 在指定的虚拟路径下创建新身份验证服务(如果不存在)。默认身份验证方法(即,用户名和密码)已启用。

     # Determine if the authentication service at the specified virtual path exists
     $authentication = Get-STFAuthenticationService -VirtualPath $authenticationVirtualPath
     if(-not $authentication)
     {
         # Add an Authentication service using the IIS path of the Store appended with Auth
         $authentication = Add-STFAuthenticationService $authenticationVirtualPath
     }
     else
     {
         Write-Output "An Authentication service already exists at the specified virtual path and will be used."
     }
     <!--NeedCopy-->
    
  • 在指定的虚拟路径下创建配置了一个 XenDesktop 控制器且在阵列 $XenDesktopServers 中定义了服务器的新应用商店服务(如果尚不存在)。

     # Determine if the store service at the specified virtual path exists
     $store = Get-STFStoreService -VirtualPath $StoreVirtualPath
     if(-not $store)
     {
     # Add a Store that uses the new Authentication service configured to publish resources from the supplied servers
     $store = Add-STFStoreService -VirtualPath $StoreVirtualPath -AuthenticationService $authentication -FarmName $Farmtype -FarmType $Farmtype -Servers $FarmServers -LoadBalance $LoadbalanceServers `
             -Port $Port -SSLRelayPort $SSLRelayPort -TransportType $TransportType
     }
     else
     {
         Write-Output "A Store service already exists at the specified virtual path and will be used. Farm and servers will be appended to this store."
         # Get the number of farms configured in the store
         $farmCount = (Get-STFStoreFarmConfiguration $store).Farms.Count
         # Append the farm to the store with a unique name
         Add-STFStoreFarm -StoreService $store -FarmName "Controller$($farmCount + 1)" -FarmType $Farmtype -Servers $FarmServers -LoadBalance $LoadbalanceServers -Port $Port `
             -SSLRelayPort $SSLRelayPort -TransportType $TransportType
     }
     <!--NeedCopy-->
    
  • 在指定的 IIS 虚拟路径下添加 Citrix Receiver for Web 服务以访问在上面创建的应用商店中发布的应用程序。

     # Determine if the receiver service at the specified virtual path exists
     $receiver = Get-STFWebReceiverService -VirtualPath $receiverVirtualPath
     if(-not $receiver)
     {
         # Add a Receiver for Web site so users can access the applications and desktops in the published in the Store
         $receiver = Add-STFWebReceiverService -VirtualPath $receiverVirtualPath -StoreService $store
     }
     else
     {
         Write-Output "A Web Receiver service already exists at the specified virtual path and will be used."
     }
     <!--NeedCopy-->
    
  • 为应用商店启用 XenApp Services,以便较旧的 Citrix Receiver 或 Citrix Workspace 应用程序客户端能够连接到已发布的应用程序。

     # Determine if PNA is configured for the Store service
     $storePnaSettings = Get-STFStorePna -StoreService $store
     if(-not $storePnaSettings.PnaEnabled)
     {
     # Enable XenApp services on the store and make it the default for this server
     Enable-STFStorePna -StoreService $store -AllowUserPasswordChange -DefaultPnaService
     }
     <!--NeedCopy-->
    

示例:创建远程访问部署

下例在以前的脚本基础上构建,以添加能够远程访问的部署。

在开始之前,请务必按照 SDK 入门中详述的步骤操作。可以使用介绍的方法对此示例进行自定义,以生成能够自动执行 StoreFront 部署的脚本。

注意:

为确保始终获得最新的增强功能和修复程序,Citrix 建议您按照本文档中所述的过程进行操作,而不是复制粘贴示例脚本。

了解脚本

本部分内容介绍由 StoreFront 生成的脚本的各部分的作用。这将有助于您自定义自己的脚本。

  • 请设置错误处理要求并导入所需的 StoreFront 模块。在较新的 PowerShell 版本中,不需要导入。

     Param(
         [Parameter(Mandatory=$true)]
         [Uri]$HostbaseUrl,
         [Parameter(Mandatory=$true)]
         [long]$SiteId = 1,
         [string]$Farmtype = "XenDesktop",
         [Parameter(Mandatory=$true)]
         [string[]]$FarmServers,
         [string]$StoreVirtualPath = "/Citrix/Store",
         [bool]$LoadbalanceServers = $false,
         [int]$Port = 80,
         [int]$SSLRelayPort = 443,
         [ValidateSet("HTTP","HTTPS","SSL")]
         [string]$TransportType = "HTTP",
         [Parameter(Mandatory=$true)]
         [Uri]$GatewayUrl,
         [Parameter(Mandatory=$true)]
         [Uri]$GatewayCallbackUrl,
         [Parameter(Mandatory=$true)]
         [string[]]$GatewaySTAUrls,
         [string]$GatewaySubnetIP,
         [Parameter(Mandatory=$true)]
         [string]$GatewayName
     )
     Set-StrictMode -Version 2.0
    
     # Any failure is a terminating failure.
     $ErrorActionPreference = 'Stop'
     $ReportErrorShowStackTrace = $true
     $ReportErrorShowInnerException = $true
     # Import StoreFront modules. Required for versions of PowerShell earlier than 3.0 that do not support autoloading
     Import-Module Citrix.StoreFront
     Import-Module Citrix.StoreFront.Stores
     Import-Module Citrix.StoreFront.Roaming
     <!--NeedCopy-->
    
  • 通过调用以前的示例脚本创建一个内部访问 StoreFront 部署。基本部署将扩展为支持远程访问。

     # Create a simple deployment by invoking the SimpleDeployment example
     $scriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
     $scriptPath = Join-Path $scriptDirectory "SimpleDeployment.ps1"
     & $scriptPath -HostbaseUrl $HostbaseUrl -SiteId $SiteId -FarmServers $FarmServers -StoreVirtualPath $StoreVirtualPath -Farmtype $Farmtype `
         -LoadbalanceServers $LoadbalanceServers -Port $Port  -SSLRelayPort $SSLRelayPort -TransportType $TransportType
     <!--NeedCopy-->
    
  • 获取根据更新需要在简单部署中创建的服务以支持远程访问场景。

     # Determine the Authentication and Receiver sites based on the Store
     $store = Get-STFStoreService -VirtualPath $StoreVirtualPath
     $authentication = Get-STFAuthenticationService -StoreService $store
     $receiverForWeb = Get-STFWebReceiverService -StoreService $store
     <!--NeedCopy-->
    
  • 对 Citrix Receiver for Web 服务启用使用 Citrix Gateway 远程访问时所需的 CitrixAGBasic。从支持的协议中获取 Citrix Receiver for Web CitrixAGBasic 和 ExplicitForms 身份验证方法。

     # Get the Citrix Receiver for Web CitrixAGBasic and ExplicitForms authentication method from the supported protocols
     # Included for demonstration purposes as the protocol name can be used directly if known
     $receiverMethods = Get-STFWebReceiverAuthenticationMethodsAvailable | Where-Object { $_ -match "Explicit" -or $_ -match "CitrixAG" }
     # Enable CitrixAGBasic in Receiver for Web (required for remote access)
     Set-STFWebReceiverService $receiverForWeb -AuthenticationMethods $receiverMethods
     <!--NeedCopy-->
    
  • 对身份验证服务启用 CitrixAGBasic。进行远程访问时需要启用。

     # Get the CitrixAGBasic authentication method from the protocols installed.
     # Included for demonstration purposes as the protocol name can be used directly if known
     $citrixAGBasic = Get-STFAuthenticationProtocolsAvailable | Where-Object { $_ -match "CitrixAGBasic" }
     # Enable CitrixAGBasic in the Authentication service (required for remote access)
     Enable-STFAuthenticationServiceProtocol -AuthenticationService $authentication -Name $citrixAGBasic
     <!--NeedCopy-->
    
  • 添加远程访问网关,提供添加可选子网 IP 地址的操作,并在要远程访问的应用商店中注册该网关。

     # Add a new Gateway used to access the new store remotely
     Add-STFRoamingGateway -Name "NetScaler10x" -LogonType Domain -Version Version10_0_69_4 -GatewayUrl $GatewayUrl '
     -CallbackUrl $GatewayCallbackUrl -SecureTicketAuthorityUrls $GatewaySTAUrls
     # Get the new Gateway from the configuration (Add-STFRoamingGateway will return the new Gateway if -PassThru is supplied as a parameter)
     $gateway = Get-STFRoamingGateway -Name $GatewayName
     # If the gateway subnet was provided then set it on the gateway object
     if($GatewaySubnetIP)
     {
         Set-STFRoamingGateway -Gateway $gateway -SubnetIPAddress $GatewaySubnetIP
     }
     # Register the Gateway with the new Store
     Register-STFStoreGateway -Gateway $gateway -StoreService $store -DefaultGateway
     <!--NeedCopy-->
    

示例:创建具有最佳启动网关的远程访问部署

下例在以前的脚本基础上构建,以添加能够远程访问的具有最佳启动网关的部署。

在开始之前,请务必按照 SDK 入门中详述的步骤操作。可以使用介绍的方法对此示例进行自定义,以生成能够自动执行 StoreFront 部署的脚本。

注意:

为确保始终获得最新的增强功能和修复程序,Citrix 建议您按照本文档中所述的过程进行操作,而不是复制粘贴示例脚本。

了解脚本

本部分内容介绍由 StoreFront 生成的脚本的各部分的作用。这将有助于您自定义自己的脚本。

  • 请设置错误处理要求并导入所需的 StoreFront 模块。在较新的 PowerShell 版本中,不需要导入。

     Param(
         [Parameter(Mandatory=$true)]
         [Uri]$HostbaseUrl,
         [long]$SiteId = 1,
         [string]$Farmtype = "XenDesktop",
         [Parameter(Mandatory=$true)]
         [string[]]$FarmServers,
         [string]$StoreVirtualPath = "/Citrix/Store",
         [bool]$LoadbalanceServers = $false,
         [int]$Port = 80,
         [int]$SSLRelayPort = 443,
         [ValidateSet("HTTP","HTTPS","SSL")]
         [string]$TransportType = "HTTP",
         [Parameter(Mandatory=$true)]
         [Uri]$GatewayUrl,
         [Parameter(Mandatory=$true)]
         [Uri]$GatewayCallbackUrl,
         [Parameter(Mandatory=$true)]
         [string[]]$GatewaySTAUrls,
         [string]$GatewaySubnetIP,
         [Parameter(Mandatory=$true)]
         [string]$GatewayName,
         [Parameter(Mandatory=$true)]
         [Uri]$OptimalGatewayUrl,
         [Parameter(Mandatory=$true)]
         [string[]]$OptimalGatewaySTAUrls,
         [Parameter(Mandatory=$true)]
         [string]$OptimalGatewayName
     )
     Set-StrictMode -Version 2.0
     # Any failure is a terminating failure.
     $ErrorActionPreference = 'Stop'
     $ReportErrorShowStackTrace = $true
     $ReportErrorShowInnerException = $true
     # Import StoreFront modules. Required for versions of PowerShell earlier than 3.0 that do not support autoloading
     Import-Module Citrix.StoreFront
     Import-Module Citrix.StoreFront.Stores
     Import-Module Citrix.StoreFront.Roaming
     <!--NeedCopy-->
    
  • 调用到远程访问部署脚本中以配置基本部署并添加远程访问权限。

     # Create a remote access deployment
     $scriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
     $scriptPath = Join-Path $scriptDirectory "RemoteAccessDeployment.ps1"
     & $scriptPath -HostbaseUrl $HostbaseUrl -SiteId $SiteId -FarmServers $FarmServers -StoreVirtualPath $StoreVirtualPath -Farmtype $Farmtype `
         -LoadbalanceServers $LoadbalanceServers -Port $Port  -SSLRelayPort $SSLRelayPort -TransportType $TransportType `
         -GatewayUrl $GatewayUrl -GatewayCallbackUrl $GatewayCallbackUrl -GatewaySTAUrls $GatewaySTAUrls -GatewayName $GatewayName
     <!--NeedCopy-->
    
  • 添加首选最佳启动网关并从所配置的网关列表中获取该网关。

     # Add a new Gateway used for remote HDX access to desktops and apps
     $gateway = Add-STFRoamingGateway -Name $OptimalGatewayName -LogonType UsedForHDXOnly -GatewayUrl $OptimalGatewayUrl -SecureTicketAuthorityUrls $OptimalGatewaySTAUrls -PassThru
     <!--NeedCopy-->
    
  • 获取应用商店服务以使用最佳网关,注册该网关并将其分配给从命名场进行的启动。

     # Get the Store configured by SimpleDeployment.ps1
     $store = Get-STFStoreService -VirtualPath $StoreVirtualPath
     # Register the Gateway with the new Store for launch against all of the farms (currently just one)
     $farmNames = @($store.FarmsConfiguration.Farms | foreach { $_.FarmName })
     Register-STFStoreOptimalLaunchGateway -Gateway $gateway -StoreService $store -FarmName $farmNames
     <!--NeedCopy-->
    
StoreFront SDK