What is wrong with the following Script ? RRS feed

  • Question

  • function Random-Number()
     $randays=Get-Random -Minimum -0 -Maximum 200
     $Date = (Get-Date).AddDays(-$randays).ToString('MM/dd/yyyy')

     return $Date $SettleDate
                {Write-Host $Date  $SettleDate}
            {Write-Error $_.Exception.Message
            throw "Unable to generate : $Date & $SettleDate"}

    the above code giving me the following two error

        Unexpected token 'SettleDate' in expression or statement.

        Missing function body in function declaration. 

     What I am doing wrong here
    Monday, May 28, 2018 11:38 AM

All replies

  • Place a comma between $Date and $SettleDate. And you should start to learn the basics of Powershell, please.
    return $Date , $SettleDate

    Best regards,


    • Edited by BOfH-666 Monday, May 28, 2018 12:11 PM
    • Proposed as answer by jrv Monday, May 28, 2018 1:31 PM
    Monday, May 28, 2018 12:10 PM