Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Nuke BATCH. Goto PowerShell  (Read 3694 times)

0 Members and 1 Guest are viewing this topic.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Nuke BATCH. Goto PowerShell
« on: November 17, 2011, 09:51:08 PM »
Some newcomers are being told to learn DOS catch programming. Who is doing this? Certainly not Microsoft. One tool in particular is being maintained by Microsoft is PowerShell. New and Intermediate programmers who have some skills should learn to speak a bit of PowerShell.
Quote
Updated: August 18, 2010
Windows Power Shell
Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell™ helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.
Quote
Scripting with Windows PowerShell
Windows PowerShell: Learn It Now Before It's an Emergency
Series: Part 1 of 5
Duration: 55 minutes 36 Seconds
Date: March 28, 2011
Learn the basics of Windows PowerShell from Microsoft Scripting Guy Ed Wilson.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Nuke BATCH. Goto PowerShell
« Reply #1 on: November 17, 2011, 10:04:36 PM »
To be honest, I've never really liked powershell. It's powerful, but in many ways it just feels like a "Bashified" .NET framework.

If I need to script something, I usually use VBScript or JScript using the built-in interpreter; for example, in order to create a proper Console application in VB6, one needs to use the command line LINK.EXE tool to edit the executable so that it is a console program. I made this into a Script because there was some processing that  I didn't want to learn how/remember how to do in Batch.

More recently, now that I'm used to C# and .NET, I've found, interestingly enough, C# itself to be a useful scripting language. I merely needed to create a short wrapper application that used the framework to compile the script given on the command line using an appropriate provider (a more recent change was that it now compiles .vb files as VB.NET code). it "cheats" by building a basic class and main method around the "script" code, depending on the language. If all goes well, it merely uses reflection to acquire a reference to the main() routine and runs it using the rest of the passed arguments. Than I just associate an extension to the script "interpreter" and add a item to the system "PathExt" variable and can run C-Sharp scripts by merely typing their base name and passing along the requisite arguments. It sounds more complicated than it is, the core logic is really only a few lines, the rest is idiot-proofing and error checking and ancillary stuff.

This isn't an "ideal" solution but typically if I'm writing a script it's usually of a throwaway nature or is just a passing whim, and I don't really need to distribute it so the fact that my script wrapper program isn't installed elsewhere isn't an issue. Usually my main concern is what I'm trying to do, and being able to do it in a language I am now quite familiar with makes it that much easier.
I was trying to dereference Null Pointers before it was cool.