Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to encrypt a text file with PowerShell

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I have written a script that is used for disk cleanup on a file server. The script looks at user shares, checks with AD to see if the account is disabled and if so checks if the user login exists in a text file that indicates who is on litigation hold. If the account is disabled and not on Litigation Hold, the directory is deleted. All of these features are working great.

I am now trying to find a way to encrypt the file and it is driving me nuts. Has anyone had any success with encrypting and decrypting a file?

I tried reading the file with Get-Content and looped through each line and tried to ConvertTo-SecureString and then append that to a new file but that didn't work. Tried downloading a PGP module but that tells me it can't work with the string data. I am at a loss. I would appreciate it if anyone that has pulled this off could point me in the right direction.

Thank you,

Mark
 
Thanks Frederico, I had found that same script and article but couldn't get it to work for my needs. I am able to protect a file, but can't figure out a means to read the encrypted data and unencrypt it in the script without reversing the encryption in the file on disk. The situation requires that the person running the script cannot casually read the contents of the file. I also don't see how you can generate a Key and save it for later use. Any additional pointers you might be able to share?

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top