![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Out-File redirection is driving me crazy Hi everyone, I'm taking a citrix exported user list and converting it to import into AD. I have a app file for each application and want to save userlist in another file. My script runs like this: PS D:\> $files= dir *.app PS D:\> foreach ($file in $files) {Get-Content $file | Select-String -SimpleMatch domainname |% {$_ -replace '"domainname"/"','domainname\'} |% {$_ -replace '";',';'} |% {$_ -replace '".',';'} | out-file -filepath "c:\$file" } It reports Out-File : The given path's format is not supported. If I just use $file it complains: Get-Content : The process cannot access the file because it is being used by another process. Well, I just found it while i was writing this. $file is full path, so I was doing C:\d:\... I could solve it using $file.Name (almost) |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Out-File redirection is driving me crazy "Cesar Garcia" <CesarGarcia@xxxxxx> wrote in message news:86B42B1F-3172-46E6-9B30-255CA207DD27@xxxxxx Quote: > Hi everyone, > I'm taking a citrix exported user list and converting it to import into > AD. > I have a app file for each application and want to save userlist in > another > file. > My script runs like this: > PS D:\> $files= dir *.app > PS D:\> foreach ($file in $files) {Get-Content $file | > Select-String -SimpleMatch domainname > |% {$_ -replace '"domainname"/"','domainname\'} > |% {$_ -replace '";',';'} > |% {$_ -replace '".',';'} > | out-file -filepath "c:\$file" } > > It reports Out-File : The given path's format is not supported. > > If I just use $file it complains: Get-Content : The process cannot access > the file because it is being used by another process. > > Well, I just found it while i was writing this. $file is full path, so I > was > doing C:\d:\... > > I could solve it using $file.Name (almost) the same file you are going to run into problems with this approach so try this: PS D:\> $files= dir *.app PS D:\> foreach ($file in $files) { (Get-Content $file) | Select-String -SimpleMatch domainname |% {$_ -replace '"domainname"/"','domainname\'} |% {$_ -replace '";',';'} |% {$_ -replace '".',';'} | out-file $file } Putting the () around the Get-Content will cause it to read the while file in before it starts sending lines down the pipe. If your file is really large, this approach isn't the best way to accomplish your goal. In that case, use a temp file and when you are done copy the temp file over the original file. -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Out-File redirection is driving me crazy "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message news:6AD7E017-2592-4677-932A-D94CE4F4B265@xxxxxx Quote: > Putting the () around the Get-Content will cause it to read the while file -- Keith |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Out-File redirection is driving me crazy My problem was with $file in Out-File. Sometimes I was getting full path like D:\path\to\file\excel.app and sometimes just file. I wasn't getting expected results even using $file.Name so... I added an extesion and wrote following code: foreach ($file in $files) {Get-Content $file | Select-String -SimpleMatch munimadrid |% {$_ -replace '"munimadrid"/"','munimadrid\'} |% {$_ -replace '";',';'} |% {$_ -replace '".',';'} |out-file ("$file" + '.list') } And it just works. I'll try your approach Keith to see if it improves performance. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Out-File redirection is driving me crazy I was getting some problems with $file name. Sometimes I was getting full path, sometimes just $files.Name. Anyway I was unable to get it working, until I followed this approach. PS D:> foreach ($file in $files) {Get-Content $file | Select-String -SimpleMatch domainname |% {$_ -replace '"domainname"/"','domainname\'} |% {$_ -replace '";',';'} |% {$_ -replace '".',';'} |out-file ("$file" + '.list') } I'll try your suggestion too Keith, to see if it improves performance anyway. Thanks |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Driving me crazy ! | Network & Sharing | |||
| WMI driving me crazy | VB Script | |||
| This is ABSOLUTELY driving me crazy: file type associations/default programs | Vista file management | |||
| Driving me crazy.... | Vista mail | |||
| How do I do this - it's driving me crazy | Vista installation & setup | |||