Where-Object issues in built-in editor

2 posts · Closed

Keith Guest
9 Aug 2024

You wrote this code for me many years ago, and now I am trying to refine it to search for a specific group that a computer is a member of. I am having issues with the Where-Object.
It works in a PowerShell window, but I cannot figure out what I am missing in the built-in editor.

Const Quote = """"

Dim cmd

cmd = "powershell.exe " & Quote & "Get-ADPrincipalGroupMembership (Get-ADComputer " & Input.Column("OS PC Name") & ") | Select-object name" & quote
Where-Object  (name -like "FM Microsoft Bitlocker") | Sort Name

'Create process object and execute PowerShell
Set proc = Internal.CreateObject("process")
proc.execute(cmd)

'Check process exit code
If proc.ExitCode = 0 Then

  'Traverse output lines
  For Each line in proc.output
    Output.Write Line
  Next
Else
  Output.Write "Exit code " & proc.ExitCode
End If

Thanks

Andrew SoftPerfect
12 Aug 2024

It can be a bit complicated to correctly handle all the nested quotes and redirections when manually constructing a string for execution. Instead, I recommend saving your script as a separate file:

param(
[string]$PcName
)
Get-ADPrincipalGroupMembership (Get-ADComputer $PcName) | Where-Object { $_.Name -like "FM Microsoft Bitlocker" } | Select-Object Name | Sort-Object Name

This script takes a single argument, which is the PC name, and prints out the group memberships. You can then execute this script from VBScript as follows:

cmd = "powershell.exe -ExecutionPolicy Bypass -File C:\path\to\your\script.ps1 -PcName " & Input.Column("OS PC Name")

'Create process object and execute PowerShell
Set proc = Internal.CreateObject("process")
proc.execute(cmd)

'Check process exit code
If proc.ExitCode = 0 Then

  'Traverse output lines
  For Each line in proc.output
    Output.Write Line
  Next
Else
  Output.Write "Exit code " & proc.ExitCode
End If
This topic is closed. It has had no new posts for over a year, so the software versions it talks about may be out of date. Start a new topic in Network Scanner if you have a similar question.