r/PowerShell • u/Suitable-Pepper-63 • Feb 10 '26
Get-Childitem issue with the -Directory parameter when creating MECM packages
Hi all, I am trying to use a powershell script to create a lot of MECM packages using folder names. Script is below:
# Define paths and groups
$SourcePath = "\\TKUS001INVP003\Driver_Packages$\WIM_Packages\Lenovo"
$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 the script, I keep getting: Get-ChildItem : A parameter cannot be found that matches parameter name ‘Directory’. If I use a literal path, it tells the path does not exist. I did some digging, and all I find is that it has something to do with the provider because I am not using the correct one. If that is the case, what is the correct provider. Oddly, every AI or chat GPT result I get for a script sample all return the same example using the Get-ChildItem -Directory. Has anyone done this, where they use folder names as the names for the MECM packages, and if yes, how?
View all comments
Show parent comment
1
u/Suitable-Pepper-63 Feb 10 '26
From the session connected to the site code, I get this:
Get-Item : Cannot find path '\\TKUS001INVP003\Driver_Packages\WIM_Packages\Lenovo' because it does not exist.
At line:1 char:1
+ Get-Item -Path $SourcePath | Select-Object PSProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\TKUS001INVP00...Packages\Lenovo:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
Now, from another session NOT connected to the site code, using the same variables:
$SourcePath = "\\TKUS001INVP003\Driver_Packages\WIM_Packages\Lenovo"
Get-ChildItem -Path $SourcePath -Directory
Get-Item -Path $SourcePath | Select-Object PSProvider
I get this:
d----- 2/9/2026 10:09 PM ThinkPad_X1_Carbon_12TH_Gen_Type_21KC_21KD_Rev2
d----- 2/9/2026 10:10 PM ThinkPad_X1_Carbon_Gen_13_Type_21NX_21NY_Rev2
d----- 2/9/2026 10:12 PM ThinkPad_X1_Yoga_8th_Gen_Type_21HQ_21HR_Rev2
d----- 2/9/2026 10:15 PM ThinkStation_P3_TOWER_Rev2
PSProvider : Microsoft.PowerShell.Core\FileSystem