A script to allow easy testing of your App-V package on any OS
Time and patience are required when creating App-V packages and testing them on various operating systems. You should always target your packages for the right operating system (OS), but testing shows that a package made for one Windows OS may run on another Windows version. This PowerShell script modifies .OSD files for you so that you can test your packages against any OS, such as Windows 8!
This script makes testing easier by modifying your .OSD files for you. It performs the following:
1. Removes any OS values in your .OSD files for you, circumventing human error.
2. It makes a backup of your original .OSD files in a local folder named OSDBACK
3. Writes out a flag file so that this script cannot be run on the same directory more than once. This protects all the backed up .OSD files.
The script works by removing all OS entries such as '<OS VALUE="Win764"/>' leaving the 'OS Value' parameter empty. This allows you to attempt to run a package on any OS. This does NOT mean that your applications will now run without issue on any OS, just that App-V will now let them allow you to test.
All original .OSD files are backed up for your later use.
Values intact prior to script run:
Values removed by script:
How to Use
Open an elevated PowerShell prompt. Type 'powershell' at the Start menu then right click the one named simple 'PowerShell' and choose 'Run as Administrator.' Change to the directory where you have save the script and kick it off with '.\APP-V_OSRemoval.PS1'. If you get an error about scripts being blocked you will need to lower permissions a bit. See these articles if you need help.
When the script runs correctly it will ask for the folder that is the root of all of your App-V files… usually X:\Content. The script will take it from there.
Using the Set-ExecutionPolicy Cmdlet: https://technet.microsoft.com/en-us/library/ee176961.aspx
Software Restriction Policies and PowerShell Code Signing: https://blogs.technet.com/b/industry_insiders/archive/2007/08/17/software-restriction-policies-and-powershell-code-signing.aspx
The script text is below but you can also download the TXT version using the link at the bottom of this article that’s named APP-V_OSRemoval ps1.txt.
=====
cls
Write-Host APP-V_OSRemoval will backup OSD files to OSDBAK folders
Write-Host then will remove references to OS from each file.
Write-Host
$CurrentDir=Read-Host "Enter the root directory for all OSD files"
$OSD = $CurrentDir + '\*.OSD'
$BAK = $CurrentDir + '\OSDBAK'
$FLAG = $CurrentDir + '\OSDFlag.txt'
#Flag this directory to preserve backups
If ((test-path -Path $FLAG) -ne $true)
{
Get-Date | New-Item -Path $FLAG -type "file"
} Else {
Write-Host
Write-Host OSDParser has already been run once. Running again
Write-Host will overwrite OSD backup files.
Break
}
# Make Backup of OSD's
$DIR = get-childitem $CurrentDir -include *.osd -recurse -Force
foreach ($file in $DIR)
{
$FileNow = $file.PSParentPath + '\OSDBAK'
If ((Test-Path -path $FileNow) -ne $True)
{
New-Item ($FileNow) -type directory
}
Copy-Item $file.PSPath $FileNow
# Remove references to OS
(Get-Content $file) -notmatch '<OS VALUE' | Set-Content -path $file
}
# Finished
Write-Host
Write-Host Finished. All OSD files in all
Write-Host subdirectories parsed.
=====
<
>
NOTE Use of the script contained herein is on an as-is basis only. Microsoft makes no representations or warranties about the suitability or accuracy of the information contained in this post for any purpose. As with any change, it is your responsibility to ensure accurate and recoverable backups exists prior to implementing the script above.
Jonathan Jordan | Senior Support Escalation Engineer
Steve Bucci | Senior Support Escalation Engineer
Get the latest System Center news on Facebook and Twitter :
App-V Team blog: https://blogs.technet.com/appv/
ConfigMgr Support Team blog: https://blogs.technet.com/configurationmgr/
DPM Team blog: https://blogs.technet.com/dpm/
MED-V Team blog: https://blogs.technet.com/medv/
Orchestrator Support Team blog: https://blogs.technet.com/b/orchestrator/
Operations Manager Team blog: https://blogs.technet.com/momteam/
SCVMM Team blog: https://blogs.technet.com/scvmm
Server App-V Team blog: https://blogs.technet.com/b/serverappv
Service Manager Team blog: https://blogs.technet.com/b/servicemanager
System Center Essentials Team blog: https://blogs.technet.com/b/systemcenteressentials
WSUS Support Team blog: https://blogs.technet.com/sus/
The Forefront Server Protection blog: https://blogs.technet.com/b/fss/
The Forefront Endpoint Security blog : https://blogs.technet.com/b/clientsecurity/
The Forefront Identity Manager blog : https://blogs.msdn.com/b/ms-identity-support/
The Forefront TMG blog: https://blogs.technet.com/b/isablog/
The Forefront UAG blog: https://blogs.technet.com/b/edgeaccessblog/
Comments
Anonymous
January 01, 2003
Here is a little more refined PowerShell script with the directory variable parameterized and tested for existence. Also, inline comments were turned into Write-Verbose so that they can be shown inline when the script is run by adding the -Verbose option. It can be run as follows: .APP-V_OSRemoval.ps1 C:OSDdirectory -Verbose Param( [Parameter(Mandatory=$true)] [ValidateScript({Test-Path $_ -PathType 'Container'})] $Directory ) $Flag = Join-Path $Directory 'OSDFlag.txt' Write-Verbose "Flagging $Directory as processed" If (!(Test-Path $Flag)) { Get-Date | New-Item -Path $Flag -type "file" } Else { Write-Warning "OSDParser has already been run once. Running again will overwrite OSD backup files. " Break } Write-Verbose "Scanning root directory for all OSD Files" $OSDFiles = Get-ChildItem $Directory -include *.osd -recurse -Force foreach ($File in $OSDFiles) { Write-Verbose "Processing $File.FullName" $FileNow = Join-Path $File.PSParentPath 'OSDBAK' If (!(Test-Path -path $FileNow)) { New-Item $FileNow -type Directory } Copy-Item $File.PSPath $FileNow (Get-Content $File) -notmatch '<OS VALUE' | Set-Content -path $File }Anonymous
January 01, 2003
Very nice blog. I need to sharpen my Powershell skills I think! Thanks for sharingAnonymous
April 03, 2012
Very nice blog. I need to sharpen my Powershell skills I think! Thanks for sharingAnonymous
March 18, 2014
Hi
I am looking for a powershell command or any way which can help me in extracting the packages version and application group names in App-v. the requirement is to know the version of the package.