bob mar
bob mar

Reputation: 7

Powershell Script Prompt 2 input in one go

i wanted to make one prompt to ask for 2 input in one go for e.g "D:\Test\File 1", "D:\Test\File 2 instead of this input first file path: "D:\Test\File 1", input second file path: "D:\Test\File 2".

function compareTwoFiles($firstFilePath, $secondFilePath) 
{
$firstFilePath = Read-Host "Input first file path" 
$secondFilePath = Read-Host "Input second file path"

if ($firstFilePath.Length -gt $secondFilePath.Length)
    {"File 1"}
elseif ($firstFilePath.Length -lt $secondFilePath.Length)
    {"File 2"}
else {"both file has same size"}
return
}

Upvotes: 0

Views: 459

Answers (1)

AwatITWork
AwatITWork

Reputation: 586

try to do this, input the file path and separate them with ";" or "-" or any other char, then split the input like this:

$input = Read-Host "Input first file path, place ';' and then other file path " 
$userInputs = $input.Split(";")

$userInputs[0]
$userInputs[1]

The output:

PS C:\Users\Awat\Desktop\testPS> .\myscript.ps1
Input first file path, place ';' and then other file path : file1.txt;file2.txt
file1.txt
file2.txt
PS C:\Users\Awat\Desktop\testPS>

your code should be similar to this:

$input = Read-Host "Input first file path, place ';' and then other file path " 
$userInputs = $input.Split(";")

// Just for output....
$userInputs[0]
$userInputs[1]

if ($userInputs[0].Length -gt $userInputs[1].Length)
    {"File 1"}
elseif ($userInputs[0].Length -lt $userInputs[1].Length)
    {"File 2"}
else {"both file has same size"}
return

Upvotes: 1

Related Questions