Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Powershell scrip to run from VBScript

Status
Not open for further replies.

LoneWolfProgrammer

Programmer
Mar 12, 2010
1
US
Here is my Call to my powershell:

strSrvInfoCommand = "powershell.exe -noprofile -command c:\powershell\ReturnTimeDate.ps1 " & strServer
Set oShellExec = oShell.Exec(strSrvInfoCommand)
Set oStdOut = oShellExec.StdOut
Set oStdErr = oShellExec.StdErr
strResults = oStdOut.ReadAll
strErrors = oStdErr.ReadAll

This code doesn't seem to run the PS script. And the VBScript that makes this call hangs. If I run the resulting Powershell the same way from the commandline, it works great.

Any ideas?

Here is the PS code:

If ($args.length -gt 0)
{
$computer = $args[0]
$namespace = "root\CIMV2"
$results = Get-WmiObject -class Win32_LocalTime -computername $computer -namespace $namespace

if ($results -eq $())
{
exit 1
}

if ($results.Month -lt 10)
{
$month = "0" + $results.Month.ToString()
}
else
{
$month = $results.Month.ToString()
}

if ($results.Day -lt 10)
{
$day = "0" + $results.Day.ToString()
}
else
{
$day = $results.Day.ToString()
}

if ($results.Hour -lt 10)
{
$hour = "0" + $results.Hour.ToString()
}
else
{
$hour = $results.Hour.ToString()
}

if ($results.Minute -lt 10)
{
$minute = "0" + $results.Minute.ToString()
}
else
{
$minute = $results.Minute.ToString()
}

if ($results.Second -lt 10)
{
$second = "0" + $results.Second.ToString()
}
else
{
$second = $results.Second.ToString()
}

$output = $month + "/" + $day + "/" + $results.Year.ToString() + " " + $hour + ":" + $minute + ":" + $second

$output | Out-File "C:\emc\logs\serververification\tempdate.txt"
exit 0
}
else
{
Write-Host "No name provided!"
exit 1
}
exit 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top