我尝试了以下代码:
$installedapps = Get-AppxPackage
$aumidList = @()
foreach ($app in $installedapps)
{
foreach ($id in (Get-AppxPackageManifest).package.applications.application.id)
{
#id
}
}
$aumidList
但这是应用程序ID。如何获得产品ID?
答案 0 :(得分:0)
使用以下 PowerShell 代码示例创建一个函数,该函数返回 Microsoft 应用程序信息的 [PSCustomObject],以及指定和安装的应用程序包名称的商店应用程序的产品 ID。该函数在 Microsoft Store 网站上查询每个签名的相应应用程序包。
# List all packages to get installed package names
# Get-AppxPackage -AllUsers
$packageName = 'Microsoft.MicrosoftEdge'
function FindAppXInfo(
$packageName,
$region = 'en-us',
$searchClass = 'c-hyperlink' ) {
$package = Get-AppxPackage -Name $packageName
$pFamilyName = $package.PackageFamilyName
$pManifest = $package | Get-AppxPackageManifest
$pAppId = $pManifest.Package.Applications.Application[0].Id
$aumid = '{0}!{1}' -f $pFamilyName, $pAppId
$pAppInfo = [Windows.ApplicationModel.AppInfo]::GetFromAppUserModelId($aumid)
if ($package.SignatureKind -eq [Windows.ApplicationModel.PackageSignatureKind]::Store) {
$query = 'https://www.microsoft.com/{0}/search/explore?q={1}+{2}' -f $region, $packageName, $package.PublisherId
$request = Invoke-WebRequest -Uri $query
$links = $request.Links | Where Class -eq $searchClass
$firstLink = $links[0]
$ProductId = $firstLink.href.SubString($firstLink.href.LastIndexOf('/')+1)
$storeLink = 'ms-windows-store://pdp/?ProductId={0}' -f $ProductId
}
$obj = [PSCustomObject][Ordered]@{
PackageFamilyName = $pFamilyName
FullName = $pAppInfo.Package.Id.FullName
ApplicationId = $pAppId
AppUserModelId = $aumid
ProductID = $ProductId
DirectLink = $firstLink.href
MsftStoreLink = $storeLink
DisplayName = $pAppInfo.Package.DisplayName
LogoFilePath = $pAppInfo.Package.Logo.OriginalString
PublisherDisplayName = $pAppInfo.Package.PublisherDisplayName
InstalledDate = $pAppInfo.Package.InstalledDate
InstalledPath = $pAppInfo.Package.InstalledPath
Description = $pAppInfo.DisplayInfo.Description
PackageVersion = $package.Version
PublisherId = $package.PublisherId
Publisher = $package.Publisher
}
return $obj
}
FindAppXInfo($packageName)