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