Hey guys, I spent the last hour of the day yesterday creating a powershell script that generates a random, secure 16 character password by pulling random characters from the ascii table between values 35 and 125. I then created a .bat to execute that script, and have set that .bat file to run when a certain autohotkey macro is hit, in my case it’s ctrl+alt+p.
Right now, the script just spits the new password out to a text file, and the .bat opens it after it has run, which is OK for now. But, ideally, what I’d like to have happen is either the .bat or the ps script copy the contents of that text file to the clipboard and then paste it to wherever the cursor lies, or read from the text file and write to where the cursor has focus.
I’ll be using this for some ftp accounts I host, and it would be cool to just have the cursor in the password block, hit ctrl+alt+p and have a randomly generated password pasted there each time.
What is the best way to go about this? I know that you can pipe out to the clipboard with powershell, but haven’t seen a direct method of pulling from the clipboard in powershell. Which is why I was thinking that reading from the text file directly might be a better bet.
Here is what I have so far on the PS side…
$randomObj = New-Object System.Random $NewPassFile = "<FilePath>" $NewPassword="" 1..16 | ForEach { $NewPassword = $NewPassword + [char]$randomObj.next(35,125) } $NewPassword > $NewPassFile $NewPassRead = get-content $NewPassFile $NewPassWrite = write-host $NewpassRead sleep -s 5 Remove-item $NewPassFile
submitted by /u/greatwhitegibby
[link] [comments]
The post Need help with a script – Noobish question appeared first on How to Code .NET.