# Get the list of files in the folder $files = Get-ChildItem -File foreach ($file in $files){ # Extract the ID from the filename, you may need to adjust this based on your actual format $id = $file.BaseName -replace '^.*ID (\d+).*$', '$1' # Set the new filename to the ID $newFileName = $id + $file.Extension # Extract the name components $nameComponents = $file.BaseName -replace 'ID \d+.*$', '' $nameComponents = $nameComponents.Trim() # Set the nameComponents into custom property $shell = New-Object -ComObject Shell.Application $folder = $shell.Namespace((Resolve-Path $file.DirectoryName)) $shellfile = $folder.ParseName($file.Name) # '21' is generally for comments but you can choose a custom property based on your requirement $folder.GetDetailsOf($shellfile, 21) = $nameComponents # Rename the file Rename-Item -Path $file.FullName -NewName $newFileName }