Hi, I'm a powershell newbie,
I'm trying to load data into OneDrive and need to shorten the filenames and paths of a large set of files (64,000 items). I have developed a number (about 40) abbreviation replacement code snipets similar to the below:
if ($newFileName.Contains("Partnership")) { Write-Host $type $item.FullName contains: Partnership -ForegroundColor red }
while ($newFileName.Contains("Partnership")) { $newFileName = $newFileName.Replace("Partnership", "Ptnrshp") }
if ($newFileName.Contains("partnership")) { Write-Host $type $item.FullName contains: partnership -ForegroundColor red }
while ($newFileName.Contains("partnership")) { $newFileName = $newFileName.Replace("partnership", "Ptnrshp") }
if ($newFileName.Contains("PARTNERSHIP")) { Write-Host $type $item.FullName contains: PARTNERSHIP -ForegroundColor red }
while ($newFileName.Contains("PARTNERSHIP")) { $newFileName = $newFileName.Replace("PARTNERSHIP", "Ptnrshp") }
Where you can see I'm trying to replace strings of various case with a standard form of an abbreviation. I fear however that this is an inefficient approach, can anyone suggest a more concise way of writing this code, that might be more efficient? I have to run the same code several times in order to catch all the replacements and it's taking forever.
Regards,
Mark Fincham