PowerShell Automated Export and Import of StoreFront Subscription Database
When upgrading the Windows Server OS on Storefront servers the best way is probably to just build new VM’s alongside the production servers. This allows for a seamless migration. Citrix provides a few PowerShell lines which will make you able to migrate the whole Storefront configuration with Import and Export commandlets in PowerShell. This proces is very easy and works good in my own experiences.
But when it comes to the Subscription database this is not migrated with the configuration of Storefront. It would be possible to manually copy files or use other trivial ways. I chose to create a script which you can run on source and destination Storefront servers which will export all stores Subscriptions.
The script can/will do the following:
- Ask if you want to Import or Export a Subscription database on Storefront
- Automatically get all stores from WWWroot folder and append them to a array
- Create .txt files with each the stores subscriptions
- Automatically import the subscriptions, assuming you have exported the old Storefront configuration to a new server
#############################################################################
#
# Name : PowerShell Automated Export and Import of StoreFront Subscription Database
# Created By: Silas Arentsen
# Purpose : Export and/or Import a .txt file(s) of Subscription database information per Store.
#
##############################################################################
"C:\Program Files\Citrix\Receiver StoreFront\Scripts\ImportModules.ps1“
##
# Export part
##
function Export-STFSubDB {
$AllStores = Get-ChildItem -Path C:\inetpub\wwwroot\Citrix | Where-Object {$_.Name -notmatch "Auth" -and $_.Name -notmatch "Web"}
#Create Folder
New-Item -ItemType Directory "$env:userprofile\desktop\ExportSUBDB"
foreach ($Store in $AllStores.Name){
Write-Host "Getting Sub DB from: " $Store
$OriginalStore = Get-STFStoreService /Citrix/$Store
Export-STFStoreSubscriptions -Store $OriginalStore -FilePath "$env:userprofile\desktop\ExportSUBDB\$($Store).txt"
$OriginalStore = ""
Write-Host "Wait 10 seconds for next export"
Start-Sleep 10
}
}
##
# Import part
##
function Import-STFSubDB {
$AllStoresImport = Get-ChildItem -Path "$env:userprofile\desktop\ExportSUBDB\"
foreach ($ImportStore in $AllStoresImport.Name){
$ImportStore = $ImportStore -replace ".txt",""
$NewStore = Get-STFStoreService /Citrix/$ImportStore
Write-Host "Importing Sub DB from: " $ImportStore
Import-STFStoreSubscriptions -Store $NewStore -FilePath "$env:userprofile\desktop\ExportSUBDB\$($ImportStore).txt"
}
}
do{
$Prompt = Read-host "Would you like to do an (E)xport or (I)mport? (E | I)"
Switch -Wildcard ($Prompt)
{
"E"
{
Export-STFSubDB
}
"I"
{
Import-STFSubDB
}
}
} while($prompt -notmatch "[EI]")

Started working in IT since 2016 for several Managed Service Providers. IT is always changing, which is why I like to learn from others. A challenge is never too much and will try to get my work up to a higher level each time.
Personal characteristics:
Motivated, calm, sincere and honest
Free time spending:
Kickboxing, technology, cars and day trips
Leave a Reply
Want to join the discussion?Feel free to contribute!