Hello guys , i have a problem with my script getting acl. this script works fine but when i have a deeper folder with lot of files it doesn't work my application bug . but when i have a direct access to the folder getting the acl , i dont have problem with get-acl. but this application and the different parts of my code has been given by different persons :( i m a newbie :)
i think the problem come from the choise of the depth and the script is looking for checking all files , do you have a solution to solve the problem ?
# Create the Com object with New-Object -com
$net = $(New-Object -comobject WScript.Network)
do
{
$ok = $false
$UNC = read-host "Veuillez entrer le nom de votre partage HO"
$ErrorActionPreference = "silentlyContinue"
net use $UNC /delete 2>$null
try {
$net.mapnetworkdrive("$Drive","$Unc",$false, "ho\fr497199", "Devoteam.2018")
$ok = $true
}
catch [System.Management.Automation.MethodInvocationException]{
Write-Host "Vous vous êtes tromper de partage!" -ForegroundColor Red
}
}
until ($ok)
}
Write-Host "`n`nVoici les niveaux en dessous de votre partage" -ForegroundColor Yellow
Function Get-ChildItemToDepth {
Param(
[String]$Path = $UNC,
[String]$Filter = "*",
[Byte]$ToDepth = $Level
)
$CurrentDepth++
Get-ChildItem $Path -Filter $Filter -Exclude "*.*" | %{
Write-Host $_.FullName
If ($_.PsIsContainer) {
If ($CurrentDepth -le $ToDepth) {
# Callback to this function
Get-ChildItemToDepth -Path $_.FullName -Filter $Filter `
-ToDepth $ToDepth -CurrentDepth $CurrentDepth
}
}
}
}
Get-ChildItemToDepth -Path $UNC
write-host "`n`nVoici les droits d'accès pour ce partage HO $UNC" -ForegroundColor Yellow
get-acl -path $UNC | Format-List -property AccessToString
$net.RemoveNetworkDrive($Drive,1)
}