Link to home
Start Free TrialLog in
Avatar of ElegantSolutions
ElegantSolutionsFlag for United States of America

asked on

VBS vs PoweShell for Logon Scripting

I can't seem to find many examples of PoweShell scripts on EE. MS seems to be pushing PS, do the members of EE think it is worth migrating scripts to PS.

It PS a better future environment or is VBS still the best way to go for the near term? Are there compelling reasons like powerful new features in PS to make it worth the switch?
Avatar of RobSampson
RobSampson
Flag of Australia image

In my opinion, for logon scripts, given that they're relatively simple in their functionality, VBS and Powershell are much the same.  Of course they are different in syntax, but I actually find VBScript a bit simpler for these simple tasks.

In Powershell, you map a drive using:
New-PSDrive –Name "G" –PSProvider FileSystem –Root "\\server\share"

Open in new window


In VBScript, you use this:
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\server\share"

Open in new window


I think Powershell is more suited to more administrative type scripts, that you run from an administrator console to retrieve information.  Powershell if a very efficient way of getting a job done with less code though, and is often less than half of the code of an equivalent VBScript, especially when working with files, active directory objects, and output formatting, as a lot of the operations are performed under hood behind single commands.

For me, I will definitely keep using VBScript for Logon tasks, probably until the Windows Script Host no longer ships with Windows

Rob.
SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great stuff footech. I like that mantra, it's similar to "if it ain't broke, don't fix it". I would re-iterate that, don't rewrite scripts, unless you want to use them as a good learning point, because you know what you should end up with.

Rob.
Yes, rewriting VB scripts can be used as a learning experience.  My approach in that case would be to determine the goals of the VB script, and it's intermediate goals, and then just apply PS techniques to accomplish those goals - rather than doing a line-by-line (or command-by-command) translation.  It's similar to how you might rewrite a script to optimize it - the first time writing a script you might use whatever you could find, then later on, with greater experience, you might examine what you wrote previously and see how you could accomplish the same goal in a much more efficient manner.

One other bit that I would put forward in support of knowing PowerShell is that many (and increasing in number) Microsoft (and even non-Microsoft) products are managed/configured through PS.
Avatar of ElegantSolutions

ASKER

Footech provided the most thorough  answer with links.

Footech, could you provide a link to your favorite  Logon script example?
Though I appreciate the points, I think this should have been a split as Rob Sampson provided some good perspective too.

I really don't have any logon script examples to share.  Any scripts would be dependent on what you want to accomplish, which can vary widely.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, Rob Sampson's last post was Very useful so if the moderator would split the points with him, that would be proper.
I appreciate both the opinion and the factual links from both authors.