Powershell + Config 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
}
}
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 开发者_StackOverflowpositional 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
$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).
精彩评论