Foreach blank lines

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 9 months ago.

  • Author
    Posts
  • #5356

    by O.Ferre at 2012-12-17 02:21:38

    Hi,
    I try to write a script to shutdown computers from a list

    example :
    foreach($pc in $liste)
    {
    shutdown -s -m \\$pc -c "Shutdown -`n Shutdown" -f -t 100
    }

    But, sometimes, there is a blank line in the file $liste, so the local computer shutdown.
    is there a way to continue if the line is blank
    if ($pc -eq $null)
    continue

    thanks a lot
    O.F

    by MattG at 2012-12-17 04:35:06

    You could simply check that the line is not null and shutdown accordingly:
    foreach($pc in $liste)
    {
    if ($pc)
    {
    shutdown -s -m \\$pc -c "Shutdown -`n Shutdown" -f -t 100
    }
    }

You must be logged in to reply to this topic.