Hey,
We have 1000’s of MSI’s assigned through group policy and often need to work with the file paths in PowerShell, here’s a function that returns the file path of the MSI from the Software Installation GPO.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Function Get-MSIPath { [CmdletBinding()] Param ( [Parameter(Mandatory=$True,position=0)] $Policy, [Parameter(Mandatory=$False)] $Domain = (Get-ADDomainController).Name ) $DC = Get-ADDomainController -DomainName $Domain -Discover $DN = (Get-ADDomain -Server $DC).DistinguishedName $GP = Get-GPO -Name $Policy -Domain $Domain -Server $DC $ADobj = Get-ADObject -filter "Name -ne 'Packages'" -Server $DC -SearchBase "CN=Packages,CN=Class Store,CN=Machine,CN={$($GP.ID.Guid)},CN=Policies,CN=System,$DN" -ErrorAction Stop -SearchScope Subtree -Properties msiFileList,displayName Return $ADobj.MSIFileList } |
This function will return the MSI path and MST path. It will also return paths of MSI’s that have been deleted from the policy in the past. In my case I don’t want this to happen so if you know a way of filtering out these ‘ghost’ paths, let us know! Also if you want to speed it up you can hard code your domain/domain controller names to avoid discovery.
The function is called like so:
1 |
Get-MSIPath -Policy "Software Policy" -Domain mydomain.internal |