Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, PowerShell, or Other? [closed]

What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.

The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.

We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future.

like image 620
eric.christensen Avatar asked Dec 02 '09 18:12

eric.christensen


People also ask

Is it better to learn PowerShell or Python?

Python is an interpreted high-level programming language whereas PowerShell provides a shell scripting environment for Windows and is a better fit if you choose to automate tasks on the Windows platform.

What is PowerShell Python?

PowerShell is a commandline user interface for Windows that is often used as part of a Python programmer's development environment. PowerShell is an implementation of the shells concept. Learn more in the development environments chapter or view the table of contents for all topics.

What language is closest to PowerShell?

It is part of the . NET framework and typically has C# code underlying its functions, although knowledge of C# is not a prerequisite for learning PowerShell. The closest comparison to the PowerShell language is Perl, which is used in similar scenarios on Linux environments.

How do I stop a Python script from PowerShell?

CTRL + Z, then hit ENTER to exit python from powershell.


2 Answers

Python works as a great, all-purpose tool if you're looking to replace CMD and BAT scripts on your Windows boxes, and can also be written to run scripts on your (L)inux boxes, too. It's a great, flexible language and can handle many tasks you throw at it.

That being said, PowerShell is an amazingly versatile tool for administering all manner of Windows boxes; it has all the power of .NET, with many more interfaces into MS products such as Exchange and Active Directory, which are a timesaver. Depending on your situation, you may get more use of of PS than other scripting languages just because of the interfaces available to MS products, and I know MS seems to have made a commitment to providing those APIs in a lot of products. PowerShell comes installed on all current versions of Windows (Windows 7+, Windows Server 2008+), and is fairly easily installed on older versions.

To address your edit that your scripts will be used to launch other processes, I think in that case either of the tools fit the bill. I would recommend PS if you plan on adding any admin-ish tasks to the scripts rather than just service calls, but if you stick to what you described, Python is good.

like image 198
MattGWagner Avatar answered Oct 01 '22 18:10

MattGWagner


We would like to standardize our scripting and are currently using bat and cmd files as the standard.

It sounds like Windows is your predominate environment.

If so, PowerShell would be much better than Python.

  • PowerShell is included with Windows Server 2008. No need to deploy/install Python runtime on every new server that rolls in.
  • The entire Microsoft server related software (Exchange, Systems Center, etc) is transitioning to PowerShell cmdlets for functionality and extensions
  • 3rd party vendors (e.g. SCOM plugins) will also use PowerShell scripts/cmdlets to expose functionality

I have more experience with Python than PowerShell but the writing is on the wall as far as the Microsoft ecosystem is concerned: go with PowerShell. Otherwise, you'll just be going against the grain and constantly interop-ing between Python and everyone else's cmdlets.

Just because you can code import win32com.client in Python does not put it on equal footing with PowerShell in the Windows environment.

like image 32
JasDev Avatar answered Oct 01 '22 17:10

JasDev