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!

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

Status
Not open for further replies.

abnrangerx67

New Member
Messages
4
Solutions
1
Reaction score
2
Points
3
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?
 
Solution
Hi, I was able to get it to work when I used what another person from another forum suggested, and that was to use a variable, but more importantly, make the connection to the path before connecting to the site code. I realized that whenever I was connected to the site code is when the path is not found.
Hi, I was able to get it to work when I used what another person from another forum suggested, and that was to use a variable, but more importantly, make the connection to the path before connecting to the site code. I realized that whenever I was connected to the site code is when the path is not found.
 
Solution
Status
Not open for further replies.

Forum statistics

Threads
7,194
Messages
28,075
Members
18,345
Latest member
mrdany

Trending content

Back
Top