Zack
asked on
Running PowerShell Through Series of Pre-Defined Directories
Hi EE,
If I had the following code
How could I add a list of series directories for this code module to execute against? Ideally, I would like to read the directories from .txt file e.g Directories.txt with each new line being treated a new directory.
Any assistance is welcome.
Thank you.
If I had the following code
$batchfiles = (gci -path .\downloads -filter "*batch*.csv").fullname
foreach ($file in $batchfiles){
$f = gc $file -ReadCount -1
write-host "$($($f.tochararray().where({$_ -eq ""'""}) | measure).count) apostrophes in $file"
out-file -FilePath $file -InputObject $f.Replace("'", '''')
}
}
How could I add a list of series directories for this code module to execute against? Ideally, I would like to read the directories from .txt file e.g Directories.txt with each new line being treated a new directory.
Any assistance is welcome.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well I think that at that point the $script var is not giving any output.
find out the Output file you defined in line #7
find out the Output file you defined in line #7
ASKER
Hi Jose,
It doesn't exist.Output.txt that is.
Thank you.
It doesn't exist.Output.txt that is.
Thank you.
ASKER
Hi Jose,
Hold up mate just looking at the event logs and I am getting a security issue one sec.
Thank you.
Hold up mate just looking at the event logs and I am getting a security issue one sec.
Thank you.
ASKER
Hi Jose,
Our system admin has left for the day otherwise I'd have a 'talk' he said security was disabled grrrr on my Dev box.
Do you mind waiting until Monday or shall just award points now?
Thank you for understanding
Our system admin has left for the day otherwise I'd have a 'talk' he said security was disabled grrrr on my Dev box.
Do you mind waiting until Monday or shall just award points now?
Thank you for understanding
I don't mind waiting haha I'm not in a rush :) I won't go anywhere :P
You can use another way:
Instead of:
You can use in sequentially instead:
You can use another way:
Instead of:
Get-Job | Remove-Job -Confirm:$false -Force
foreach($directory in $(gc $PathToTextFile -ea Stop)){
Invoke-Command -ScriptBlock $script -ArgumentList $directory,$OutputFile -AsJob
}
Get-Job | Wait-Job
Get-Job | Receive-Job
You can use in sequentially instead:
foreach($directory in $(gc $PathToTextFile -ea Stop)){
Invoke-Command -ScriptBlock $script -ArgumentList $directory,$OutputFile
}
ASKER
No output at all.
Open in new window
Running as admin ./fileparser.ps1
Thank you