Securely store your password for your Powershell scrypt

Hello,

Security is something not that easy to put in place when your are scripting. Many people store sensitive data into their script and that can lead to a serious treat.

Powershell can be really handy as its possible to encrypt some string to make them “encrypted”. Its not perfect but atleast with some basic rules it can protect your precious password.

Why it is no perfect? because it will only make you password unreadable. anyone that can access the file can use it! its not a big probleme if you store the file in a folder that only your user can access.

Also, please note that if your server restart, you will need to regenerate the protected password again

Now, lets script!

 

This part of script will allow you to encrypt a String.

 

To use it again later just do a:

 

Simple script to syncronize folders using powershell and winscp

hello,

here is a simple script that will allow you to sync 2 distant folders.

for this script to work you will need to Winsc Automation tools download http://winscp.net/eng/docs/scripting

First lets load the assembly:

 

 

when you have loaded the assembly, you will need to configure your connection information :

 

You can get the server Fingerprint in Winscp under the session > information about server/protocol.

now let start the easy part and prepare the destination and origin folder:

Your script is almost done! Now we will prepare the Session handler part

Lets connect and start the transfert!

And this last part will handle error (because you want to know when your script fail!

 

 

Thanks to Winscp forum who helped me alot with this :)