0

My powershell script is setup as follows:

$body =  Get-ChildItem E:\log -File -Recurse | Where Name -Match '(\d{8})\.' | 
    Foreach {Add-Member -Inp $_ NoteProperty ReturnDate ($matches[1]) -PassThru} | 
    Group DirectoryName | 
    Foreach {$_.Group | Sort ReturnDate -Desc | Select -First 1 | Out-String }


$emailSmtpServer = "server"
$emailFrom = "email"
$emailTo = "email"
$emailSubject = "Testing e-mail"
$emailBody = $body


Send-MailMessage -To $emailTo -From $emailFrom -Subject $emailSubject -Body ($body|Out-String) -SmtpServer $emailSmtpServer

In the log folder I have a bunch of subfolders, e.g. folder1, folder2, folder3. These are likely to change so I'd like to setup a config file to be able to maintain them instead of going through the entire E:\log folder each time I run the script.

I want to add something such as

$configfile = Get-Content -path E:\config.txt

This outputs Process1, Process2, Process3, etc and I'm uncertain how to put that data into my script the way it's currently structured. Any advice would be appreciated. I was trying to add

$body = Get-Childitem E:\log\$_ 

to my initial line, but that was not working

1 Answer 1

1

Try this:

get-childitem ( get-content e:/config.txt )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.