[xml]$configSettings = get-content .ScriptSigner.config
Write-Host([string]::Format("XML Settings : {0}",$configSettings.InnerXml))
$sourceFolder = ($configSettings.folder.sourcefolder)
$destinationFolder = ($configSettings.folder.destinationFolder)
Write-Host ("Source Folder = $sourceFolder");
Write-Host ("Destination Folder = $destinationFolder");
$items = Get-ChildItem -Path @sourceFolder
# enumerate the items array
foreach ($item in $items)
{
# if the item is a directory, then process it.
if ($item.Attributes -eq "Directory")
{
Write-Host $item.Name
}
}
上面是我用来从目录中读取所有子项的powershell代码。该目录是在配置文件中配置的。
但是我一直得到这个错误
ERROR: Get-ChildItem : A positional parameter cannot be found that accepts argument ''.
ERROR: At F:GaganpowershellScriptSigner.ps1:37 char:23
ERROR: + $items = Get-ChildItem <<<< -Path @sourceFolder
ERROR: + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
ERROR: + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
ERROR:
有人愿意帮忙吗?
谢谢选手gagan
$items = Get-ChildItem -Path @sourceFolder
我想你是说:
$items = Get-ChildItem -Path $sourceFolder
$
前缀变量名,当您使用哈希表来"splat"多个参数时使用@
(这在该位置不起作用,因为-Path
需要参数)。