none
how to select more folder? RRS feed

  • Question

  • Hi guys,

    I want to get more info out of my folders, at the moment i will receive an email if nothing has been added. My problem is i dont know how to let the script run for multiple folders. Any help is appreciated.

    Script below:

    [string]$path = @("X:\Brievenbus\Customer1")


     $File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }

    $SMTPMessage = @{
    To = $To
    From = $From
    Subject = "$Subject at $Path"
    Smtpserver = $SMTPServer
    }


    ForEach ($path in $path){
    #$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }
    If ($File -eq $null)
    { $SMTPBody = "`nLaatste 24H is er niets meer gestuurd bij klant:`n`n $($_.FullName) $path"

    Send-MailMessage @SMTPMessage -Body $SMTPBody
    }
    }

    Monday, October 8, 2018 7:05 AM

Answers

  • $paths = @("X:\Brievenbus\Customer1", "X:\Brievenbus\Customer2","X:\Brievenbus\Customer3") ForEach ($path in $paths) { $SMTPMessage = @{ To = $To From = $From Subject = "$Subject at $path" Smtpserver = $SMTPServer } $File = Get-ChildItem $path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) } If ($File -eq $null) { $SMTPBody = "`nLaatste 24H is er niets meer gestuurd bij klant:`n`n $($_.FullName) $path" Send-MailMessage @SMTPMessage -Body $SMTPBody

    } }


    • Marked as answer by Shango92 Monday, October 8, 2018 8:41 AM
    Monday, October 8, 2018 7:54 AM

All replies

  • $paths = @("X:\Brievenbus\Customer1", "X:\Brievenbus\Customer2","X:\Brievenbus\Customer3") ForEach ($path in $paths) { $SMTPMessage = @{ To = $To From = $From Subject = "$Subject at $path" Smtpserver = $SMTPServer } $File = Get-ChildItem $path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) } If ($File -eq $null) { $SMTPBody = "`nLaatste 24H is er niets meer gestuurd bij klant:`n`n $($_.FullName) $path" Send-MailMessage @SMTPMessage -Body $SMTPBody

    } }


    • Marked as answer by Shango92 Monday, October 8, 2018 8:41 AM
    Monday, October 8, 2018 7:54 AM
  • Works perfect. Thanks alot.
    Monday, October 8, 2018 8:41 AM