Get-ChildItem returns a list of File System objects, not just file names.
You can use the -Name
option to get it to return just file names.
The output type is the type of the objects that the cmdlet emits.
• System.Object - The type of object that Get-ChildItem returns is determined by the objects in the provider drive path.
• System.String - If you use the Name parameter, Get-ChildItem returns the object names as strings.
Something like this:
$orgPath = "d:\testOrg\" $delim = "-" Get-ChildItem $orgPath -Name | ` foreach { $nameArray = $_.Split($delim) $newName = $nameArray[2]+$nameArray[0]+$nameArray[1]+"_"+$nameArray[3]+$nameArray[4] Write-Output $newName }