Powershell +配置文件
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的意思是:
$
前缀变量名,当您使用哈希表“splat”多个参数时使用@
(这在那个位置不起作用,因为-Path
需要一个参数)。I think you mean:
$
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).