Powershell +配置文件

时间:2011-10-17 14:34:51

标签: xml powershell configuration-files

[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:\Gagan\powershell\ScriptSigner.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

1 个答案:

答案 0 :(得分:1)

  

$ items = Get-ChildItem -Path @sourceFolder

我认为你的意思是:

$items = Get-ChildItem -Path $sourceFolder

$为变量名添加前缀,当您使用哈希表“splat”多个参数时使用@(由于-Path需要参数,因此无法在该位置工作)。