I have a single folder filled with PDF's, all their filenames contain a Pxxx-xx number.
Examples:
"P418-04 hingeblock.pdf"
"P293-21 corner profile.pdf"
"P810-18 bench support.pdf
"R5511-01 coat hook.pdf"
I want to create a folder structure based on these numbers and place every file inside its own folder.
I figured out how to create the folders using a sample folder structure when I have the matches:
$ItemNames | ForEach-Object{
Get-ChildItem -Path ("$TargetPath\000 Sample Folder") | Copy-Item -Destination ("$TargetPath\$_") -Recurse -Container
I get as far as selecting the files:
Get-Item -Path ("$SourcePath") | ls | where Name -match '[PR]\d?\d\d\d-?\d?\d?'
Only, how do i make it list ONLY the matching part of the filename instead of the entire filepath?
"Get-Item" always show s a list with columns "mode", "lastwritetime" and "name" and outputs the full filelocation.
I only want a simple list of:
P418-04
P293-21
P810-18
R5511-01
So I can use that list to create the folder names.