Link to home
Avatar of bibi92
bibi92Flag for France

asked on

format log file

Hello,
When I executed the following script
Get-ChildItem -Path e:\test -Include $PrefixList -Recurse |
	Group-Object -Property DirectoryName |
	ForEach-Object {
		$Directory = $_.Group
		$PrefixList | ForEach-Object {
			$Prefix = $_
			$Directory | Where-Object {$_.Name -like $Prefix} | Sort-Object -Property Name | Select-Object -First 1 | ForEach-Object {
				$NewName = $_.BaseName.SubString(1) -replace '_\d{8}_\d{6}\Z'
				Rename-Item -Path $_.FullName -NewName $NewName 
				$_ | Select-Object 'DirectoryName', 'Name', @{n='NewName'; e={$NewName}} | out-file e:\log.txt -ErrorVariable ERR1 -encoding "default" -append
			}
		}
	} 

Open in new window


The content of the log is :
DirectoryName                           Name                                    NewName                                
-------------                           ----                                    -------                                
E:\Files\CAMER                          ZCAMER_20170214_032034.txt              CAMER                              



DirectoryName                           Name                                    NewName                                
-------------                           ----                                    -------                                
E:\Files\TOGO                           ZTOGO_20170216_124903.txt               TOGO      

How can I generate :

DirectoryName                           Name                                    NewName                                
-------------                           ----                                    -------                                
E:\Files\CAMER                          ZCAMER_20170214_032034.txt              CAMER                              
                             
E:\Files\TOGO                           ZTOGO_20170216_124903.txt               TOGO    

Thanks

Regards
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of bibi92

ASKER

Thanks regards