Hello all,
Can anyone help me optimizing this part of my script? Its fast but it could be a lot faster i think.
function ProcessPath ($folder, $filePath)
{
$folderOwner = 55
##write-host Processing $filePath -BackgroundColor Cyan
LogInfo "Processing $filePath "
$acl = (get-acl filesystem::"$filePath" -ErrorAction SilentlyContinue).Access |Select-Object -ExpandProperty IdentityReference -Unique
foreach ($user in $acl)
{
if($groupid){
$groupid.Close();}
if($userid){
$userid.Close();}
$aclid = 0
$Domain,$user = $user -split "\\",2
$sqlCmd = $sqlConn.CreateCommand()
$sqlCmd.CommandText = "SELECT USER_ID,Obj_type FROM dbo.USERS where USER_LOGIN ='$user'";
$userid= $sqlCmd.ExecuteReader();
$userid.Read();
if (!$userid.HasRows)
{
$userid.Close();
$sqlCmdgrp = $sqlConn.CreateCommand()
$sqlCmdgrp.CommandText = "SELECT GROUP_ID,obj_type FROM dbo.GROUPS where GROUP_LOGIN ='$user'";
$groupid= $sqlCmdgrp.ExecuteReader();
$groupid.Read();
if (!$groupid.HasRows)
{
$objtype ='4'
$aclIdfinal='5'
}
else
{
$objtype =$groupid.GetValue(1);
$aclIdfinal=$groupid.GetValue(0);
}
$groupid.Close();
}
else
{
$objtype =$userid.GetValue(1);
$aclIdfinal=$userid.GetValue(0);
}
$objtype
$userid.Close();
sqlNonQuery "INSERT on database what i wanna)";
#write-host insert $user -BackgroundColor DarkCyan