通过powershell从xml文件中获取信息,试图卸载应用程序



我在解析xml文件时遇到问题

<DisplayName>Remote_Take_Over_S1_0002</DisplayName>

我正试图从"C:ProgramDataApp-V1BBEDDA5-595E-4CF7-834A-B282C4981469C71FE9F-F1C0-47F9-9518-E94898B6424FAppxManifest.xml"获得上述信息

我知道如何或从哪里开始,但我已经走了这么远。

$ComputerName = $txb_hostname.Text
$RemoteParentPath = Join-Path -Path "\$ComputerName" -ChildPath 'c$ProgramDataApp-V'
$RemoteManifestPaths = Get-ChildItem -Path $RemoteParentPath -Recurse -Filter 'AppxManifest.xml' | Select-Object -ExpandProperty FullName
foreach ($manifestFile in $RemoteManifestPaths)
{
$xml = [xml](Get-Content -Path $manifestFile -Raw)
$xml.SelectSingleNode('//*[local-name()="DisplayName"]/text()').Value 
LogWrite $xml
} 

有什么想法吗?

现在出现错误不能对空值表达式调用方法。行:6字符:5

Get-Content:找不到路径"H:\AppxManifest.xml",因为它不存在。行:5字符:18

设法对以上错误进行排序

我假设您希望在远程计算机(或者在本例中,使用文件UNC路径的当前计算机(上的c:ProgramDataApp-V路径下找到所有AppxManifest.xml文件,然后以某种方式操作该XML文件;也许是为了获取DisplayName值?

如果是这样的话,试试这样的东西:

[string]$ComputerName = $env:COMPUTERNAME
[string]$RemoteParentPath = Join-Path -Path "\$ComputerName" -ChildPath 'c$ProgramDataApp-V'
[string[]]$RemoteManifestPaths = Get-ChildItem -Path $RemoteParentPath -Recurse -Filter 'AppxManifest.xml' | Select-Object -ExpandProperty FullName
foreach ($manifestFile in $RemoteManifestPaths) {
$xml = [xml](Get-Content -Path $manifestFile -Raw)
$xml.SelectSingleNode('//DisplayName/text()').Value
}  

我把它分解成多行,以便更容易理解正在发生的事情/尝试每一件作品。注意:我还没有测试代码本身。

最新更新