#################### ##bulk Update to Latest## ## Notes ## Please remeber to make a Cred file for Flexapp Packaging Console and ProfileUnity Password.txt ## First time running will produce errors as the applications don't exist. ## Example command ## ## update-FPABatchJob -jobfile "C:\Users\administrator\Desktop\Automation\test.csv" -argfile "C:\Users\administrator\Desktop\argfileDemo.json" -servername "https://pro2020:9075" ## update-ConfigFlexapps -jobfile "C:\Users\administrator\Desktop\Automation\catalog.csv" -configname "Buildv2 - PD" -servername "pro2020" <########################################################################### Update Note 1.2.3 Speed update (no status) 1.2.4 Added EQ instead of Match on most calls. ###########################################################################> ## ProfileUnity Details ## ##Speed up Powershell Process show no progress## $ProgressPreference = 'SilentlyContinue' ## ProfileUnity Server name (E.G. (Prou.server.domain)) ## [string]$global:servername= "pro2020" ## login for proU Console ## $user = "administrator" # Follow run Secure String instruction to make Password and AES file. (path to password.txt)# $passwordFileLocation = "C:\Users\administrator\Desktop\Automation\password.txt" # location of the AESKey # $AESKeyFilePath = "C:\Users\administrator\Desktop\Automation\aeskey.txt" ########################################################################### #$pass=Get-Content $passwordFileLocation | ConvertTo-SecureString #use key and password to create local secure password $AESKey = Get-Content -Path $AESKeyFilePath $pwdTxt = Get-Content -Path $passwordFileLocation $securePass = $pwdTxt | ConvertTo-SecureString -Key $AESKey ## login Function ## function connect-ProfileUnityServer{ ##Ignore-SSL Library Code add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' ##Get Creds #[string]$global:servername= Read-Host -Prompt 'FQDN of ProfileUnity Server Name' $pass2=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securepass)) #Connect to Server Write-host "Logging into ProfileUnity Server" Invoke-WebRequest https://"$servername":8000/authenticate -Body "username=$user&password=$pass2" -Method Post -SessionVariable session $global:session=$session } ######################### ## Supporting Functions ## ######################### ## Load ProfileUnity Configurations function edit-proUconfig([string]$name) { $PUGC = ((Invoke-WebRequest https://"$servername":8000/api/configuration -WebSession $session).Content) | ConvertFrom-Json [string]$configID=$PUGC.Tag.Rows | Where-Object {$_.name -Match $name} | foreach-object {$_.id} $configR= ((Invoke-WebRequest https://"$servername":8000/api/configuration/"$configID" -WebSession $session).Content) | ConvertFrom-Json $config=$configR.tag $global:CurrentConfig = $config } ########################## ## Get Filter ## function get-ProUFilters { $PUG = ((Invoke-WebRequest https://"$servername":8000/api/Filter -WebSession $session).Content) | ConvertFrom-Json $PUG.Tag.Rows } ########################## ## Add-Flexapp to ProUConfig ## function Add-proUFlexAppDia([string]$DIAname, [string]$filtername){ #$dianame1 = get-ProUFlexapps | Where-Object {$_.Name -eq "$DIAname"} $date = get-date $maxver = ((get-ProUFlexapps | Where-Object {$_.name -eq "$DIAname"}).Version | Measure-Object -Maximum).Maximum $global:dianame1 = (get-ProUFlexapps | Where-Object {$_.name -eq "$DIAname" -and $_.Version -eq "$maxver"}) if ($filtername -eq $null){ $filterID = "" }else{ $filterID1 = get-ProUFilters | Where-Object {$_.Name -eq "$filtername"} $filterID = $filterID1.id } $DIAPackage = @{ DifferencingPath="%systemdrive%\FADIA-T\VHDW\%username%" UseJit="False" CacheLocal="False" PredictiveBlockCaching="False" CacheAllLocal="False" FlexAppPackageId=$DIAname1.id FlexAppPackageUuid=$DIAName1.uuid Sequence = "0" } $global:moduleItem = @{ FlexAppPackages=@($DIAPackage); Playback = "0" ReversePlay = "False" FilterId = "$filterID" Description="version $maxver added on $date with PowerTools" Disabled = "False" Sequence = "0" } $currentconfig.FlexAppDias += @($moduleItem) } ######################### ## Save Configuration settings No Prompt ## Function Save-ProUConfigNoPrompt{ Invoke-WebRequest https://"$servername":8000/api/configuration -ContentType "application/json" -Method Post -WebSession $session -Body($Currentconfig | ConvertTo-Json -Depth 10) } ########################## ## deploy Configuration settings ## Function Update-ProUConfig([string]$name) { $PUGC = ((Invoke-WebRequest https://"$servername":8000/api/configuration -WebSession $session).Content) | ConvertFrom-Json [string]$configID=$PUGC.Tag.Rows | Where-Object {$_.name -Match $name} | ForEach-Object {$_.id} $URL="https://'$servername':8000/api/configuration/'$configId'/script?encoding=ascii&deploy=true" $URL=$URL -replace "'", "" Invoke-WebRequest "$URL" -WebSession $session } ########################## ## Get FlexApps ## function get-ProUFlexapps { $PUFA = ((Invoke-WebRequest https://"$servername":8000/api/flexapppackage -WebSession $session).Content) | ConvertFrom-Json $PUFA.TAG.ROWS } ######################### ## Build Configuration Flexapp Array ## function New-FlexappConfigInventory{ #load-prouconfig $configname $inventory = $CurrentConfig.FlexAppDias.FlexAppPackages.FlexAppPackage #if inventory Null foreach ($package in $packages){ $PackName = $package.name $InventoryItems = ($inventory | Where-Object {$_.name -eq "$PackName"}) foreach ($item in $InventoryItems){ #[version]$FAAppVerI = ($item).Name.Split('-')[1] [version]$FAAppVerI = [string]$item.VersionMajor+"."+[string]$item.VersionMinor+"."+[string]$item.VersionBuild+"."+[string]$item.VersionRevision $inventoryT=[pscustomobject]@{ Name = $packName AppVersion = $FAAppVerI } [array]$global:InventoryC += $inventoryT } } } ######################### ## Build Inventory Flexapp Array ## function New-FlexappInventory{ $inventory = get-Prouflexapps foreach ($package in $packages){ $PackName = $package.name $InventoryItems = ($inventory | Where-Object {$_.name -eq "$PackName"}) foreach ($item in $InventoryItems){ [version]$FAAppVerI = [string]$item.VersionMajor+"."+[string]$item.VersionMinor+"."+[string]$item.VersionBuild+"."+[string]$item.VersionRevision $inventoryT=[pscustomobject]@{ Name = $packName AppVersion = $FAAppVerI AppID = $item.id } [array]$global:InventoryV += $inventoryT } } } ######################### # Main Update Section # function Update-ConfigFlexapps ([string]$jobfile, [string]$configname, [string]$servername){ #Connect to ProfileUnity server connect-ProfileUnityServer #Load Job CSV $packages = Get-Content $jobfile | ConvertFrom-Csv ## Edit Configuration and Test ## edit-proUconfig $configname Write-host "Testing ProfileUnity Configuration Name" ## Load Configuration and Test Existance ## if (!$CurrentConfig) { Write-host "$config doesn't exists please select new name" break } Else { {continue} } ## Update to current Flexapp Build ## ## Building Inventories ## New-FlexappInventory New-FlexappConfigInventory ForEach($package in $packages){ ## Make New PackageFile $Packname = $package.name $FilterName = $package.filtername ## Check if AppName Null ## if (!($inventoryC | Where-Object {$_.name -eq "$Packname"})){ Write-host "Package $Packname does not exist in configuration" $FAAppVerC = $Null {continue} } Else { Write-Host "Getting Configuration Package Version" ## Getting Configuration App object ## $FAAppVerC = (($inventoryC | Where-Object {$_.name -eq "$Packname"}).AppVersion | Measure-Object -Maximum).Maximum {continue} } ## Get Main Inventory object latest Version ## $FAAppVerI = (($inventoryV | Where-Object {$_.name -eq "$Packname"}).AppVersion | Measure-Object -Maximum).Maximum ## Version Check ## if ($FAAppVerC -ge $FAAppVerI) { #add Null check on inventory# Write-host ""$Package.name""$AppVer" is same or newer" -ForegroundColor Yellow -BackgroundColor red {continue} } Elseif (($CurrentConfig.FlexAppDias | Where-Object {$_.FlexAppPackages.FlexAppPackage.Name -eq "$packName"}) -eq $null) { #$IAppName = "$Packname" #[string]$updateFA = (((get-prouflexapps | Where-Object {$_.name -eq $Iappname}).name).AppVersion | Measure-Object -Maximum).Maximum Add-proUFlexAppDia -DIAname $Packname -FilterName "$filtername" Write-Host "$updateFA Added" {continue} } Else{ ## Add New not Replace ## Write-host "Replacing "$package.name""$FAAppVerI" in "$configname"" -ForegroundColor black -BackgroundColor green $CurrentConfig.FlexAppDias = $CurrentConfig.FlexAppDias | Where-Object {$_.FlexAppPackages.FlexAppPackage.Name -notmatch "$packName"} ## ## ## Add New Flexapp ## #$IAppName = "$Packname" #[string]$updateFA = ((get-prouflexapps | Where-Object {$_.name -eq $Iappname}).name) Add-proUFlexAppDia -DIAname $Packname -FilterName "$filtername" Write-Host "$Packname Updated" {continue} } } Write-host "Saving configuration $configname" Save-ProUConfigNoPrompt } ######################### #update-ConfigFlexapps -jobfile "C:\Users\administrator\Desktop\Automation\catalog.csv" -configname "Buildv2 - PD" -servername "pro2020"