CSV remove full folder path and leave just the folder name and size information

I have CSV file that has some information like below.

How can I remove the full path and have just the folder name and folder size information and output results back to csv file. I am new to PS and would appreciate any help on how to accomplish this.

FolderName Size(GB) Size(TB)


vms:\192.168.0.1.@222\Some-Datacenter\Volume-00\file-path\Folder1 111 GB 0.11 TB
vms:\192.168.0.1.@222\Some-Datacenter\Volume-00\file-path\Folder2 121 GB 0.12 TB
vms:\192.168.0.1.@222\Some-Datacenter\Volume-00\file-path\Folder3 131 GB 0.13 TB
vms:\192.168.0.1.@222\Some-Datacenter\Volume-00\file-path\Folder4 141 GB 0.14 TB
vms:\192.168.0.1.@222\Some-Datacenter\Volume-00\file-path\Folder5 151 GB 0.15 TB

Desired Output Example:

FolderName Size(GB) Size(TB)


Folder1 111 GB 0.11 TB
Folder2 121 GB 0.12 TB
Folder3 131 GB 0.13 TB
Folder4 141 GB 0.14 TB
Folder5 151 GB 0.15 TB

Not very elegant…

$Results = @()
Get-Content "C:\temp\56.txt" | select-object -skip 2 | % {
$item=$_-replace'(^\s+|\s+$)',''-replace'\s+',''
$Results+=[PSCustomObject]@{
Folder=(Split-Path$item.Split("")[0]-Leaf).Trim()
SizeGB=$item.Split("")[1]+""+$item.Split("")[2]
SizeTB=$item.Split("")[3]+""+$item.Split("")[4]
}
}
# results $Results
 
Folder SizeGB SizeTB ------ ------ ------ Folder1 111 GB 0.11 TB Folder2 121 GB 0.12 TB Folder3 131 GB 0.13 TB Folder4 141 GB 0.14 TB Folder5 151 GB 0.15 TB

 

 

I would use Split-Path:

$csv = Import-Csv E:\temp\example.csv

foreach ($row in $csv) {

    $row.FolderName = $row.FolderName | Split-Path -Leaf
    $row | Export-Csv e:\temp\new_example.csv -Append -NoClobber -NoTypeInformation

}
Thank you so much Matt. That script worked brilliantly. I was looking into -replace comparison operator and did not read up on Split-Path -Leaf

Thank you so much Matt. That script worked brilliantly. I was looking into -replace comparison operator and did not read up on Split-Path -Leaf