check for file content in different paths out of a textfile

  • Follow


hi there

sorry guys..for you this might be a simple question. but i am new to 
powershell and i am queued to following problem:

1: i have a text file (array.txt), which is automatically generated. the 
content of this file are 5 lines. each line points as unc path to a location. 
how can i automatically check in each unc path of this file if there are 
files in the folder? i tried to use an array and also a foreach solution but 
i cant find the way to it. 

2: the above mentioned text file has (after the automatic generation of it) 
several blank lines. how i can prevent the creation of these blank lines?

here some code:

Get-Content 
\\server\share$\Helpdesk\Scripte\Profilbereinigung\adcomputer.txt | 
select-string -pattern $computer | ForEach-Object {Out-File -filepath 
c:\temp\array.txt -append -inputobject $_}

I really hope you understand my question :-)

Thanks for your help, guys!
0
Reply Utf 6/10/2010 1:34:35 PM

Try this to create array.txt without blank lines:
Get-Content 
\\server\share$\Helpdesk\Scripte\Profilbereinigung\adcomputer.txt | 
Where {$_ -match $computer } | Add-Content c:\temp\array.txt

This should work on the array file to check the paths:
Get-content array-txt | foreach { if (@(get-childitem $_) -gt 0) {"Files 
exist at $_"} else {"No files at $_"}}

-paul


"dumbo" wrote:

> hi there
> 
> sorry guys..for you this might be a simple question. but i am new to 
> powershell and i am queued to following problem:
> 
> 1: i have a text file (array.txt), which is automatically generated. the 
> content of this file are 5 lines. each line points as unc path to a location. 
> how can i automatically check in each unc path of this file if there are 
> files in the folder? i tried to use an array and also a foreach solution but 
> i cant find the way to it. 
> 
> 2: the above mentioned text file has (after the automatic generation of it) 
> several blank lines. how i can prevent the creation of these blank lines?
> 
> here some code:
> 
> Get-Content 
> \\server\share$\Helpdesk\Scripte\Profilbereinigung\adcomputer.txt | 
> select-string -pattern $computer | ForEach-Object {Out-File -filepath 
> c:\temp\array.txt -append -inputobject $_}
> 
> I really hope you understand my question :-)
> 
> Thanks for your help, guys!
0
Reply Utf 6/10/2010 3:59:11 PM

Thanks
The hint for the blanklines was working fine
With the array i got an error because the script was not able to handle the 
"-gt 0" so i did with -match "":

$TArray = Get-Content "c:\temp\array.txt"
foreach ($_ in $TArray) {if(Get-ChildItem $_ | where {$_.Extension -match 
""}) {Add-Content c:\temp\result.txt "OK $_"} else {Add-Content 
c:\temp\result.txt "Fehler $_"}}

This is working very fine now, thanks for your help Paul!

"PaulChavez" wrote:

> Try this to create array.txt without blank lines:
> Get-Content 
> \\server\share$\Helpdesk\Scripte\Profilbereinigung\adcomputer.txt | 
> Where {$_ -match $computer } | Add-Content c:\temp\array.txt
> 
> This should work on the array file to check the paths:
> Get-content array-txt | foreach { if (@(get-childitem $_) -gt 0) {"Files 
> exist at $_"} else {"No files at $_"}}
> 
> -paul
> 
> 
> "dumbo" wrote:
> 
> > hi there
> > 
> > sorry guys..for you this might be a simple question. but i am new to 
> > powershell and i am queued to following problem:
> > 
> > 1: i have a text file (array.txt), which is automatically generated. the 
> > content of this file are 5 lines. each line points as unc path to a location. 
> > how can i automatically check in each unc path of this file if there are 
> > files in the folder? i tried to use an array and also a foreach solution but 
> > i cant find the way to it. 
> > 
> > 2: the above mentioned text file has (after the automatic generation of it) 
> > several blank lines. how i can prevent the creation of these blank lines?
> > 
> > here some code:
> > 
> > Get-Content 
> > \\server\share$\Helpdesk\Scripte\Profilbereinigung\adcomputer.txt | 
> > select-string -pattern $computer | ForEach-Object {Out-File -filepath 
> > c:\temp\array.txt -append -inputobject $_}
> > 
> > I really hope you understand my question :-)
> > 
> > Thanks for your help, guys!
0
Reply Utf 6/15/2010 10:53:32 AM

2 Replies
672 Views

(page loaded in 0.116 seconds)

10/21/2014 11:59:19 PM


Reply: