Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Return powershell Function variable back to VBScript

$
0
0

Hey Scripting Guy,

I have a vbscript function that I use to call a Powershell Function. I need to return the powershell output back to the calling vbscript. I've tried different methods but I can only get return codes (either 1 or 0) back to the calling vbscript function and not the string value itself.

Here is the code:

vbscript-

Function GetDomain(ByVal username As String) As String
Dim strCmd, ReturnDomain As String

Dim objshell

strCmd = "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -file c:\temp\Get-Infosec2.ps1" & "'" & username & "'"


Set objshell = CreateObject("Wscript.shell")
ReturnDomain = objshell.Run(strCmd)

GetDomain = ReturnDomain

Set objshell = Nothing
End Function

**********************************

Powershell -

 

FunctionGet-Infosec2{

[cmdletbinding()]


Param(

[parameter()]


[string]$name


)


# Add the Quest ActiveRoles snapin for easier AD management; but first check if it's already loaded.



$SnapIn

="Quest.ActiveRoles.ADManagement"


If

(Get-PSSnapin$SnapIn-ea"silentlycontinue") {

       

write-Host"Quest ActiveRoles plugin already loaded. Continuing ..."


    }

   

elseIf (get-PSSnapin$SnapIn-registered-ea"silentlycontinue") {

       

write-Warning"Quest ActiveRoles plugin registered but not loaded. Loading."


       

Add-PSSnapin$SnapIn


    }

else {

       

write-Host"PS Snapin $SnapInnot found."-foregroundcolorRed


}

Write-host$ldapFilter


$domainname=Get-QADUser-Identity$name-Propertiesdn   -SizeLimit0 |select-objectdn


$newstring=$domainname-split ("DC")

$newstring1=$newstring[0]


$newstring2=$newstring[1]


$domainname=$newstring2.Substring(0,$newstring2.Length-1)

$domainname=$domainname.Substring(1)

  

$domainname


}

 The result that I am trying to achieve is getting the value of $domainname back to the calling vbscript function.

Any Idea what I am doing wrong?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>