gc from a txt file, put it in a variable, and pass to gci

I am trying to take a list of servers in a text file and put them into the 
variable $Server, the pass that variable on to the get-childitem cmdlet to 
get the ACL information of all of the folders in the "SDATA" folder where 
inheritance is turned off. 

$Server = get-content c:\scripts\servers.txt | Foreach-Object {Get-ChildItem 
\\$Server\SDATA | ? {$_.PSIsContainer} | ? {Get-Acl $_.FullName | % 
{$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | ? 
{!$_.IsInherited}}} | get-acl  | export-csv output4.csv -noType}

Most of the script works. If I remove the get-content and  foreach sections, 
and just run everything from get-childitemand I specify the actual servername 
it works fine. I have hundreds of servers to run this on so it needs to be 
automated. any help is greatly appreciated.

Thank you.

Kevin
0
Utf
2/11/2010 6:59:02 PM
windows.powershell 690 articles. 0 followers. Follow

3 Replies
980 Views

Similar Articles

[PageSpeed] 39

you are referencing a var that isnt there, $server. i assume you are 
relating that to your foreach, saying for each server go to server\sdata..

since the servers are coming from the previous part you would reference it 
like you do for PSIsContainer using the $_

so i think you just change \\$Server\SDATA to \\$_\SDATA and you should be 
good.

"ksinc11" <ksinc11@discussions.microsoft.com> wrote in message 
news:42016D84-51A1-46F1-B8D4-0BA0C1575178@microsoft.com...
>I am trying to take a list of servers in a text file and put them into the
> variable $Server, the pass that variable on to the get-childitem cmdlet to
> get the ACL information of all of the folders in the "SDATA" folder where
> inheritance is turned off.
>
> $Server = get-content c:\scripts\servers.txt | Foreach-Object 
> {Get-ChildItem
> \\$Server\SDATA | ? {$_.PSIsContainer} | ? {Get-Acl $_.FullName | %
> {$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | 
> ?
> {!$_.IsInherited}}} | get-acl  | export-csv output4.csv -noType}
>
> Most of the script works. If I remove the get-content and  foreach 
> sections,
> and just run everything from get-childitemand I specify the actual 
> servername
> it works fine. I have hundreds of servers to run this on so it needs to be
> automated. any help is greatly appreciated.
>
> Thank you.
>
> Kevin 

0
Justin
2/11/2010 7:03:35 PM
You're using $Server inside the foreach scriptblock but it doesn't reference 
anything.

Try this:

foreach ($server in (get-content c:\scripts\servers.txt))
{
Get-ChildItem \\$Server\SDATA |
? {$_.PSIsContainer} |
? {Get-Acl $_.FullName |
%{$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') |
? {!$_.IsInherited}}} | get-acl | export-csv output4.csv -noType
}


"ksinc11" wrote:

> I am trying to take a list of servers in a text file and put them into the 
> variable $Server, the pass that variable on to the get-childitem cmdlet to 
> get the ACL information of all of the folders in the "SDATA" folder where 
> inheritance is turned off. 
> 
> $Server = get-content c:\scripts\servers.txt | Foreach-Object {Get-ChildItem 
> \\$Server\SDATA | ? {$_.PSIsContainer} | ? {Get-Acl $_.FullName | % 
> {$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | ? 
> {!$_.IsInherited}}} | get-acl  | export-csv output4.csv -noType}
> 
> Most of the script works. If I remove the get-content and  foreach sections, 
> and just run everything from get-childitemand I specify the actual servername 
> it works fine. I have hundreds of servers to run this on so it needs to be 
> automated. any help is greatly appreciated.
> 
> Thank you.
> 
> Kevin
0
Utf
2/11/2010 7:07:02 PM
Thank you, that works great. 

Kevin

"PaulChavez" wrote:

> You're using $Server inside the foreach scriptblock but it doesn't reference 
> anything.
> 
> Try this:
> 
> foreach ($server in (get-content c:\scripts\servers.txt))
> {
> Get-ChildItem \\$Server\SDATA |
> ? {$_.PSIsContainer} |
> ? {Get-Acl $_.FullName |
> %{$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') |
> ? {!$_.IsInherited}}} | get-acl | export-csv output4.csv -noType
> }
> 
> 
> "ksinc11" wrote:
> 
> > I am trying to take a list of servers in a text file and put them into the 
> > variable $Server, the pass that variable on to the get-childitem cmdlet to 
> > get the ACL information of all of the folders in the "SDATA" folder where 
> > inheritance is turned off. 
> > 
> > $Server = get-content c:\scripts\servers.txt | Foreach-Object {Get-ChildItem 
> > \\$Server\SDATA | ? {$_.PSIsContainer} | ? {Get-Acl $_.FullName | % 
> > {$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | ? 
> > {!$_.IsInherited}}} | get-acl  | export-csv output4.csv -noType}
> > 
> > Most of the script works. If I remove the get-content and  foreach sections, 
> > and just run everything from get-childitemand I specify the actual servername 
> > it works fine. I have hundreds of servers to run this on so it needs to be 
> > automated. any help is greatly appreciated.
> > 
> > Thank you.
> > 
> > Kevin
0
Utf
2/11/2010 7:24:01 PM
Reply:

Similar Artilces:

gc from a txt file, put it in a variable, and pass to gci
I am trying to take a list of servers in a text file and put them into the variable $Server, the pass that variable on to the get-childitem cmdlet to get the ACL information of all of the folders in the "SDATA" folder where inheritance is turned off. $Server = get-content c:\scripts\servers.txt | Foreach-Object {Get-ChildItem \\$Server\SDATA | ? {$_.PSIsContainer} | ? {Get-Acl $_.FullName | % {$_.GetAccessRules($true, $true, 'System.Security.Principal.NTAccount') | ? {!$_.IsInherited}}} | get-acl | export-csv output4.csv -noType} Most of the script works. ...

Please help me divide a .txt email list that are separated with spaces and sort them in to excel cells
taking a .txt email list that are separated with spaces and sort them in to excel cells thanks so much in advance Please see your other threads where you posted. Can you only post you question once? (And if not receiving good answers, ONLY then considering posting it into another newsgroup). Thanks. -- Wigi http://www.wimgielis.be = Excel/VBA, soccer and music "adardesign@gmail.com" wrote: > taking a .txt email list that are separated with spaces and sort them > in to excel cells > thanks so much in advance > > ...

File/"copy to Folder" access
I am not able to find the "Copy to Folder" option, under the File dropdown, when replying (or forwarding) a message. I have tried adding it from the "customize" function, but was unsuccessful. Any ideas? What version of Outlook are you using? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP Roland Schorr & Tower http://www.rolandschorr.com Microsoft OneNote FAQ: http://www.factplace.com/onenotefaq.htm **I apologize but I am unable to respond to direct requests for assistance. Please post questions and replies here in the newsgroup. Mahalo! "news.hp.com"...

Slow File Open accesst to files
When using Excel 2002, and file open and going to mapped network drive folder that has 1000 files in it, it takes 4 to 5 minutes for the files to be listed in the file open window. If I go to Windows Explorer and browse this same folder the files are shown right away. On a different PC with Excel 2000, the file open list is populated right away. Any ideas? Roger Konwinski My first suggestion would be to move some of those 1000 files into separate subfolders. Not only will it make excel's life easier, it should make it easier for humans, too. But sometimes cleaning up the windows...

setting up different files
I want to know how to set up a seperate file or database for my mom. File|New. Money always opens the last file you used if you start it from Program Items. If you double click on the file you want to use instead, you can open the different files at different times. "jamesp" <jamesp@discussions.microsoft.com> wrote in message news:566A63F3-0906-4D02-A908-35CE57DAE979@microsoft.com... >I want to know how to set up a seperate file or database for my mom. 1. On the File menu, point to New, and then click New File. 2. In the Save in box, click the directory where you ...

Joint accounts in separate files
Is it possible, with any version of MS Money, to transfer funds to accounts that are in a sperate Money file? That is, my partner and I each us MS Money to manage our finances, using our own seprate MS Money files. We also have a few joint accounts. We would like to create a separate file for our joint accounts and be able to record the transfer of funds from our personal accounts to the joint account. How do we do this? Many thanks. Heather Money doesn't know how to do this. You will have to enter reciprocal transactions in each file. "Heather" <hrh@hhollick.com>...

Can't see existing zip files when saving attachments
I'm a college teacher and my students submit their homework via zipped email attachments. I save the attachments to each student's folder on my C: drive. About 1/3 of the time, when I attempt to save the zip attachment to an existing folder which already contains zip files, the existing files are not visible in the Outlook Save As dialog box. Other file types (e.g. rtf) display fine. Exiting and re-entering Outlook usually 'fixes' the problem. All of the files are then visible when I save the attachment. This problem was occuring in Outlook 2002 and has ported ...

GC [WildPacket]
This is the error I am getting on my Exchange Servers .. Event ID:9144 NSPI Proxy failed to connect to GC ServerName over transport TCP/IP.The Server is down or unreachable.Client will be directed to ......... I do have one GC in this site and it is up and running and I have 2 exchange boxes in this site and both have this error message?? Please advise. Thank you. The problem specifically relates to DSProxy and as the error points out it can't reach a GC server. Are you sure nothing is wrong with the GC box? What happens when you run DCDiag? Nue "WILDPACKET" <WILDPA...

Exchange Failing when Removing GC from same box
The background: I am trying to install Exchange 2007 but cannot because I have two Windows 2000 DCs with GCs. The two Windows 2000 DCs happen to be on the same boxes as my Exchange 2000 cluster. I have two other Windows 2003 boxes in the same site with all FSMO roles and both are GC. The problem: I'm in a catch 22 because I cannot install Exchange 2007 and when I remove either the GC role from the Windows 2000 boxes or demote them, Exchange fails. The Question: Has anyone come across a situation like this and know of a solution? Thanks In order to install Ex07, you will ne...

Picture File
Hello, I have a problem that just started for no apparent reason. I have been using photo's edited in Picture IT 2000, I cut-out a part of a photo and then save it in either JPEG or Picture it format then insert it in my Publisher projects, no problem. However this last time I try to do the same and for some reason the photo keeps a white background around the object that I cut-out. Example : I cut out a picture of a hat in Picture it and then I insert it on someone's head in a publisher project. This used to come out ok and then for some reason the "cut-out" hat had a white ...

Publisher Cannot Save File
Perhaps I'm having a "blonde moment" but I'm trying to save my catalog and get message "Publisher Cannot Save File". I have attempted to save it to different drives as well as to my server but always receive same message. Can anyone help me? Hi Pam, 1. Have you tried saving to your main local drive, usually the C:Drive? 2. Does this happen only with this particular publication, or for all publications? 3. Are you signed on as an administrator or as a users? 4. Are you running over a network and trying to save over a network? Brian Kvalheim Microsoft Publis...

need help finding outlook files now that I have loaded XP
This is a long story but I'll try to be concise.....I had a problem with Windows 2000 and could not logon ...so after alot of phone calls I decided to go ahead and load XP on (which I already had) but I was afraid I would lose my files that I used with Windows 2000 so I loaded XP in a different directory. Therefore I now have two operating systems on my computer. Since then, I have managed to reload all my software so that it points to XP and most things are up and running. However, I use Outlook 2000 for my contacts, email, etc. I have managed to get any emails in the inbox ...

how do I create comma and double quote delimited file
I'm trying to create an csv type file with double quote around selected cell values Mike, Excel will put quote marks around a cell that contains a comma, or already has quote marks in it. Otherwise, it won't. If you need quotes around all fields, try the Text Write Program at www.smokeylake.com/excel. Also, there's info on text files in section "Text files and Excel." -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "mikeb" <mikeb@discussions.microsoft.com> wrote in message news:302D628...

second outlook data file
Hi, I created a second outlook data file for my daughter's email. However, when she gets an email to her pop3 account, send/receive doesn't download it to her mailbox. Might there be a setting I missed or are you allowed only one data file to receive email. When I set up the data file I entered the email account including all the pop3 settings. Thanks. Gary Do you mean that you set up a seperate profile for your daughter which included mail server settings & PST settings? "Gary" <Gary@discussions.microsoft.com> wrote in message news:75CD4761-6946-4975-...

[2007] Any way to transparently import data from txt ?
Hi there Excel developers, Is there any way to transparently import data into a sheet using the same parameters than when you do it manually but without asking for anything and without displaying the import wizard, just pass its parameters? The operation consists of: - Data -> Import from TXT - Then tell it "Fixed Width" and "Start at row 40" - Then set the column separators (break lines) by positions - Then import the data Is this possible programmatically? Without recording a macro? Thanks for any help. Sincerely, Steve JORDI (Remove the K_I...

Rename Exchange Database file
Could anybody show me the safe way to rename exchange database file: priv1.edb to priv2.edb ? Thank you. I want to rename it because I was reading an article that says that I can have problem restoring exchange if the two databases .edb and .stm have the same name, backed up and restored at the same time. Thank you I would not bother about renaming them, and I cannot understand why you would have problems. -- Mark Fugatt "Thuan Pham" <thuanp@advancedcableties.com> wrote in message news:17a501c48c68$ed6f5380$a601280a@phx.gbl... > Could anybody show me the safe way t...

BackupWrite and file times
Hello! I am using BackupRead to backup files and BackupWrite to restore them. I have noticed that the restored files do not have the create, access, and modified times of the original file. I was under the impression that BackupRead was supposed to save all file information. I can always use SetFileTime to set the file dates after restore, but that means I have to come up with a way to store the dates along with the file. Is normal for BackupWrite to not set file dates or am I doing something wrong? Thank you! -Anton ...

Delete multiple files from a folder using an Access Database
Good Morning All, I am not sure if I am posting this in the right place, but please bear with me. I am trying to run a db query to quickly populate a database with filenames from a folder on my hard drive. Then in turn I would like to be able to delete files from the folder, based on my deletes in the database. I hope that this makes sense. I am currently using the following code in the Visual Basic editor to populate my table with the necessary data: Sub GetGameFiles() Dim strFile As String Dim strFolder As String Dim strSQL As String strFolder = "C:\path\to\thefile\iwantadded\tothi...

Macro to open files from a partial file name ?
Hi, I have an external application which dumps data to text files which I then work on using excel. I'm trying to write a macro to automate the batch conversion process, but I have a problem because the external application names the files with a date appendage (see example below) :- B_Report_011103.txt I do need to keep the date in the excel file name if possible. How can I get excel to open any filename begining with the string "B_Report" ? Is there any way of adding a wildcard to the file name string ? Rich On Sat, 1 Nov 2003 08:14:21 +0000 (UTC), "Rich" ...

Can't see existing files when saving attachments.
I'm a teacher at a college and my students submit their homework via zipped email attachments, so I get a lot of email each day with attached files. Between a quarter and a third of the time when I attempt to save the attachment to an existing folder which already contains files, some or all of the existing files are not visible. I've just noticed that this is particularly true for zipped files. Exiting and re-entering Outlook usually 'fixes' the problem. All of the files are then visible. I've tried a variety of search combos in the Knowledgebase with no s...

GC [WILDPACKET
Removing a DC which is also a GC and is the first DC in our Domain. There are other DCs too which are GCs. We have 3 Exchange 2003 Server in our setup, how do I check that at which GCs are these 3 Exchange Servers looking at and how do I change them to see at a new GC DC? Please advise. Thank you in advance. On Thu, 24 Nov 2005 11:41:08 -0800, "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote: >Removing a DC which is also a GC and is the first DC in our Domain. >There are other DCs too which are GCs. > >We have 3 Exchange 2003 Server in our setu...

Outputting a CString to File Problem
Hello, Currently I am using Visual C++ 2005 Pro, with an MFC application. However, when I attempt to output a CString to a file via ofstream, the resulting output is a hex value, not the text in the CString I intended. Does anybody have any ideas why this would happen? Here is the code snippet in question: CString sPathToSettings = GetWorkingDirectory(); sPathToSettings += "settings.ini"; ofstream OutFile(sPathToSettings); OutFile << sPathToSolution; OutFile.close(); BTW: The sPathToSettings string points to a valid path, as it does create a file successfully. ...

Shared File
Excel 2007 I have an Excel file that is [Shared] I would like to change the password on this file, but it will not let me. How do I change this file so it is not shared? And is this what is stopping me from changing the password? Sharing a s/s does not require a password. To unshare select Review on the ribbon and then in the Changes box you will see options for protecting and sharing. On the editing tab check the box "Allow changes .. etc" Is the s/s protected? That's usually where you will find it is password protected. "Canon" wrote: > ...

copy file via Access VBA
How can I make a copy of C:\Source\test.txt to C:\CopyLoc\ but if test.txt already exist in C:\CopyLoc\ not to do anything. Thanks, Dan hi Dan, On 18.03.2010 11:10, Dan wrote: > How can I make a copy of C:\Source\test.txt to C:\CopyLoc\ > but if test.txt already exist in C:\CopyLoc\ not to do anything. Use this Win32 API function: Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" ( _ ByVal AExistingFileName As String, _ ByVal ANewFileName As String, _ ByVal AFailIfExists As Boolean _ ) As Boolean Copy it in ...

Splitting a workbook's sheets into seperate files
I have a workbook with several spreadsheets in it, how do I quickl seperate these sheets into seperate files -- Turnipbo ----------------------------------------------------------------------- Turnipboy's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2452 View this thread: http://www.excelforum.com/showthread.php?threadid=47779 I think the only way, is programing it with vba. I suggest using "For Each" statement to scroll through all sheets in a given workbook, and within the "For" creating a new workbook (using "Add" statement),...