Regular expression to remove SIDs from list

Hey everyone so I have a script and in it I try to find the current user, as well as the last user. Currently I'm using a regular expression to throw the System account SIDs and other things like that out of the list. However this doesn't seem to be taking
SQL SIDs out of my list ie. ReportServer$LOCAL with the SID S-1-5-80-4264962431-3932693095-1576469926-235475122-2208986020
What's the best way to get only user SIDs?
Here's what I have so far:
$Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Computer
$Win32User = $Win32User | Where-Object {($_.SID -notmatch "^S-1-5-\d[18|19|20]$")}
$Win32User = $Win32User | Sort-Object -Property LastUseTime -Descending
$LastUser = $Win32User | Select-Object -First 1
When I can this it breaks since there is no actual user tied to this SID:
$UserSID = New-Object System.Security.Principal.SecurityIdentifier($LastUser.SID)
$User = $UserSID.Translate([System.Security.Principal.NTAccount])
Thanks for any help!!

Start cmd.exe as your domain user and run whoami /user to get your own SID. You will get something like this:
USER INFORMATION
User Name SID
========================= =============================================
DEMOSYSTEM\CustomAccount1 S-1-5-21-3419697060-3810377854-678604692-1000
The last part of the SID, in this case 1000, is called RID. When you create a new user or computer object in your domain, only the RID will be different from your own SID. The RID starts on 1000 and increments as you create new objects.
If you are only interested in user accounts from the same domain as your user, you can use a regex like this, only based on your own SID:
$_.SID -match '^S-1-5-21-3419697060-3810377854-678604692-[\d]{4,10}$'

Similar Messages

  • Using Regular Expressions To Remove Characters JDK 1.4

    I want to write a regular expression to remove all commas in a string of text.
    string is:
    1,000
    or 1,000,000
    I want it to return 1000 and 1000000.
    I have tried some but I am just starting with Regular Expressions.
    Please Help!

    Try this tutorial: Linux : Education : Tutorials
    Using regular expressions
    David Mertz
    President, Gnosis Software, Inc.
    September 2000
    http://www-105.ibm.com/developerworks/education.nsf/linux-onlinecourse-bytitle/6C2B4863702F592B8625696200589C5B?OpenDocument

  • Regular Expression to remove space in HTML Tag

    Hello All,
    My HTML string is like below.
    select '<CityName>RICHMOND</CityName> 
    <StateCd>ABCD CDE 
    <StateCd/>
    <CtryCd>CAN</CtryCd>
    <CtrySubDivCd>BC</CtrySubDivCd>' Str from dual
    Desired Output is
    <CityName>RICHMOND</CityName><StateCd>ABCD CDE 
    <StateCd/><CtryCd>CAN</CtryCd><CtrySubDivCd>BC</CtrySubDivCd>
    i.e. want to remove those spaces from tag value area having only spaces otherwise leave as it is. Please help to implement the same using Regular expression.

    Hi,
    It's unclear what you want.  This site seems to be formatting your message in some odd way.
    Post a statement like
    SELECT '...' FROM dual;
    without any formatting, to show your input, and post the exact output you want friom that, with as little formatting as possible.  It might help if you use some character like ~ instead of spaces (just for posting; we'll find a solution that works for spaces).
    To remove the text that consists of spaces and nothing else between the tags, you can say
    REGEXP_REPLACE ( str
                   , '> +<'
                   , '><'
    How is this string being generated?  Maybe there's some easier, more efficient way to keep the bad sub-wrtings out of the string in the first place.

  • Regular Expression for Removing a space after the a... tag?

    Hi there,
    I'm fairly new to using Regular Expressions, but am in need of one that will help me find all <a...> tags that have a space immediately following that tag and replace it with the exact same tag, but no space following the <a...> tag.
    So, for example, a regular expression that will find:
    <a href="somelink.html"> Somelink</a>
    as well as:
    <a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('sub-nav_button_professional_portal','','images/sub-nav_button_ professional_portal_f2.png',1)"> Somelink</a>
    And just remove the space appearing as part of the hyperlink.  Does anyone know how to accomplish this?

    Thought of that, but it would remove spaces from crucial areas of my pages.  For example, conditional logic within a script, like:
    for (i = 0; i > (a.length - 2); i += 3)
    would become:
    for (i = 0; i >(a.length - 2); i += 3)
    While that wouldn't pose a huge problem, I'm messing up the syntax in order to fix something else, which is why I wanted to go the route of a regular expression.  I need to replace all "<a ...> " (space included) tags with "<a ...>" and make sure that the properties within the <a> tag stay in tact.

  • How can i remove items from list that have been deleted when i click on them it keeps showing empty

    how can i remove items from the list that have been deleted when i click on them it keeps showing folder empty

    Actually, Reader SHOULD keep showing documents that no longer exist, I disagree. It's no big deal, and people will quickly realise why they can't open the file. They open more files, the old ones move off.
    The REASON why it should not check is that checking whether a file exists can take a long time when things aren't good. For instance if a file server goes down, or a memory card is unplugged. That in turn would mean delays opening the File menu, and I've seen some software that can sit there for several minutes. That would really give people something of which to complain...

  • UnsupportedOperationException Error while removing object from List

    Hi,
    I need to remove a set of objects from List if it contains similar objects as the other one.
    Follwing is the code snippet of the above scenario...
    List selectedPaxList = new ArrayList();
    TreeSet seatAssignedPaxlist= new TreeSet();
    selectedPaxList.add("1");
    selectedPaxList.add("2");
    selectedPaxList.add("3");
    seatAssignedPaxlist.add("1");
    seatAssignedPaxlist.add("2");
    if(selectedPaxList.containsAll(seatAssignedPaxlist))
    selectedPaxList.removeAll(seatAssignedPaxlist);
    If i do this in java program it executes fine without any error.But if I do the same in JSP I am getting the following error......
    java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:167)
    at java.util.AbstractList$Itr.remove(AbstractList.java:432)
    at java.util.AbstractCollection.removeAll(AbstractCollection.java:351)
    Plz... help me to resolve the issue

    java.lang.UnsupportedOperationException
    at
    java.util.AbstractList.remove(AbstractList.java:167)
    at
    java.util.AbstractList$Itr.remove(AbstractList.java:43
    2)
    at
    java.util.AbstractCollection.removeAll(AbstractCollect
    ion.java:351)
    That stack trace looks wrong to me.
    ArrayList overrides the remove method, so it
    shouldn't be using the method in AbstractList. That's what I thought, too. There is either something missing or it's not an ArrayList. In fact the javadoc of AbstractList.remove sais:
    "This implementation always throws an UnsupportedOperationException."
    So it really looks like another subclass is used.
    Also
    the object it is trying to remove is a list (from
    your exmaple it should be a String)
    I could be wrong.These are just the code references not the parameters, I think.
    -Puce

  • JList run time errors when removing items from list

    Hi there
    I am having trouble removing items from a JList. For a While it was working fine and now it outputs runtime errors everytime samething gets removed from the lsit
    Here is the code
    //declare
    public class Consumertab1gui extends JPanel implements ActionListener
         public static JList conList = null;
         private static DefaultListModel model = null;
    // Create a list with some items
    model = new DefaultListModel();
    conList = new JList(model);
    //set the size of cells in the list with the length of the string
    conList.setPrototypeCellValue("Lenght 1234567890");
    conList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    conList.addListSelectionListener(new ValueReporter());
    //set a scroll onto the list
    JScrollPane conScroll = new JScrollPane(conList);
    add(conScroll,c);
    //when the button gets pressed to drop the selected item the following code is called
    private void dropConsumer()
    int selItem=0;
    componentsV.comVRemove(conList.getSelectedValue().toString());
    selItem=conList.getSelectedIndex();
    System.out.println("No:"+(model.getSize()-1));
    System.out.println("S:"+selItem);
    remConList(selItem);
    dropCon.setEnabled(false);
    //which in turns calls this
    public void remConList(int pos)
         model.remove(pos);
    when the model.remove(pos) code is executed the following runtime errors are given:
    java.lang.NullPointerException
    at Consumertab1gui$ValueReporter.valueChanged(Consumertab1gui.java:197)
    at javax.swing.JList.fireSelectionValueChanged(JList.java:1321)
    at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1335)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214)
    at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:546)
    at javax.swing.plaf.basic.BasicListUI$ListDataHandler.intervalRemoved(BasicListUI.java:1561)
    at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:160)
    at javax.swing.DefaultListModel.remove(DefaultListModel.java:478)
    at Consumertab1gui.remConList(Consumertab1gui.java:38)
    at Consumertab1gui.dropConsumer(Consumertab1gui.java:58)
    at Consumertab1gui.actionPerformed(Consumertab1gui.java:46)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5100)
    at java.awt.Component.processEvent(Component.java:4897)
    at java.awt.Container.processEvent(Container.java:1569)
    at java.awt.Component.dispatchEventImpl(Component.java:3615)
    at java.awt.Container.dispatchEventImpl(Container.java:1627)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
    at java.awt.Container.dispatchEventImpl(Container.java:1613)
    at java.awt.Window.dispatchEventImpl(Window.java:1606)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    can anyone spot any mistakes in the code or suggest possible resons as to why these run time errors occur?
    Thanks
    alexis

    java.lang.NullPointerException
    at Consumertab1gui$ValueReporter.valueChanged(Consumertab1gui.java:197)The NullPointerException occurs at line 197, in the valueChanged method of your ValueReporter inner class. I have looked through your post several times but I don't see where you posted that method. Anyway, that is where you should look.
    PC&#178;

  • Removing dups from list

    Hello
    i am removing dups from a list by overwriting the equals method of the class. The equals method is checking for only one attribute...but i want to have another list with different elements from the list (another attribute)
    class C has two main attributes, Color and Size. I want to have a list with different colors and another list with different sizes.
    class C equals method:
    public boolean equals(Object obj) {
         C drt = (C) obj;
         boolean bRet;
         if (drt.getColor().equals(this.getColor()) {
              bRet = true;
         else {
              bRet = false;
         return bRet;
    }adding to list A
    ListIterator li  = B.listIterator();
    while (li.hasNext())
    C celement = (C) li.next();
    if (!A.equals(celement))
       A.add(celement);
    }at this point list A consists of different (by color) celements. But what if i want to have another list to have different (by size) celements...?

    The obvious way of getting a collection of distinct things is to use a Set. However you can't have multiple "equals()" methods. There is no inbuilt "Equivalator" analogous to a Comparator.
    At the moment you are comparing a list with an element which can't be good.
    One way or another you have to compare each thing with the list so far to see if it should be added. Maybe something like:import java.util.ArrayList;
    import java.util.List;
    public class Thing {
        private String color;
        private String size;
        public Thing(String color, String size) {
            this.color = color;
            this.size = size;
        public String getColor() {
            return color;
        public String getSize() {
            return size;
        public String toString() {
            return "[" + color + "," + size + "]";
        public static void main(String[] args) {
            List<Thing> theThings = new ArrayList<Thing>();
            theThings.add(new Thing("a", "1"));
            theThings.add(new Thing("b", "1"));
            theThings.add(new Thing("a", "2"));
            theThings.add(new Thing("b", "2"));
            theThings.add(new Thing("c", "3"));
            theThings.add(new Thing("d", "1"));
            List<Thing> colorList = new ArrayList<Thing>();
            List<Thing> sizeList = new ArrayList<Thing>();
            for(Thing thing :theThings) {
                    // look for a color match
                boolean found = false;
                for(Thing test :colorList) {
                    if(test.getColor().equals(thing.getColor())) {
                        found = true;
                        break;
                if(!found) colorList.add(thing);
                    // look for a size match
                found = false;
                for(Thing test :sizeList) {
                    if(test.getSize().equals(thing.getSize())) {
                        found = true;
                        break;
                if(!found) sizeList.add(thing);
            System.out.println("Color list: " + colorList);
            System.out.println("Size list: " + sizeList);
    }

  • Help reordering or removing apps from list

    How can you reorder or remove apps from the list of apps you get to if you swipe to the left of The Hub? I can remove the apps from displaying messages in The Hub, but cannot reorder or removed(hide) them from the list ? It is hard to keep prying eyes from private emails, texts, bbms, with these quick links as is.

    You cannot "hide" apps that appear in the Hub, but you can eliminate the from being displayed in the Hub (and put them back later).
    Open the Hub with the swipe right, then select the three dots in the lower righthand corner. Choose Settings > Hub Management and turn off whatever you don't want to see displayed in the Hub. Just turn 'em back on later when you feel like it. 
    It won't stop prying eyes from simply opening BBM or Test Messages, but at least they won't be on display in the Hub when you're trying to demo the device. 

  • Regular expression to extract value from xml

    Hi,
    I need to extract the value of an XML tag.
    <purchaseId>Best-200423</purchaseId>
    The result of the expression should be: "Best-200423".
    Something like this ([^\\<purchaseId\\>]*[^\\</purchaseId\\>]) does not work.
    Does somebody has a soltuion?
    I can't get it to work! I want to use the Java Regular Expression functionality.
    Best wishes
    Jochen

    You got lucky, is all. Try changing "Best" to "pest" in your example and it won't work. The square brackets are spurious, and you want m.getGroup(1) to get the stuff that matches the () group.
    Square brackes mean "match any of the characters in the brackets". [^ means "match any character not in this list").                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Regular Expression To Remove Leading While Space

    Hii
    I have a data like this
    20200 Kuala Terengganu
    Terengganu
    Luala Terengganu
    I want to remove the Leading white space in the Second line .Can anybody help me to
    write regular expression for this?
    I want my result like the following :
    20200 Kuala Terengganu
    Terengganu
    Luala Terengganu
    Thanks In Advance
    Jim John

    But there's no difference between two group of lines which you posted. Could you please format your input and desired output with please?
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SDK J2 EE server remove it from list of programs which start with windows

    Hello there
    Since SDK J2EE 5 server takes many resources, I would like to be able to remove it from the list of programs which start with Windows XP PRO start up.
    How could I possibly do that?
    Thanks in advance

    Since SDK J2EE 5 server takes many resources,is it take more resource ?
    is it decrease your speed ?
    is it not allow another app or software to run ?
    if you say yes,
    then
    type msconfig in start->run
    click startup tab and deselect the corresponding checkbox
    or
    go to control panel -> administrator tools -> services -> select the service , then right click properties and select disable in drop down,
    or
    control panel -> add or remove programs -> select j2ee-xxx remove it

  • Regular expression - get longest number from string

    I believe it is easy one but I can't get it.Lets say I have a string 'A1_1000' I want to substract the 1000 using regular expression. When I feed Match regular expression I get '1' which is not the longest number. I know other ways of doing that but I want clean solution in one step. Does anybody knows the right regular expression to accomplish that? Thanks!
    LV 2011, Win7
    Solved!
    Go to Solution.

    ceties wrote:
    This is the best solution I was able to come with. I am just wondering if there is "smoother way" without the cycle.
    Since multiple checks are required I would tend to beieve that we do have to loop through the possibilities. in this example
    I start check at offset "0" into the string for a number. Provided i find a number I check if it is longer that any previous number I found and if so save the new longer number in the shift register.
    Have fun!
    Ben
    Message Edited by Ben on 04-15-2009 09:23 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Find_Longest.PNG ‏33 KB

  • Regular Expression for multiline response from a device

    Hi,
    I am trying to have a regular expression in java for a response (example response is )
    Freq Table Info:
    # freqs = 12
    # trackers = 1 (LF), 1 (HF)
    fmin = 300000 Hz
    fsplit = 7000000 Hz
    fmax = 150000000 Hz
    updates = 1
    Freq Table:
    Slot | Mode | Description
    -----|------|---------------------------------------------------------
    0 | FUND | 400000 ( 400000
    1 | FUND | 13560000 ( 13560000) Hz, tracking = True
    Need to match this response and extract 400000 and 1356000 , stuck at mot being able to match the response. I tried [\\w]+[\\W]+ as well as \\w , dont think they work well enough, also tried testing on http://www.iowacomputergurus.com/free-products/regular-expression-tester.aspx, dont think am on the money yet. Can somebody please give any pointers or suggestions.
    Thanks for your time.

    PaddyK54 wrote:
    Hi,
    I am trying to have a regular expression in java for a response (example response is )
    Freq Table Info:               
    # freqs    =  12                
    # trackers =   1 (LF),   1 (HF)                               
    fmin       =     300000 Hz                          
    fsplit     =    7000000 Hz                          
    fmax       =  150000000 Hz                          
    updates    =          1                       
    Freq Table:          
    Slot | Mode | Description                         
    -----|------|---------------------------------------------------------                                                                      
    0  | FUND |     400000 (    400000                                  
    1  | FUND |   13560000 (  13560000) Hz, tracking = True       Need to match this response and extract 400000 and 1356000 , Well, given that input, your matches both are:
    - made of two or more digits,
    - followed by one or more spaces,
    - followed by an opening parentheses.
    So the regex \d{2,}(?=\s+\()would uniquely identify 400000 and 1356000 (with the example input you posted, which I know little about!). For all I know, other input may have opening parenthesis on other location in your string, which will break the regex.
    For example, what if the following line occurs in your input:
    # trackers = 123456 (LF), 1 (HF)
    You see how that breaks my suggested regex?

  • Open with.....removing apps from list?

    When I right-click and choose 'open with' on a picture for example, I get a huge great list of pre-sets to change the file too. Some of the icons/formats I don't recognise but I think they are a combination of Photoshop, and Flash, Fireworks etc file conversions.
    Is there anyway to remove these presets from the 'open with' list of apps? I've looked at Onyx to clear launcher options but this made no difference? Or does it have to be done in each application somehow?
    Cheers

    Solved this one myself eventually!
    It seems that if you have photoshop it creates a folder in the application folder called 'droplets'. These are shortcut links to the 'open with' menu. So if you have these shortcut options and want rid of them - then trash the droplets folder.

Maybe you are looking for

  • 9IAS error when updating or Deleting the DAD

    Hello, I am getting the following error when ever i am updating or deleting the DAD Changes not applied : Instance not found for fqn et="system";ei="0",et="DADList";ei="45",et="StandardDAD";ei="64 Any suggestions, Thanks, Sudheer

  • How do I install Adobe PageMaker 6.5 on Windows 7

    I recently upgraded from Vista to Windows 7 and can't get my PageMaker to install. I realize it's an obsolete program but I have my business cards and other inportant items in that program. I would not mind upgrading to something newer in Adobe as lo

  • Help !!  its urgent !!! HTTPS to HTTP switching in weblogic App server !!

    Hi, I am using servlets in Weblogic Server environemt. My client (browser based) switches from HTTPS to HTTP and vice versa while accessing different servlets. In IE application works fine but when using Netscape it fails in many parts . I have read

  • TS1702 How to cancel the auto renewal subscription for Australia Women Weekly

    I purchased Australia women weekly 6 month subscription before, and now I want to cancel it. Itune auto renewed my subscription for another 6 month laterly.How can I cancel the auto renew now?

  • Mobile viewing options?

    Hi just wondering how your pdf sharing works with mobile devices, in particular, when viewing with a mobile browser after clicking an adobe send link... such as what happens if the mobile device has a mobile pdf reader installed...or doesn't have one