Gainster
Gainster

Reputation: 5631

Prompting for input in powershell

I want to the script to prompt for the string pattern in the select-string. How can I do that ?

$FileExists = (Test-Path C:\Users\v-hshabb\Desktop\text.txt)
echo $FileExists
If (($FileExists)) 
{
echo $FileExists
  Remove-Item C:\Users\v-hshabb\Desktop\text.txt
}

GET-CHILDITEM  -recurse C:\Enlistment\DAX62\source\*| SELECT-STRING -pattern "@GLS150005"    >text.txt

Upvotes: 1

Views: 130

Answers (1)

David Brabant
David Brabant

Reputation: 43499

Use Read-Host before calling Get-ChildItem.

$pattern = Read-Host
gci -recurse C:\Enlistment\DAX62\source\*| SELECT-STRING -pattern $pattern >text.txt

Upvotes: 3

Related Questions