I am trying to add two different source paths under one object but I am not able to do that, could anyone help, please.
就像我有两个源路径,我想把这两个路径组合在一个对象下,这样我就可以运行我的代码并用子项检查条件
$RetailSource = 'Retail P&C Sales Intelligence*'
$GroupSource = 'Group P&C Sales Intelligence*'
$sourcepath = Join-path -path 'c:uploadtool' -childpath $RetailSource,$GroupSource
Get-ChildItem的-Path
参数可以采用一系列路径进行迭代,因此可以执行以下操作:
# create an array of paths and store it in variable $sourcepath
$RetailSource = 'Retail P&C Sales Intelligence'
$GroupSource = 'Group P&C Sales Intelligence'
$sourcepath = (Join-Path -Path 'c:uploadtool' -ChildPath $RetailSource),
(Join-Path -Path 'c:uploadtool' -ChildPath $GroupSource)
Get-ChildItem -Path $sourcepath { ... }
或
$RetailSource = Join-Path -Path 'c:uploadtool' -ChildPath 'Retail P&C Sales Intelligence'
$GroupSource = Join-Path -Path 'c:uploadtool' -ChildPath 'Group P&C Sales Intelligence'
Get-ChildItem -Path $RetailSource, $GroupSource { ... }
您的代码使它看起来像是要将3个部分组合成一个完整的路径,实际上您需要将两个完全组合的路径连接为字符串数组。参见Get-ChildItem
上的Path参数