# Present file act from many servers at once

**URL:** <https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560>\
**Category:** PowerShell Help\
**Created:** [September 17, 2021, 8:39am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560 "2021-09-17T08:39:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![skoeld](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@skoeld](https://forums.powershell.org/u/skoeld)\
**Post date:** [September 17, 2021, 8:39am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/1 "2021-09-17T08:39:28Z")

</div>

I am creating a script that pressent actual security settings on each file and catalog and then exporting it to an Excel file.

Now to the problem. I am importing servernames by using an csv file. So far so good.  
But now I want to make a check and create an excel worksheetname for each different servername where info is presented.

There is my problem.

```auto
$excel = New-ConditionalText -Range "A1:E1" -BackgroundColor Yellow -ConditionalTextColor Black
$ExportPath = "g:\Edu.xlsx"

$server = Get-Content "F:\Scripts\Computers.txt"
$Output = @()
ForEach ($srv in $server){
   $FolderPath = Get-ChildItem -Directory -Path \\$srv\d$\Websites -Recurse -Force
  
ForEach ($Folder in $FolderPath) {
    $Acl = Get-Acl -Path $Folder.FullName
    ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{ `
    'Folder Name' = $Folder.Name;
    'Folder Path' = $Folder.FullName;
    'Group/User' = $Access.IdentityReference.ToString();
    'Permissions' = $Access.FileSystemRights;
    'Inherited' = $Access.IsInherited}
$Output += New-Object -TypeName PSObject -Property $Properties            
}
}}
#$Output | Out-GridView
$Output | Export-Excel $ExportPath `
    -AutoSize `
    -AutoFilter `
    -BoldTopRow `
    -FreezeTopRow `
    -WorksheetName $srv `
    -ConditionalText $excel

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 17, 2021, 9:08am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/2 "2021-09-17T09:08:16Z")

</div>

You have to move your `Export-Excel` command inside the outermost foreach loop and use the server name as a part of the file name. 😉

---

<div class="post-metadata">

**Author:** ![skoeld](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@skoeld](https://forums.powershell.org/u/skoeld)\
**Post date:** [September 17, 2021, 9:13am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/3 "2021-09-17T09:13:03Z")

</div>

Ok that created the worksheetnames correctly but information was from each server in every sheet ☹  
I am missing something small I know but I am totaly stuck right now

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 17, 2021, 9:15am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/4 "2021-09-17T09:15:33Z")

</div>

Hmmm … did I get you right? You wanted to have the results for each server in a separate file, right?

Something like this should work actually:

```auto
$excel = New-ConditionalText -Range "A1:E1" -BackgroundColor Yellow -ConditionalTextColor Black
$server = Get-Content 'F:\Scripts\Computers.txt'
$ExportPath = 'g:\Edu.xlsx'

ForEach ($srv in $server) {
    $FolderPath = Get-ChildItem -Directory -Path \\$srv\d$\Websites -Recurse -Force
    $result = 
    ForEach ($Folder in $FolderPath) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
            [PSCustomObject][ordered]@{ 
                'Folder Name' = $Folder.Name
                'Folder Path' = $Folder.FullName
                'Group/User' = $Access.IdentityReference.ToString()
                'Permissions' = $Access.FileSystemRights
                'Inherited' = $Access.IsInherited
            }
        }
    }
    $ExportExcelParams = @{
        Path = $ExportPath
        AutoSize = $true
        AutoFilter = $true
        BoldTopRow = $true
        FreezeTopRow = $true
        WorksheetName = $srv
        ConditionalText = $excel
    }
    $result | Export-Excel @ExportExcelParams
}

```

---

<div class="post-metadata">

**Author:** ![skoeld](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@skoeld](https://forums.powershell.org/u/skoeld)\
**Post date:** [September 17, 2021, 9:23am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/5 "2021-09-17T09:23:54Z")

</div>

Close but not exactly.  
Instead of creating a separate file for every server I want to create a separate worksheet in one excel file with the servername and info from that and only that server.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 17, 2021, 9:29am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/6 "2021-09-17T09:29:48Z")

</div>

Ah … ok … without having experiences with this module and without trying it right now … I changed my code suggestion above … try it

---

<div class="post-metadata">

**Author:** ![skoeld](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@skoeld](https://forums.powershell.org/u/skoeld)\
**Post date:** [September 17, 2021, 9:29am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/7 "2021-09-17T09:29:58Z")

</div>

This is the solution. 🙂

```auto
$excel = New-ConditionalText -Range "A1:E1" -BackgroundColor Yellow -ConditionalTextColor Black
$server = Get-Content "F:\Scripts\Computers.txt"

ForEach ($srv in $server) {
    $FolderPath = Get-ChildItem -Directory -Path \\$srv\d$\Websites -Recurse -Force
    $result = 
    ForEach ($Folder in $FolderPath) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
            [PSCustomObject][ordered]@{ 
                'Folder Name' = $Folder.Name
                'Folder Path' = $Folder.FullName
                'Group/User' = $Access.IdentityReference.ToString()
                'Permissions' = $Access.FileSystemRights
                'Inherited' = $Access.IsInherited
            }
        }
    }
    $ExportExcelParams = @{
        Path = "g:test.xlsx"
        AutoSize = $true
        AutoFilter = $true
        BoldTopRow = $true
        FreezeTopRow = $true
        WorksheetName = $($srv)
        ConditionalText = $excel
    }
    $result | Export-Excel @ExportExcelParams
}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 17, 2021, 9:31am UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/8 "2021-09-17T09:31:24Z")

</div>

Ah … now you’ve figured it out by yourself … great. 👍🏽 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:21pm UTC](https://forums.powershell.org/t/present-file-act-from-many-servers-at-once/17560/9 "2024-05-16T20:21:21Z")

</div>


