Avatar of ElegantSolutions
ElegantSolutions
Flag 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?
PowershellVB Script

Avatar of undefined
Last Comment
ElegantSolutions

8/22/2022 - Mon
RobSampson

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
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RobSampson

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.
footech

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ElegantSolutions

ASKER
Footech provided the most thorough  answer with links.

Footech, could you provide a link to your favorite  Logon script example?
footech

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
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ElegantSolutions

ASKER
Yes, Rob Sampson's last post was Very useful so if the moderator would split the points with him, that would be proper.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ElegantSolutions

ASKER
I appreciate both the opinion and the factual links from both authors.