header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
awk equivalent
Last Post 07 Jul 2011 07:18 AM by halr9000. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Marcelo CavalcanteUser is Offline
New Member
New Member
Posts:1
Avatar

--
07 Jul 2011 05:18 AM
    Friends,

    In this example:

    get-wmiobject win32_groupuser |where-object { $_.PartComponent -like "*55555555*" }  |select-object __PATH

    Resp:

    \\XYZ\root\cimv2:Win32_GroupUser.Gr...2_Group.Domain=\"XYZ\",Name=\"Administradores\"",
    PartComponent="
    \\\\XYZ\\root\\cimv2:Win32_UserAccount.Domain=\"EMPRESA\",Name=\"55555555\""

    I want to get2values:
    Administradores and 55555555

    How do I get?


    Thanks,


    Marcelo Cavalcante
    Rio de Janeiro - Brazil
    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    07 Jul 2011 07:18 AM
    A few comments. First, WMI queries like this can take a while. It's usually more efficient to perform more specific WMI query, so moving your "*555555*" filter to the Get-WMIObject cmdlet. You can read more about WMI & PowerShell here.

    Second, there's easier ways of working with AD groups. I'd suggest either the Quest cmdlets or the PowerShell V2 Active Directory cmdlets (which require 2008R2 ADWS be setup). Those ship with 2008 R2 or for W7, I think you get them with the RSAT feature.

    Sometimes, you really do need to parse text like you are trying to do. But with PowerShell, you if you can work with objects, you should, because it's always going to be easier. When you really do need to go there, I'd use either the Split operator, or regular expressions with the Match operator. The technique depends on the text and how much time you have. If you know awk, I'm sure you know regex to some extent, so you may want to go that route.
    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer