"Supply Values for the following parameters"

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

  • Author
    Posts
  • #5179

    by Cancerous at 2012-10-08 22:32:43

    Noob to PS, but I know bash and batch.

    I'm trying to do a simple script that tests the existence of a file and then creates another depending on the outcome, but prompts me for a parameter value after running it.

    Code:
    function test-existence {
    if(test-path -path "C:\testran.flag") {echo > C:\users\admin\desktop\true.flag}
    if(!(test-path -path "C:\testfailed.flag")) {echo > C:\users\admin\desktop\false.flag}
    test-existence
    I've tried running it as a function and just as a two line script, but it still produces the same result.

    Prompt:
    [quote]Supply values for the following parameters:
    InputObject[0]]This is part of a fully automated setup so I need this to run without any user interaction.

    Thanks.

    by Klaas at 2012-10-09 00:45:45

    echo is an alias for write-output, and if you don't tell it what it has to write, it will ask you.
    try Get-Help echo -full
    Maybe you want to use New-Item instead:
    if(test-path -path "C:\testran.flag") {New-Item -Type file -Path C:\users\admin\desktop\true.flag}

    by Cancerous at 2012-10-10 15:04:50

    Solved it using Add-Content

    function test-existence
    {
    if(test-path -path "C:\testran.flag") {Add-Content C:\users\admin\desktop\true.flag ""}
    if(!(test-path -path "C:\testfailed.flag")) {Add-Content C:\users\admin\desktop\false.flag ""}
    }
    test-existence

You must be logged in to reply to this topic.