Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING Not able to use Powershell to create Packages based on folder names

abnrangerx67

New Member
Messages
2
Reaction score
0
Points
1
Hi all, I am trying to use a powershell script to create a lot of MECM packages using folder names. Script is below:

Code:
# 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?
 

Forum statistics

Threads
7,181
Messages
28,010
Members
18,315
Latest member
WillR

Trending content

Back
Top