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

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

Gagan
  • 5,416
  • 13
  • 58
  • 86
  • Which line gives you the error? – EBGreen Oct 17 '11 at 14:37
  • where you get this error? post complete error – CB. Oct 17 '11 at 14:38
  • I have updated the error that I am getting..thanks – Gagan Oct 17 '11 at 14:45
  • 1
    So you assign a single value to $sourceFolder ($sourceFolder = ($configSettings.folder.sourcefolder)) the you address it as if it is an array $items = Get-ChildItem -Path @sourceFolder. What happens if you use $sourceFolder? – EBGreen Oct 17 '11 at 14:47
  • Stupid me ... Thanks EBGreen.. How do I Mark your post as an answer , please suggest :) – Gagan Oct 17 '11 at 14:51
  • @EBGreen Array variables use a `$` (PowerShell is not Perl). `@` in a parameter list serves a different purpose. – Richard Oct 17 '11 at 14:57
  • You can't make a comment as an answer: ask @EBGreen to re-write it as an answer and then accept that. – Richard Oct 17 '11 at 14:57
  • Yup, temporary perl slip there. I'm not worried about the rep and I was not positive that this was the answer since I didn't have a chance to test/replicate it. – EBGreen Oct 17 '11 at 15:16

1 Answers1

1

$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).

Richard
  • 106,783
  • 21
  • 203
  • 265