Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Converting PowerShell Script Into Parallel Runs

$
0
0
I have been doing a bit of research on PowerShell "parallel" running of code, and I'm not quite understanding how to use some code that I've got in this way.

What I am trying to do is run my code against the 42 file share servers here at work. The code works fine, but I have been manually setting up and running 42 instances of PowerShell to complete the task. I was hoping that I could convert my code into the parallel functions so that they could all run in the one window.
Workflow ServerRun 
{
    $ListOfServers = Get-Content "C:\Test Folder\ListOfServers.txt"

    ForEach -parallel ($FileServer in $ListOfServers)
    {
        $FileServerSharesFullName = gwmi win32_Share -ComputerName $FileServer | Where-Object {$_.type -eq '0'} | Where {$_.name -notlike "$"}

        $FileServerShares = $FileServerSharesFullName.Name | % {$_.ToString()}

        $DataOutFile = "C:\Test Folder\Data\$FileServer.FolderPermissions.txt"

        Foreach ($Share in $FileServerShares)
        {
            $FilePath = "\\" + $FileServer + "\" + $Share

            $FoldersInFilePath = gci -Path $FilePath -Directory -Recurse

            Foreach ($Folders in $FoldersInFilePath)
            {
                Foreach ($Folder in $Folders)
                {
                    $ACLs = get-acl $Folder.FullName |
                    ForEach-Object {$_.Access} |
                    Where {$_.IdentityReference -notlike "*BUILTIN*" -and $_.IdentityReference -notlike "*NT AUTHORITY*" -and $_.IdentityReference -notlike "CE\Domain Admins" -and $_.IdentityReference -notlike "Everyone" -and $_.IdentityReference -notlike "CREATOR OWNER" -and $_.IdentityReference -notlike "CE\Domain Users" -and $_.IdentityReference -notlike "*S-1-5*" -and $_.IdentityReference -notlike "*lndk*" -and $_.IdentityReference -notlike "*Domain Computers*" -and (dsquery group -samid $_.IdentityReference.Value.Split("\")[1])}
                    Foreach ($ACL in $ACLs)
                    {
                        $DataOutInfo = $Folder.Fullname + ":" + ($ACL.IdentityReference.Value.Split('\'))[1] + ":" + $ACL.FileSystemRights
                        Add-Content -Value $DataOutInfo -Path $DataOutFile
                    }
                }
            }
        }
    }
}

When I run this in in PowerShell ISE, nothing runs... Any help would be greatly appreciated.

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>