# Wrapping Windows Phone8 # This Scripts wrapps all WinPhone8 apps in UnwrappedApps Folder # Mauricio Schaepers #setting Folder $FolderUnwrappedApps = "C:\UnwrappedApps" $FolderWrappedApps = "C:\WrappedApps" $FolderMDXToolkit = "C:\MDXToolKit" #Setting Options $PFXPath = "C:\Microsoft\Certificate.pfx" $PFXPassword = "mypw" $phonePublisherId = "aaaaaaaa-bbbb-cccc-dddd- eeeeeeeeeeee" $mdmURLsTXT = "C:\MDXToolKit\mdmURLs.txt" #Setting Errorflag to false $MissingRequirements = $false #Checking User Input ##Check if $FolderWrappedApps exists if (!(Get-Item $FolderWrappedApps).Exists){ Write-Host "$FolderWrappedApps not found, creating it" New-Item -ItemType Directory -Path $FolderWrappedApps $FolderWrappedApps = (Get-Item $FolderWrappedApps).FullName } else { $FolderWrappedApps = (Get-Item $FolderWrappedApps).FullName } ##Check if $FolderUnwrappedApps exists if (!(Get-Item $FolderUnwrappedApps).Exists){ Write-Warning "$FolderUnwrappedApps not found" Write-Warning "Unable to proceed, make sure $FolderUnwrappedApps exists containing WP8 Apps" $MissingRequirements = $true } else { $FolderUnwrappedApps = (Get-Item $FolderUnwrappedApps).FullName } ##Check if $FolderMDXToolkit exists if (!(Get-Item $FolderMDXToolkit).Exists){ Write-Warning "$FolderMDXToolkit not found" Write-Warning "Unable to proceed, make sure $FolderMDXToolkit exists containing the Citrix Windows Phone Wrapper" $MissingRequirements = $true } else { $FolderMDXToolkit = (Get-Item $FolderMDXToolkit).FullName #Check if $FolderMDXToolkit contains CGAppPrepTool $MDXToolkitExe = "$FolderMDXToolkit\CGAppPrepTool.exe" if (!(Get-Item $MDXToolkitExe).Exists){ Write-Warning "$MDXToolkitExe not found" Write-Warning "Unable to proceed, download the WP8 Wapper from the Citrix Download Portal" $MissingRequirements = $true } } ##Check if Certificate exists if (!(Get-Item $PFXPath).Exists){ Write-Warning "$PFXPath not found" Write-Warning "Unable to proceed, make sure $PFXPath exists containing the Certificate deliveredby Symantec" $MissingRequirements = $true } else { $PFXPath = (Get-Item $PFXPath).FullName #Check if certificate is readable and correct if (!(New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($PFXPath, $PFXPassword)).Verify()){ Write-Warning "Unable to proceeed, password to $PFXPath is incorrect or certificate in not valid" $MissingRequirements = $true } } ##Check if $mdmURLsTXT exists if (!(Get-Item $mdmURLsTXT).Exists){ Write-Warning "$mdmURLsTXT not found" Write-Warning "Unable to proceed, make sure $mdmURLsTXT exists containing ServerURLs, each per line" $MissingRequirements = $true } else { $colmdmURLs = Get-Content $mdmURLsTXT } if ($MissingRequirements -eq $false){ #All script preparations are done, let's start wrapping! Write-Host "Start wrapping" #Collect all apps in UnwrappedApps Folder excluding directories $colUnwrappedApps = Get-ChildItem $FolderUnwrappedApps | Where-Object {!($_.PSisContainer)} #Let us sort apps, right now just WorxHome, WorxMail and WorxWeb are known $colUnwrappedAppsWorxHome = @() $colUnwrappedAppsWorxWeb = @() $colUnwrappedAppsWorxMail = @() $colUnwrappedAppsUnknown =@() foreach ($App in $colUnwrappedApps){ switch ($App.Name) { {($_ -like "*WorxHome*")}{ $colUnwrappedAppsWorxHome += $App; break} {($_ -like "*WorxWeb*")}{ $colUnwrappedAppsWorxWeb += $App; break} {($_ -like "*WorxMail*")}{ $colUnwrappedAppsWorxMail += $App; break} default { Write-Host "$App.Name is unknown, we can give a try" $colUnwrappedAppsWorxMail += $App} } } #Build MDX Apps ## Wrapping WorxHome foreach ($file in $colUnwrappedAppsWorxHome){ foreach ($mdmServerURL in $colmdmURLs) { #Create for each MDM Server a WorxHome file $mdmURI = $mdmServerURL |%{New-Object System.Uri $_} #Create temporary Workspace $XAPFile = $FolderWrappedApps + "\" + $file.BaseName + $mdmURI.DnsSafeHost + ".xap" #Execute Wrapper & $MDXToolkitExe -in:$File.FullName -out:$XAPFile -C:$PFXPath -password:$PFXPassword -verbose -resign -phonePublisherId:$phonePublisherId -mdmServerUrl:$mdmURI.AbsoluteUri #Remote existing file if it exists if (Test-Path $FolderWrappedApps\Temp){ Remove-Item $FolderWrappedApps\Temp -Recurse } ############### ##This section is buggy, as soon as using -out the xap file gets currupted ##Support Case 67438645 ############### #Create temporary Workspace #$TempWorkfolder = New-Item -ItemType Directory -Path ($FolderWrappedApps + "\" + $file.BaseName) #$TempMDXFile = [string]$TempWorkfolder + "\" + $file.BaseName + ".mdx" #Build final Name #$MDXFile = $FolderWrappedApps + "\" + $file.BaseName + $mdmURI.DnsSafeHost + ".mdx" #Execute Wrapper #& $MDXToolkitExe -in:$File.FullName -out:$TempMDXFile -C:$PFXPath -password:$PFXPassword -verbose -resign -phonePublisherId:$phonePublisherId -mdmServerUrl:https://mdm.adn.de/zdm #Move MDX to destination folder #Move-Item -Path $TempMDXFile -Destination $MDXFile -Force #Remove $TempWorkfolder #Remove-Item $TempWorkfolder -Recurse ########## ##Buggy code stop ########## } } ## Wrapping WorxWeb foreach ($file in $colUnwrappedAppsWorxWeb){ #Create temporary Workspace $TempWorkfolder = New-Item -ItemType Directory -Path ($FolderWrappedApps + "\" + $file.BaseName) $TempMDXFile = [string]$TempWorkfolder + "\" + $file.BaseName + ".mdx" #Build final Name $MDXFile = $FolderWrappedApps + "\" + $file.BaseName + ".mdx" #Execute Wrapper & $MDXToolkitExe -in:$File.FullName -out:$TempMDXFile -T:"$FolderMDXToolkit\Templates\WorxWeb" -C:$PFXPath -password:$PFXPassword -verbose -resign -phonePublisherId:$phonePublisherId #Move MDX to destination folder Move-Item -Path $TempMDXFile -Destination $MDXFile -Force #Remove $TempWorkfolder Remove-Item $TempWorkfolder -Recurse } ## Wrapping WorxMail foreach ($file in $colUnwrappedAppsWorxMail){ #Create temporary Workspace $TempWorkfolder = New-Item -ItemType Directory -Path ($FolderWrappedApps + "\" + $file.BaseName) $TempMDXFile = [string]$TempWorkfolder + "\" + $file.BaseName + ".mdx" #Build final Name $MDXFile = $FolderWrappedApps + "\" + $file.BaseName + ".mdx" #Execute Wrapper & $MDXToolkitExe -in:$File.FullName -out:$TempMDXFile -T:"$FolderMDXToolkit\Templates\WorxMail" -C:$PFXPath -password:$PFXPassword -verbose -resign -phonePublisherId:$phonePublisherId #Ask user if existing file should be overwriten #if (Test-Path $MDXFile){ # Write-Host "$MDXFile does already exist, do you want to remove the existing one?" # Remove-Item -Path $MDXFile -Confirm #} #Move MDX to destination folder Move-Item -Path $TempMDXFile -Destination $MDXFile -Force #Remove $TempWorkfolder Remove-Item $TempWorkfolder -Recurse } }