0

I have a powershell script for foldercleanup. I want key value ($key) to be returned by a function called passval ,which is a separate file. but its not passing. This is the function

  function passval{$s="cleanupfolder"
               $s
              return $s}

This is the main code

$colItems = (Get-ChildItem D:\00Newfolder  -recurse | Measure-Object -property length -sum)
    "{0:N2}" -f ($colItems.sum / 1MB) + " MB"
    $xxx="{0:N2}" -f ($colItems.sum/ 1MB)
    $str=Get-Content D:\trial.txt | ConvertFrom-Csv

    "This is the function passed value" 
     $key = passval
     echo $key

    $flag=0

    for($i=0; $i -lt $str.length; $i++){

    if($str[$i].key -eq $key){
    $flag=1
    $flag
    $value=$str[$i].value



    }
    }

    $flag

    if($flag -eq 0){$a = new-object -comobject wscript.shell

    $b = $a.popup(“no match" )}

    if($flag -eq 1){$a = new-object -comobject wscript.shell

    $b = $a.popup(“ match" )}             


    if($xxx -gt $value){Remove-Item  D:\00Newfolder\*   -include *.jpg}

    $colItems = (Get-ChildItem D:\00Newfolder  -recurse | Measure-Object -property length -sum)
    "{0:N2}" -f ($colItems.sum / 1MB) + " MB"
    $xxx="{0:N2}" -f ($colItems.sum/ 1MB)

1 Answer 1

1

Where is your passval function defined? It has to be defined before it's called. And as it's now it will return your value twice, change it to:

function passval
{
     $s="cleanupfolder"               
     return $s
}

And on a side note: work on you formatting and naming. In powershell your function should be called something like Get-PassValue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.