header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

change from a switch to a pipeline
Last Post 24 Sep 2008 06:43 PM by halr9000. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Anton1701User is Offline
New Member
New Member
Posts:13
Avatar

--
24 Sep 2008 05:29 PM  

Good morning PSers!

If have this code:

**********StartCode*****************

 

$mytoken = [System.Security.Principal.WindowsIdentity]::GetCurrent()

 

{

 

 

 

{

 

{

 

foreach($g in $mytoken.Groups)$TestG = $g.Translate("System.Security.Principal.NTAccount")switch -regex ($TestG.ToString())"\(\d{5}\)$"$g

 

write-host ($TestG.ToString())

 

}

}

**********************EndCode**************************

I would like to do this with a pipe line.

So I tryed this:

*****************StartCode**************************

 

 

I am Receiving a list of SIDs and not list of group names.

Thoughts?

$mytoken.Groups | Where-Object {$_.Translate("System.Security.Principal.NTAccount").ToString() -match "\(\d{5}\)$"}
*****************EndCode****************************

$mytoken = [System.Security.Principal.WindowsIdentity]::GetCurrent()

}

ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
24 Sep 2008 05:53 PM  

[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups | foreach { $_.Translate([System.Security.Principal.NTAccount]).value }

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:335
Avatar

--
24 Sep 2008 06:43 PM  
Just for the books...I don't recall the last time I used to use the toString() method of an object to make something work.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer