Showing posts with label Vim and PowerShell. Show all posts
Showing posts with label Vim and PowerShell. Show all posts

Friday, May 25, 2012

Sherlock Holmes: Secret of encrypted PowerShell Script files.. Password Protect .PS1 files using VIM.

 

sh_profile7

Hi,

This article is quite off from my regular PowerShell topic, but it's fun doing it .  So the situation is like that, One of my friend wrote a Powershell script but someone he wants to encrypt or password protected so that on one else {his fellow colleagues who just believes in COPYING & PASTING and make no efforts to learning technologies} use it, copy it .

When is asked me this question, i was not sure what to do,,as i always believe is sharing...then VIM come to my mind and in my one previous article i also mentioned about vim in this blog. You can find the article here:

 http://newdelhipowershellusergroup.blogspot.in/2011/11/hi-i-hope-some-of-you-know-about-what.html

Let's start.

so we have a enc.ps1 file in D drive and that file contains a two line script.

25-05-2012 12-24-39

run the script , So all is good... we have a script file and that file is running successfully.

25-05-2012 12-26-16

, I hope that you already have VIM on you laptop if not check my previous article which i mentioned in the beginning of this article.

now just open the enc.ps1 file in vim so that we can check that if file is opening in the vim or not.

25-05-2012 12-30-20

ok, file is opening, now press "ESCAPE" key and type q! in vim. {q means quit}

25-05-2012 12-31-01

now open the file again with -x parameter on vim. {small x not X (as VIM is based on Linux and Linux is case sensitive)}

25-05-2012 12-32-58

Now it ask you to enter a encryption password, provide it .

25-05-2012 12-33-28

Ok type the same password again.

25-05-2012 12-34-21

It open our .PS1 file,, now type,press "Escape" key again., in colon type wq! and press enter {w=write, q=quit}

25-05-2012 12-35-09

okies we are back to our Powershell console.

25-05-2012 12-36-51

Now lets open our enc.Ps1 Powershell script file in notepad.

Ooops,, i don't know this "Alien's" scripting language,, i think we need "Sherlock Holmes" to decode it..

25-05-2012 12-38-35

Mission accomplished :-)

Now whenever you open the same file in VIM it ask you for password first.

25-05-2012 12-41-02

asking for password to open the file.

25-05-2012 12-41-18

and if someone runs it. :)

Damn!!!!! :)

25-05-2012 12-42-30

oh !!!! and how to change or remove password :)

Open the file in VIM , Enter you password to open it . press "ESCAPE" key and type :X {capital } and hit enter.

25-05-2012 12-45-35

if you want to change password provide it , if you want to remove the password, jut keep it blank and press Enter.

25-05-2012 12-45-57

Press Enter again

25-05-2012 12-47-28

now press "Escape" , type wq! {write, quite, forcefully}

25-05-2012 12-47-59

Now we are back in Powershell console. now open the same file in "notepad"

25-05-2012 12-50-04

Wow !! we back from where we start.

I hope that you enjoyed this post.

Thanks

Aman Dhally

Buy-More-Twitter-Followers

00485s99

Wednesday, November 16, 2011

“VIM” a console based Script Editor for PowerShell

 

Hi,

I hope some of you know about what is VIM is and for those who don’t know what VIM is for them “VIM” is console based text editor and it’s very advance text editor. Basically VIM was made for LINUX and it’s come pre-installed in most of the Linux Distributions. Now they also make it compatible with Windows. You can download VIM executable from VIM website or you can download VIM directly from this Download link ftp://ftp.vim.org/pub/vim/pc/vim73_46w32.zip 

Why to use VIM?

hummm.. if you want to do edit PowerShell scripts directly from PowerShell Console or you don’t want to use EDIT command to edit PowerShell Script and want some more advance features then VIM is for you. We will use VIM as console based test Editor.

How to use it?

Download vim  ftp://ftp.vim.org/pub/vim/pc/vim73_46w32.zip  and save it anywhere on your laptop and Extract the .ZIP file.

Vim-0

Now Paste the extracted Vim.exe folder in C:\Windows\System32 so that it automatically added to your environmental path so that we can execute the VIM.exe from anywhere in the console.

Vim-1

Now lets open PowerShell Console and see if we able to run VIM successfully.

Vim-2

It’s Open.. to quit this windows type :q

Vim-3

Now open a PowerShell Script using VIM , Vim  and location of PowerShell Script

Vim-4

Looks good isn’t

Vim-5

Press Escape and type :se nu in vim and hit Enter and Line Number appear in the script :)

Vim-7

to quit the vim without saving the script Press Escape Key and type :q! and hit enter.

To know more about vim see this online documentation : http://vimdoc.sourceforge.net/htmldoc/usr_toc.html 

 

Thanks for reading

 

Aman Dhally