locked
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')
     $SettleDate=(Get-Date).AddDays(-$randays+2).ToString('MM/dd/yyyy')   

     return $Date $SettleDate
            try
                {Write-Host $Date  $SettleDate}
            catch
            {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,

    (79,108,97,102|%{[char]$_})-join''


    • 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