Solved

multiple file output powershell

Posted on 2016-10-28
7
19 Views
Last Modified: 2016-10-28
I have a script that goes out and gets the folder ACL's recursive, however, the files are getting quite large..is there a way to make it cap at a certain file size then create new?
$ErrorActionPreference = "Continue" 
$strComputer = $env:ComputerName 
$colDrives = Get-PSDrive -PSProvider Filesystem 
ForEach ($DriveLetter in $colDrives) { 
    $StartPath = "E:\Share" 
    Get-ChildItem -LiteralPath $StartPath -Recurse | 
    ForEach { 
      $FullPath = Get-Item -LiteralPath (Get-Item -LiteralPath $_.PSPath) 
      (Get-Item -LiteralPath $FullPath).GetAccessControl() | 
      Select * -Expand Access | 
      Select @{N='Server Name';E={$strComputer}}, 
             @{N='Full Path';E={$FullPath}}, 
             @{N='Type';E={If($FullPath.PSIsContainer -eq $True) {'D'} Else {'F'}}}, 
             @{N='Owner';E={$_.Owner}}, 
             @{N='Trustee';E={$_.IdentityReference}}, 
             @{N='Inherited';E={$_.IsInherited}}, 
             @{N='Inheritance Flags';E={$_.InheritanceFlags}}, 
             @{N='Ace Flags';E={$_.PropagationFlags}}, 
             @{N='Ace Type';E={$_.AccessControlType}}, 
             @{N='Access Masks';E={$_.FileSystemRights}} } | 
      Export-CSV -NoTypeInformation -Delimiter "|" –Path "$strComputer`_$DriveLetter.csv" }

Open in new window

0
Comment
Question by:leadtheway
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:contactkarthi
ID: 41864079
try using -maxsize
0
 
LVL 1

Author Comment

by:leadtheway
ID: 41864095
where would it go?
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41864272
So far as I know Export-CSV doesn't have the -MaxSize parameter.  You'd probably need to re-write the end of the script to Export-CSV -Append and then update the output file name each time by checking it's size and moving to the next file when it's size has been reached.

With some re-writes you could have it export a csv for each drive root folder.  It seems to me just splitting it on file size is going to make it hard to use efficiently.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:leadtheway
ID: 41864306
the way it is now will output per drive letter, problem is for a file server the list gets huge, over 1gb already
0
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41864356
Over 1GB in CSV?  You're collecting a ton of information then, I don't think CSV is the right format.  Even if you split it into 20MB files that would be 50 different files, how would you efficiently use that for anything?

I think you might want to stand up a SQL Express instance and drop the information into SQL, where you can query it to get the information you need on demand.  You can have your script repopulate it every x duration to keep it current.
0
 
LVL 1

Author Comment

by:leadtheway
ID: 41864437
maybe I need a script that just gives me what I'm looking for.. I just need the folder name and ACL
0
 
LVL 1

Author Comment

by:leadtheway
ID: 41864495
I think i need to go the SQL route..don't look like this is a good option
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now