Get-Content with open file dialog
hello,
is possible browse screen , can select file ?(get-content)
dirk
i have create new script :)
it works powershell -sta
# script ping list of ip addresses # 2013 05 28, version 0.8 # created dirk bremer function get-openfile($initialdirectory) { [system.reflection.assembly]::loadwithpartialname("system.windows.forms") | out-null $openfiledialog = new-object system.windows.forms.openfiledialog $openfiledialog.initialdirectory = $initialdirectory $openfiledialog.filter = "text files (*.txt)|*.txt" $openfiledialog.showdialog() | out-null $openfiledialog.filename $openfiledialog.showhelp = $true } $inputfile = get-openfile function get-savefile($initialdirectory) { [system.reflection.assembly]::loadwithpartialname("system.windows.forms") | out-null $savefiledialog = new-object system.windows.forms.savefiledialog $savefiledialog.initialdirectory = $initialdirectory $savefiledialog.filter = "text files (*.txt)|*.txt" $savefiledialog.showdialog() | out-null $savefiledialog.filename $savefiledialog.showhelp = $true } $outputfile = get-savefile $a = "date ^ computer name ^ hostname ^ ip address ^ online" $a | out-file -enc ascii -width 400 -append $outputfile $computers= gc $inputfile foreach ($computername in $computers) { try { $dns =[system.net.dns]::gethostentry($computername) } catch { "there resolution error: $_ " # in here error.... $dns= "" $hostname = null $ip = null } $hostname = $dns.hostname $ip = $dns.addresslist trap { continue } if (test-connection $computername -erroraction silentlycontinue -count 1 ) { $(get-date -format 'dd-mm-yy hh:mm') + " ^ " + $computername + " ^ " + $hostname + " ^ " + $ip + " ^ " + "online" | out-file -enc ascii -width 400 -append $outputfile} else { $(get-date -format 'dd-mm-yy hh:mm') + " ^ " + $computername + " ^ " + $hostname + " ^ " + $ip + " ^ " + "offline" |out-file -enc ascii -width 400 -append $outputfile } }
dirk
Windows Server > Windows PowerShell
Comments
Post a Comment