Powershell +配置文件

发布于 2024-12-10 12:05:54 字数 1208 浏览 0 评论 0原文

[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:

有人愿意帮忙吗?

感谢和问候 加甘

[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
      }
}

The above is the powershell code that I am using to read all the child items from a directory. This directory is configured in the config file.

But I keep getting this error

     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:

Somebody care to help please ?

Thanks and Regards
gagan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪之魂 2024-12-17 12:05:54

$items = Get-ChildItem -Path @sourceFolder

我认为您的意思是:

$items = Get-ChildItem -Path $sourceFolder

$ 前缀变量名,当您使用哈希表“splat”多个参数时使用 @ (这在那个位置不起作用,因为 -Path 需要一个参数)。

$items = Get-ChildItem -Path @sourceFolder

I think you mean:

$items = Get-ChildItem -Path $sourceFolder

$ prefixes variable names, use @ when you are using a hash-table to "splat" multiple arguments (which wouldn't work in that position because -Path requires an argument).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文