StoreFront

店面 PowerShell 的管理模块

Citrix StoreFront 提供了多个 Microsoft Windows PowerShell 2.0 版模块,这些模块在您安装 StoreFront 时会包含在内。借助这些模块,您可以执行与使用 StoreFront 管理控制台 相同的任务,以及仅凭控制台无法完成的任务。

注意:

思杰店面 PowerShell 模块与 PowerShell 6 或更高版本不兼容。

有关 PowerShell 模块参考,请参阅 StoreFront 开发人员文档

开始使用

  1. 确保 StoreFront 管理控制台已关闭。

  2. 启动 PowerShell 命令行提示符窗口或 Windows PowerShell ISE,并以管理员权限运行。

    您必须使用 StoreFront 服务器上本地管理员组的成员身份运行 shell 或脚本。

  3. 要在脚本中使用 cmdlet,请将 PowerShell 中的执行策略设置为 RemoteSigned。有关 PowerShell 执行策略的更多信息,请参阅 Microsoft 文档

  4. 您可以使用 示例脚本 作为起点。

  5. 使用 Get-Help cmdlet 并提供 cmdlet 名称和 -Full 参数,以获取有关特定命令的更多信息。

虚拟路径

用于获取或创建应用商店、网站或身份验证服务的 cmdlet 接受 VirtualPath 参数。这是应用程序在 IIS 中托管的路径。应用商店和网站路径也可以在 StoreFront 管理控制台中找到。通常,按照惯例,身份验证路径与带有后缀 Auth 的应用商店路径相同,而网站路径与带有后缀 Web 的应用商店路径相同。例如,对于应用商店虚拟路径 /Citrix/Store,身份验证服务的路径为 /Citrix/StoreAuth,网站的路径为 /Citrix/StoreWeb

例如,要获取路径为 /Citrix/Store 的应用商店服务,请运行命令:

Get-STFStoreService -VirtualPath '/Citrix/Store'
<!--NeedCopy-->

如果您省略 VirtualPath,则它会返回所有服务。如果只有一个服务,则 PowerShell 会将其视为单个对象。

站点 ID

某些 cmdlet 包含 SiteId 参数。如果您在同一服务器上的不同 IIS 站点上部署了多个部署,则必须指定 SiteId。如果您只有一个站点,则不需要该参数。

示例脚本

StoreFront 包含一些可供参考的示例脚本,这些脚本可以在 %ProgramFiles%\Citrix\Receiver StoreFront\PowerShellSDK\Examples 文件夹路径中找到。您可以将这些脚本用作创建您自己的个性化脚本的参考模板。

-  Use the PowerShell ISE, Visual Studio Code or a similar tool to edit the script.
-  Use variables to assign values that are to be reused or modified.
-  Remove any commands that are not required.
-  Note that StoreFront cmdlets can be identified by the prefix STF.
示例 功能描述
创建一个简单的部署 脚本:创建一个简单部署,其中包含配置了单个 CVAD 站点的 StoreFront 控制器。
创建远程访问部署方案 脚本:基于上一个脚本,为部署添加远程访问。
创建具有最佳启动网关的远程访问部署 脚本:基于上一个脚本,添加首选的最佳启动网关以提供更好的用户体验。

创建简单的部署

以下示例展示了如何创建配置了一个 CVAD 站点的简单部署。

在开始之前,请确保您遵循 Get Started 中详述的步骤。此示例可以自定义以生成用于自动化 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 服务。-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-->
    
  • 如果在指定的虚拟路径上不存在,则创建新的存储服务,该服务配置有一个站点(也称为场),其中包含在数组 $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 虚拟路径添加一个网站,以访问在上面创建的存储中发布的应用程序。

     # 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 服务,以便旧版 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-->
    

示例:创建远程访问部署

以下示例在前一个脚本的基础上添加了一个具有远程访问功能的部署。

在开始之前,请确保您遵循 Get Started 中详述的步骤。此示例可以使用所述方法进行自定义,以生成用于自动化 StoreFront 部署的脚本。

本节解释了 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-->
    
  • 在 思杰接收器™ for Web 服务上启用 思杰AGBasic,这是使用 思杰网关 进行远程访问所必需的。从支持的协议中获取 思杰接收器™ for Web 的 思杰AGBasic 和 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-->
    

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

以下示例基于之前的脚本,添加了一个具有最佳启动网关远程访问的部署。

在开始之前,请确保您遵循 入门 中详细介绍的步骤。可以使用所述方法自定义此示例,以生成用于自动化 StoreFront 部署的脚本。

了解脚本的用法

本节解释了 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-->
    
店面 PowerShell 的管理模块