Hey everyone! I'm working on a PowerShell script to create multiple MECM packages based on folder names, but I'm running into an issue. Here's a snippet of my script:
```powershell
# Define paths and groups
$SourcePath = "\TKUS001INVP003Driver_Packages$WIM_PackagesLenovo"
$SiteCode = "TK1"
$DPGroup = "All Software Distribution Points"
# Import Module
Import-Module "$($env:SMS_ADMIN_UI_PATH)..ConfigurationManager.psd1"
Set-Location "$($SiteCode):"
# Get folders, create packages, and distribute
Get-ChildItem -Path $SourcePath -Directory | ForEach-Object {
$Package = New-CMPackage -Name $_.Name -Path "$($SourcePath)$($_.Name)" -Description "Imported via Script"
# Distribute the content
Start-CMContentDistribution -PackageName $Package.Name -DistributionPointGroupName $DPGroup
}
```
When I run this, I keep getting an error saying: "Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'." It's strange because this syntax seems to be used everywhere. Shouldn't it work? I suspect it might be about the PowerShell version or the provider being used since I can't seem to get the correct path either. I'd love to hear if anyone has dealt with this and how you solved it!
4 Answers
Can you pull the exact error from `$Error`? I’m not seeing what you are. I tested this with both PowerShell 5.1 and 7 using a network path, and it worked just fine for me. Might give us a clue!
Have you tried changing the double quotes in your `$SourcePath` to single quotes? It seems you might have a path issue too. I tested a UNC path with a `$` in it and it worked fine for me! Also, make sure you're running outside of PowerShell ISE if you want it to behave normally.
I did copy the exact path from my file explorer, so it's correct. I think when I set the location to the site code in MECM, it causes the path resolution to fail. Running it in a normal session works fine though. Such a frustrating catch-22!
What does this return for you?
`Get-Item -Path $SourcePath | Select-Object PSProvider`
This could tell us what provider you're working with for that path.
What version of PowerShell are you using? I'm pretty sure that a network path like yours should still be handled by the FileSystem provider, so both `-Path` and `-Directory` should work. I can’t check right now, but I remember it being fine in the past. Let me know!
Thanks for the reply! I’m on PowerShell 5.1. I even tried using the PowerShell ISE from within MECM and still got that error. I’ll give PowerShell 7 a shot and see if it changes anything!

Here’s the error I'm getting:
"Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At line:19 char:33..."
Seems like the same issue persists!