Saturday, May 31, 2014

#13 : Find the path of applications with Powershell

There is a Windows command "Where" which tells use the location of executable applications. Such as, if you are looking for location of notepad, you can run :

where Notepad

Output:
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe

This helps you much when there are two versions of same executable and you want to know which will get priority. For example, in the above output, there are two entries for notepad.exe, but when you call notepad without providing full path, it will pick the one located in System32.

The same can be achieved in Powershell with the help of Get-Command cmdlet. This cmdlet will tell you the same output :

get-command notepad

CommandType     Name                                                     Definition
-----------     ----                                                     ----------
Application     notepad.exe                                              C:\Windows\system32\notepad.exe
Application     notepad.exe                                              C:\Windows\notepad.exe
You can adjust the output with format-table cmdlet. Such as, if you want to get output in form of Name and Definition only, you can try below :

get-command notepad | ft name, definition

That's all for today. Hope you liked this article. Thanks for reading!

Thursday, May 22, 2014

#11 : Creating executable (EXE) from Powershell script using PS2EXE?

As you all know that Powershell is .NET Framework based scripting language. When a Powershell script runs, scripting is converted ty MSIL (Microsoft Intermediate Langage) and then executed. In short we can say that Powershell script is not interpreted as Batch programming or Unix-based shell scripting. So, internally a Powershell script is converted to machine language then why there is no in-build compiler for Powershell? This is puzzle to me, but this is how it is. Anyways, when we are talking about scripting language, why to think about compiling script to EXE, if you really want to compile, use C# or VB.NET. But you know what, we always think something which is missing. Overall, there is no executable compilation mechanism provided in Powershell (Period!).

There are some alternatives to compile script to Powershell. One of the tool is PS2EXE. This can be download from CodePlex from below location:

https://gallery.technet.microsoft.com/PS2EXE-Convert-PowerShell-9e4e07f1

This is good utility which creates exe from a ps1 file. Before you get so excited to use it, let me tell you some facts about it:
1. This utility will only encapsulate your script and create exe with that. This is not a compilation of your script. So, you still need to have Powershell installed on the machine where you run.

2. You code is safe and embedded, so nobody can read what you are doing.

You can try it if this meets your requirement. Next time, we will talk about another tool similar to this.

Thank you for reading this article!

Friday, May 9, 2014

#10 : Powershell Editor : PowerShell SE

I found this tool interesting as it give much more with the simple interface. You may download it free from CNET Download as well.

Thursday, May 8, 2014

#9 : Developing Powershell scripts with Notepad++

Not sure how many are using Notepad++ for developing Powershell, but I am using Notepad++ every time I develop. Being Powershell developer, it helps alot due to following reasons: 

1. Syntax highlighting : This is really easy and you can also edit the color code you want. You can download syntax highlighter or you can make your definition. These things are so easy. Just go to style configurator and set the color you want. 

2. Block Collapsing : The + sign to the left of function block or if statement makes code more and more manageable. ALT+1 and ALT+2 can be used for different levels collapse you want. 

3. Freeware : This tool is free and you don't have to convince your manager. Just request to download. You can also find portable version of Notepad++ also.

Please see the download location at - http://notepad-plus-plus.org/

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...