Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


PoSH & VBS working hand in hand

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,64889
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> PoSH & VBS working hand in hand
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 PoSH & VBS working hand in hand - 10/8/2008 5:58:31 AM   
  turranx


Posts: 42
Score: 0
Joined: 2/7/2006
Status: offline
Our environment is migrating from Windows 2000/2003/XP to Windows 2008/Vista.  When you make the jump from any of the older server or desktop OSs to the newer server and desktop OSs (Vista & WS2008), some stuff breaks.  The broken functionality that is causing me a lot of pain is email.  The CDO messaging component that I've relied upon for 5 years is missing from Vista.

This works in 2000/2003/XP but not Vista:

      

This works in Vista because PowerShell is installed in Vista:

      

But can what do you do if you want to keep using the same VB Scripts (because they work) and replace the dead components?  You could try something like this:

      
But the problem with this (above) code is that once your body reaches a certian character limit, the objShell.Run() call fails.  So what else to do?


What about using a file to hold the contents of the body?

      
This works* but relies upon somewhere to write on the file system.  I'd really like to move away from using files to transfer the data between scripting languages.  You'll notice an extra line in the PoSH command.  When 'get-content' reads a file, it doesn't return a string.  It returns an object that contains an array of strings.  These strings were created on Carridge Return / Line Feed markers.  It's the equivalent of 'arrLines = Split(strEmailBody,VBCRLF)' in VBS.  If you pass the PoSH object $msg this array of strings, it fails.  So you have to Join it back together using the PoSH command '[String]::Join()'.

*This doesn't always work. While it does work on my own Vista box, it fails on a co-workers Vista box with a "System cannot find the file specified" error.  I've not yet had the chance to sit down and figure out why the code breaks on his workstation.


What other options do we have?  What about an objShell.Exec() attempt?  To keep it simple, lets not even worry about sending an email.  Lets instead center on getting commands into and out of an objShell.Exec shell object.

      
You can see from my comment in the code above she no-workie.  I have to kill the PowerShell.exe executable in Task Manager before the script will continue.  When it does continue, it obviously errors out since the shell instance running inside objExec is no longer "alive".  If I were to take out the command 'Wscript.echo objStdOut.ReadAll' entierly, it would go on to 'objStdIn.Write("Exit")' and hang again.  I had hoped that with this code I would be able to open a shell, run PoSH inside of it then close it down gracefully.  Unfortunately it hangs like toilet paper on trees in late October.


So this is where I stand: I can use objShell.Run() but don't like having to pass the body of an email from one language to the next through the file system.  Does anyone have any ideas?

_____________________________

Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord
 
 
Post #: 1
 
 RE: PoSH & VBS working hand in hand - 10/8/2008 8:44:47 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
A lot of scripting things change and break in Vista. In some cases you may be better off rewriting scripts that will run on Vista. PowerShell is certainly a viable alternative, but there are many parts you need to get right, in addition to command syntax.  I'd suggest starting from scratch using the PowerShell paradigm, which takes some getting used to coming from the VBScript world.  Is there a particular task you'd like to see done in PowerShell?

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to turranx)
 
 
Post #: 2
 
 RE: PoSH & VBS working hand in hand - 10/8/2008 12:24:18 PM   
  turranx


Posts: 42
Score: 0
Joined: 2/7/2006
Status: offline
quote:

ORIGINAL: SAPIENScripter

I'd suggest starting from scratch using the PowerShell paradigm, which takes some getting used to coming from the VBScript world.  Is there a particular task you'd like to see done in PowerShell?


This email problem is a small component of a much larger script (several thousand lines).  Because my day is full already, the quickest way to meet my goals is to get PoSH working with VBS during this transition period.  Then when I have more time I'll be able to slowly phase out VBS in favor of PoSH.  Starting from scratch is not an option at this moment in time.

See a particular task done in PoSH?  What do you mean?  Like an example of PoSH-only code that works that fits my needs?  Nope, not at this time.  But I do appreciate your time and effort.

_____________________________

Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
http://www.myspace.com/Evil__Overlord

(in reply to SAPIENScripter)
 
 
Post #: 3
 
 RE: PoSH & VBS working hand in hand - 10/8/2008 9:11:54 PM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
Your effort was a little overwhelming and I wasn't sure what you wanted to accomplish. You should be able to write a PowerShell script to do certain tasks and execute from VBS using the Exec or Run method:

powershell -nologo -command "& (c:\scripts\myscript.ps1}"

While you can pass parameters to your script you won't be able to share variables between the two unless you write them to a shared space like the registry or a file. 

From a command prompt type powershell /? to see how you would execute a powershell command or script.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to turranx)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> PoSH & VBS working hand in hand Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts