Last active
March 30, 2016 19:41
-
-
Save gangstanthony/9a49ec92eb05e772d321ba7ac976b303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://community.spiceworks.com/topic/1529112-path-too-long-error | |
# This script requires the Get-Files function below | |
# https://github.com/gangstanthony/PowerShell/blob/master/Get-Files.ps1 | |
$files = Get-Files \\Fileserver\E$ -Recurse -NameOnly | |
# get available drives in case dealing with long file names | |
# we can map a drive to a long file path so it is short enough for powershell to handle | |
$drives = [io.driveinfo]::getdrives() | % {$_.name[0]} | |
$alpha = [char[]](65..90) | |
$avail = diff $drives $alpha | select -ExpandProperty inputobject | |
$drive = $avail[0] + ':' | |
$result = foreach ($file in $files) { | |
# if filename is longer than 240 characters, | |
# map a drive to the current path to shorten the filename | |
$null = subst $drive /d | |
$path, $newfile = '' | |
if ($file.length -gt 240) { | |
$path = Split-Path $file | |
subst $drive $path | |
$newfile = Join-Path $drive $(Split-Path $file -Leaf) | |
} | |
$acl = if ($newfile) { | |
$newfile | Get-Acl | |
} else { | |
$file | Get-Acl | |
} | |
[pscustomobject]@{ | |
File = $file | |
ACL = $acl | |
} | |
# un-map the drive (whether we mapped it or not, just to be sure) | |
$null = subst $drive /d | |
} | |
$result | ? {$_.acl.group -match 'domain\\ad-security-group'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment