Forum Discussion
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 into memory
3. Run commands on the text file list ( list of computernames)
Thanks for your help.
- Ionut LazarCopper 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
- ilyas_2018Copper Contributor
seems your trying to run some command in multiple computer at once, it is possible make sure you have full access. Adamzter81