title: Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'
body: <p>I am getting <code>Get-ChildItem : *A parameter cannot be found that matches parameter name 'Directory'*</code> error message , below is the script used, kindly help me in finding the issue?</p>
  
  <p><strong>Script:</strong></p>
  
  <pre><code>Function Clear-ReadOnlyFiles([string]$path)
  {
    "Clearing readonly attribute from files in $path"
   New-Variable -Name read_only -Value 1 -Option readonly
   Get-ChildItem -Path $path |
   Where-Object { $_.attributes -match 'readonly' } |
   ForEach-Object {
     $_.attributes = $_.attributes -Bxor $read_only }
  }#end Clear-ReadonlyFiles
  
  
  $ZipCmd     = "{0}\7za.exe" -f $BackupDir
  $ZipCmdArgs     = "-sdel"
  
  # Grab Directories in Location
  $Directories = Get-ChildItem -Path $BackupDir -Directory
  
  # Cycle Through and Launch 7za to Compress
  # Check if Archive Exists - If yes, delete source folder
  ForEach ($Directory in $Directories)
  {
      $Source  = "{0}\{1}" -f $BackupDir,$Directory.Name
      $Archive = "{0}.7z" -f $Source
  
      # Clear Read-Only Attribute on Folder
      $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly
      ForEach ($SubFile in $SubFiles) {
          $SubFile.IsReadOnly = $False
      }
  
      #If ($Directory.IsReadOnly -eq $True) { $Directory.set_IsReadOnly($False) }
  
      $AllArgs = @('a', $ZipCmdArgs, $Archive, $Source);
  
      &amp; $ZipCmd $AllArgs
  }
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <pre><code>Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
  At C:\Play\BackupCompress.ps1:35 char:57
  + $Directories = Get-ChildItem -Path $BackupDir -Directory &lt;&lt;&lt;&lt; 
      + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
      + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  
  Get-ChildItem : A parameter cannot be found that matches parameter name 'ReadOnly'.
  At C:\Play\BackupCompress.ps1:45 char:66
  +     $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly &lt;&lt;&lt;&lt; 
      + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
      + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  
  Property 'IsReadOnly' cannot be found on this object; make sure it exists and is settable.
  At C:\Play\BackupCompress.ps1:47 char:18
  +         $SubFile. &lt;&lt;&lt;&lt; IsReadOnly = $False
      + CategoryInfo          : InvalidOperation: (IsReadOnly:String) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound
  </code></pre>