Forum Discussion
Adamzter81
Sep 04, 2020Copper Contributor
Input from a text file and then command
Hello, I am trying to accomplish the following via powershell, any help is appreciated. 1. Open a dialog box to select a text file (list of computernames) 2. Import the selected text file ...
Ionut Lazar
Sep 04, 2020Copper Contributor
Hello Adamzter81,
Personally I would choose to open the file by creating a function and passing the path as an argument or having hard coded in the script, but if you want to have an Open File Dialog to select a file, you can use something like the next code, which is asking you to select a txt file then you can use the property FileName to obtain the path that you want to import in $Computers variable:
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.filter = "TXT (*.txt) | *.txt" $OpenFileDialog.ShowDialog() | Out-Null $Computers = Get-Content $OpenFileDialog.FileName
Once you have all the computers imported in the variable you can play around with them by using foreach looping.
Best regards,
Ionut Lazar