Share via


Difference between the Name and FullName property

Question

Tuesday, July 3, 2012 10:17 AM

Hi

Why does this script work:

PS Dir_Prove:\>>> Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item $_.Name -WhatIf}
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Guida_PowerShell_2,0.txt".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\it_windows_7_ultimate_with_sp1_x86_dvd_619122.iso".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Kalimba.mp3".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Lista.txt".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\ListSortedSize.txt".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Maid with the Flaxen Hair.mp3".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Sleep Away.mp3".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Visio.Premium.2010.x64.Volume.License.SP1.iso".
WhatIf: Execution the operation "Remove File" on the destination "C:\Users\test\Documents\PowerShell\Wildlife.wmv".
PS Dir_Prove:\>>>

and this:

PS Dir_Prove:\>>> Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item $_.FullName -WhatIf}
Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Impossible to associate the argument to parameter 'Path' because it is null.
In line:1 car:110
+ Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property Name | ForEach-Object {Remove-Item <<<<  $_.FullName -WhatIf}
    + CategoryInfo          : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand

PS Dir_Prove:\>>>

does not work?

What is the difference between the Name and FullName property?

Thanks

Bye

Balubeto

All replies (5)

Tuesday, July 3, 2012 6:03 PM ✅Answered | 1 vote

See for yourself.  Fullname is the full path, and name is just the file name.  Run the following code to see the difference:

'Test' | Set-Content 'Test.txt'
$file = Get-Item '.\test.txt'
$file.Name
$file.FullName

Grant Ward, a.k.a. Bigteddy


Tuesday, July 3, 2012 6:37 PM ✅Answered | 1 vote

Also, the fullname can be either a drive letter oriented or a UNC path:

 

C:> $file = get-item '\EPSON563EAC\MEMORYCARD\xo'

C:> $file.name

xo

C:> $file.fullname

\EPSON563EAC\MEMORYCARD\xo

 

 


Tuesday, July 3, 2012 10:35 AM | 2 votes

Hi Balubeto,

The reason why it isn't working has nothing to do with the difference between Name and FullName.

The reason why it isn't working for you is because you have used Select-Object -Property Name. Once you do this, you limit the output of the object to the property selected. You can see this by running Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property FullName | Get-Member

Try:

Get-ChildItem | Where-Object {$_.Length -gt 2MB} | Select-Object -Property FullName | ForEach-Object {Remove-Item $_.FullName -WhatIf}

Phill McSherry


Tuesday, July 3, 2012 10:43 AM

It is not necessary to use the Select-Object cmdlet at all, really.

Get-ChildItem | Where-Object {$_.Length -gt 2MB} | ForEach-Object {Remove-Item $_.FullName -WhatIf}

Grant Ward, a.k.a. Bigteddy


Tuesday, July 3, 2012 5:58 PM

So:

PS Dir_Prove:\>>> Get-ChildItem | Where-Object {$_.Length -gt 2MB} | ForEach-Object {Remove-Item $_.FullName -WhatIf}
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Guida_PowerShell_2,0.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\it_windows_7_ultimate_with_sp1_x86_dvd_619122.iso".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Kalimba.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Lista.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\ListSortedSize.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Maid with the Flaxen Hair.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Sleep Away.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Visio.Premium.2010.x64.Volume.License.SP1.iso".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Wildlife.wmv".
PS Dir_Prove:\>>>
PS Dir_Prove:\>>> Get-ChildItem | Where-Object {$_.Length -gt 2MB} | ForEach-Object {Remove-Item $_.Name -WhatIf}
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Guida_PowerShell_2,0.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\it_windows_7_ultimate_with_sp1_x86_dvd_619122.iso".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Kalimba.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Lista.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\ListSortedSize.txt".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Maid with the Flaxen Hair.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Sleep Away.mp3".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Visio.Premium.2010.x64.Volume.License.SP1.iso".
WhatIf: Esecuzione dell'operazione "Rimuovi file" sulla destinazione "C:\Users\test\Documents\PowerShell\Wildlife.wmv".
PS Dir_Prove:\>>>

What is the difference between the Name and FullName property?

Thanks

Bye

Balubeto