我有一个路径数组,是从一些注册表查询中检索到的。目前,仍将它们作为目录对象返回,但我需要将它们转换为仅由字符串组成的数组。在PowerShell中,最有效的方法是什么?
代码:
代码:
$found_paths = @();
$uninstall_keys = getRegistrySubkeys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" '\\Office[\d+.*]';
if ($uninstall_keys -ne $null)
{
foreach ($key in $uninstall_keys)
{
$product_name = getRegistryValue $key "DisplayName";
$version = getRegistryValue $key "DisplayVersion";
$base_install_path = getRegistryValue $key "InstallLocation";
$full_install_path = Get-ChildItem -Directory -LiteralPath $base_install_path | Where-Object Name -match '^Office\d{1,2}\D?' | Select-Object FullName;
$found_paths += ,$full_install_path
}
}
write-output $found_paths;
输出:
FullName
--------
C:\Program Files\Microsoft Office Servers\OFFICE15
C:\Program Files\Microsoft Office\Office15
期望输出:
C:\Program Files\Microsoft Office Servers\OFFICE15
C:\Program Files\Microsoft Office\Office15
;
来终止语句。 - mklement0