Powershell script to bulk-add App-V packages – standalone

If you are testing multiple App-V packages and want to save a ton of time adding and publishing manually each package via elevated powershell, do the following:

Create a folder on the root of C: named Packages.

On the desktop create the following ps1 script:

# Get the ID and security principal of the current user account

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()

$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role

$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if we are currently running “as Administrator”

if ($myWindowsPrincipal.IsInRole($adminRole))

{

# We are running “as Administrator” – so change the title and background color to indicate this

$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + “(Elevated)”

$Host.UI.RawUI.BackgroundColor = “DarkBlue”

clear-host

}

else

{

# We are not running “as Administrator” – so relaunch as administrator

# Create a new process object that starts PowerShell

$newProcess = new-object System.Diagnostics.ProcessStartInfo “PowerShell”;

# Specify the current script path and name as a parameter

$newProcess.Arguments = $myInvocation.MyCommand.Definition;

# Indicate that the process should be elevated

$newProcess.Verb = “runas”;

# Start the new process

[System.Diagnostics.Process]::Start($newProcess);

# Exit from the current, unelevated, process

exit

}

# Run your code that needs to be elevated here

Write-Host -NoNewLine “Press any key to continue…”

$null = $Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)

Set-ExecutionPolicy RemoteSigned

Import-Module AppvClient

Enable-AppV

Get-ChildItem “C:\Packages” -recurse -force -include *.appv | Add-AppvClientPackage | Publish-AppvClientPackage -global | Mount-AppvClientPackage

The first section of the script allows you to right click the .ps1 script and choose “Run with Powershell” without having to run the script in an elevated cmd window.

All you need to do is copy and paste the App-V packages you want to test to the C:\Packages folder and run the script as above. All packages will be added and published as global for all users.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.