#################### ##bulk Pack## ##Make Json From CSV + chocolatey Version## ## 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" -server "https://pro2020:9075" <########################################################################### Update Note 4.1 cleaned up Verbs 4.2 added select -first 1 to choco version check (max version) 4.3 Speed update (no status) ###########################################################################> ## 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 } ######################### ## Get FlexApps ## function get-ProUFlexapps { $PUFA = ((Invoke-WebRequest https://"$servername":8000/api/flexapppackage -WebSession $session).Content) | ConvertFrom-Json $PUFA.TAG.ROWS } ######################### function Update-FPABatchJob ([string]$jobfile, [string]$Defaultfile, [string]$server) { connect-ProfileUnityServer $packages = Get-Content $jobfile | ConvertFrom-Csv $FA = get-ProUFlexapps ForEach($package in $packages){ ## Make New PackageFile $Packname = $package.name ## Check if AppName Null ## if (!($FA | Where-Object {$_.name -match "$Packname"})) { Write-host "Package $Packname2 does not exist" $FAAppVer = $Null {continue} } Else { Write-Host "Getting Inventory Package Version" $FAAppVer = (($FA | Where-Object {$_.name -match "$Packname"}).Version | Measure-Object -Maximum).Maximum {continue} } $AppVer = (Find-Package -Source chocolatey -Name $package.name).version | select -first 1 ## Version Check ## if ($faAppVer -ge $appver) { Write-host ""$Package.name""$FAAppVer" is same or newer" -ForegroundColor Yellow -BackgroundColor red {continue} } Else { $Newpkgfile=[pscustomobject]@{ Name = $package.Name PackageVersion = $appver SizeMB = $package.size Installer = $package.installer InstallerArgs = $package.installerargs } Write-host "Adding "$package.name""$AppVer" to queue" -ForegroundColor black -BackgroundColor green [array]$NewpkgfilePack += $Newpkgfile {continue} } } ## Check if json Null ## if (!$NewpkgfilePack) { Write-host "No new Packages to Update" Break } Else { {continue} } ConvertTo-Json @(@($NewpkgfilePack)) | out-file "$env:temp\PackageTemp.json" -Encoding ascii $arglist = "create packages /PrimaryAddress $server /packagesfile $env:temp\Packagetemp.json /DefaultsJSON $Defaultfile /WaitForDone" start-sleep -seconds 2 Start-Process -FilePath "C:\Program Files (x86)\Liquidware Labs\FlexApp Packaging Automation\primary-client.exe" -ArgumentList $arglist -wait -NoNewWindow start-sleep -seconds 10 remove-item "$env:temp\Packagetemp.json" } ############### #update-FPABatchJob -jobfile "C:\Users\administrator\Desktop\Automation\catalog.csv" -Defaultfile "C:\Users\administrator\Desktop\argfileCatalog.json" -server "https://pro2020:9075"