Reputation: 411
I wondering if this is possible, I tried to use "split-Path" wrongly and my filename dissappears. Thanks in advance.
Actual Output:
\\myHostname\c$\users\myUser\desktop -- 9,05 MB
Ficheros Megas
-------- -----
\\myHostname\c$\users\myUser\Desktop\something.exe 5,00
\\myHostname\c$\users\myUser\Desktop\photo.jpg 2,00
desired output:
Ficheros Megas
-------- ------
\Desktop\something.exe 5,00
\Desktop\photo.jpg 2,00
CODE:
param([string]$pc,[string]$user)
$w7="\\$pc\c$\users\$user\desktop"
if(Test-Path $w7){
#Desktop:
$colItems = (Get-ChildItem $w7 | Measure-Object -ErrorAction "SilentlyContinue" -property length -sum)
$msg = "$w7 -- " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB"
Write-host -ForegroundColor Green "$msg"
#Files:
Get-ChildItem -Recurse -force -Include *.* -exclude *.ini, *.lnk $w7 -ErrorAction "SilentlyContinue" | ls | Select-Object @{Name="Ficheros";Expression={$_.FullName}}, @{Name="Megas";Expression={$_.Length / 1MB}}
}
else{
Write-Host -BackgroundColor White -ForegroundColor Red "FAIL"
}
Upvotes: 0
Views: 872
Reputation: 6615
Can you try this?
Name="Ficheros";Expression={$_.FullName -replace '.*?(\\Desktop.*)','$1'}
EDIT: Updating for non-greedy regex as suggested by @TheMadTechnician
Upvotes: 1