Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, November 10, 2016 10:14 AM
Hi,
I'm working on an script which will update ACL.
So first I'm trying to list every files in order to change the owner (There are some issues with some owners).
My script is starting well the listing, but for some files (not all), I've got an error on an Get-Item with the known message "Cannot find path. File does not exist".
Can you help me please?
Here is my code :
import-module c:\temp\Get-FolderItem.psm1
$FolderToScan = "D:\Donnees\00 - Maintenance Thermique\1. Organisation"
$OldOwner = "Administrateurs"
$NewOwner = New-Object System.Security.Principal.NTAccount($OldOwner)
TRY
{
Get-folderItem -Path $FolderToScan | Foreach-object {
$path = $_.FullName
$test = Resolve-Path $_.FullName
$f = Get-Item -LiteralPath $_.FullName -Force
}
}
CATCH [System.IO.IOException]
{
$Log = "" | Select-Object FileName,Path
$Log.FileName = $_.Name
$Log.Path = $_.FullName
$Log | Export-Csv "c:\temp\errlog.csv" -Notype -Append
}
function Resolve-PathSafe
{
param
(
[string] $Path
)
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
}
My try catch is not working, but it's an other pb.
The function Get-FolderItem is an function from technet which use robocopy to get full path when there are longer than 255.
For example, I've got my error for this file : D:\Donnees\00 - Maintenance Thermique\1. Organisation\Procédures\Réunion d'agence 2015-4T.PPTX
Where is the error in the path ? This file is really existing (I checked).
regards
All replies (6)
Monday, November 21, 2016 8:36 AM ✅Answered
Nop, I resolved it by using Robocopy to get all path I needed.
Thursday, November 10, 2016 11:19 AM
You cannot pass a long filename to any standard CmdLet.
\(ツ)_/
Thursday, November 10, 2016 11:52 AM
So I suppose the only way is to create an PSDrive ?
Monday, November 14, 2016 8:35 AM
Hi Fred,
Please see link below:
This is a good explanation!
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Monday, November 21, 2016 8:06 AM
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Monday, November 21, 2016 8:46 AM
Thanks for sharing the solution!
Have a nice day!
Best regards,
Andy