Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read values returned from a powershell command in VB.Net

950 views
Skip to first unread message

mjxplant

unread,
Feb 20, 2008, 11:59:02 AM2/20/08
to
I have downloaded and installed the ActiveRoles Management Shell for AD and
one of the command in there is get-qaduser when ran you get the follow output
in powershell


Name Type DN
------ ----- --
Don White user CN=Don White, OU=Employee, DC=Domain,
DC=com

I run the following command and I can invoke the powershell command, but how
would I go about reading the DN that is returned?

<Code>

Sub AD_Powershell(ByVal UserID As String)
Dim myRunspace As Runspace
Dim rsConfig As RunspaceConfiguration
Dim snapInException As PSSnapInException
Dim info As PSSnapInInfo
Dim PSCommand As String

'The following code opens a runspace that has access to the Exchange
Management Shell.
rsConfig = RunspaceConfiguration.Create()
info = rsConfig.AddPSSnapIn("quest.activeroles.admanagement",
snapInException)
myRunspace = RunspaceFactory.CreateRunspace(rsConfig)
myRunspace.Open()

'First, create a new instance of the Pipeline class by using the
runspace that you created.
Dim pipeLine As Pipeline
pipeLine = myRunspace.CreatePipeline()

'Next, create an instance of the Command class by using the name of
the cmdlet that you want to run.
PSCommand = "get-qadUser"
Dim myCommand As New Command(PSCommand)

Dim IDparam As New CommandParameter("Identity", "UserID")
myCommand.Parameters.Add(IDparam)

'Next, add the command to the Commands collection of the pipeline.
pipeLine.Commands.Add(myCommand)


'Now, call the Pipeline.Invoke method to run the command.
Dim commandResults As Collection(Of PSObject)
commandResults = pipeLine.Invoke()

End Sub

Oisin (x0n) Grehan [MVP]

unread,
Feb 20, 2008, 7:04:52 PM2/20/08
to
On Feb 20, 11:59 am, mjxplant <mjxpl...@discussions.microsoft.com>
wrote:

Hi,

If you are expecting just one object back, use:

' get first object in collection
Dim record as PSObject = commandResults(0)

' read the DN property and cast to string
Dim dn as String = DirectCast(record.Properties("DN").Value, String)

Hope this helps,

- Oisin


0 new messages