List Local Group members with PowerShell 5

This script:
$Server="."
$LocalGroup = "Administrators"
$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"
$Members = @($Group.psbase.Invoke("Members"))
$Members | ForEach-Object {
    $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
works fine in powershell 2 (windows 7), but fails on powershell 5
"Error while invoking GetType. Could not find member."
It returns only domain groups. No local groups or local users or domain users.
Is there a reason why? And can it be modified for powershell 5?
Thanks

Try it like this:
$group=[ADSI]"WinNT://$env:COMPUTERNAME/Administrators,group"
$group.Members() |
ForEach-Object {
($_.GetType()).InvokeMember('Name', 'GetProperty', $null, $_, $null)
¯\_(ツ)_/¯

Similar Messages

  • Query the Local Computer Policy with PowerShell

    One of our applications requires some local computer policy settings for some services accounts and we wanted to be able to query these values with a Remote PowerShell window. 
    I was unable to find the registry keys that hold the Local Computer Policy and I also tried activating and importing the import-module grouppolicy but couldn’t figure out how to query the local policy. 
    Below are the values I am interested in seeing:  I also tried the posting here which was most like what I was looking for but no luck.
    SeAssignPrimaryTokenPrivilege(Replace a process-level token)
    SeImpersonatePrivilege (Impersonate a client after authentication)
    SeServiceLogonRight (Log on as a service)
    SeIncreaseQuotaPrivilege (Adjust memory quotas for a process)
    SeBatchLogonRight (logon as a batch job)
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/9fac4ebd-ab68-4ee9-8d5a-44413f08530e/wmi-query-for-user-rights-assignment-local-computer-policy?forum=ITCG
    Thanks,
    Chris
    Chris J.

    The local GPO is a bit tricky.  Administrative Templates go into a registry.pol file, but for the rest of the settings you see in the local GPO, they're just configured on the computer (generally in the registry somewhere.)  If you change, for
    example, the user rights assignments with ntrights.exe, you'll see those changes reflected in the local Group Policy object as well.  This different from domain GPOs, where there's an INF file that contains all the settings that aren't part of an administrative
    template registry.pol file.
    Regarding user rights assignments, there's no quick and easy way to get at this information that I'm aware of.  NTRights.exe makes it easy to change user rights assignments, but doesn't offer functionality to query the existing settings.  For that,
    you need to use the Win32 API function
    LsaEnumerateAccountsWithUserRight.  This can be done from PowerShell, but it involves some embedded C# code that uses P/Invoke... it's about the most complicated type of code you're likely to encounter in a PowerShell script.
    I tinkered around with this recently, and this code seems to work (though it's a little on the ugly side):
    # All of this C# code is used to call the Win32 API function we need, and deal with its output.
    $csharp = @'
    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Principal;
    using System.ComponentModel;
    namespace LsaSecurity
    using LSA_HANDLE = IntPtr;
    [StructLayout(LayoutKind.Sequential)]
    public struct LSA_OBJECT_ATTRIBUTES
    public int Length;
    public IntPtr RootDirectory;
    public IntPtr ObjectName;
    public int Attributes;
    public IntPtr SecurityDescriptor;
    public IntPtr SecurityQualityOfService;
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct LSA_UNICODE_STRING
    public ushort Length;
    public ushort MaximumLength;
    [MarshalAs(UnmanagedType.LPWStr)]
    public string Buffer;
    [StructLayout(LayoutKind.Sequential)]
    public struct LSA_ENUMERATION_INFORMATION
    public IntPtr PSid;
    sealed public class Win32Sec
    [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true),
    SuppressUnmanagedCodeSecurityAttribute]
    public static extern uint LsaOpenPolicy(LSA_UNICODE_STRING[] SystemName,
    ref LSA_OBJECT_ATTRIBUTES ObjectAttributes,
    int AccessMask,
    out IntPtr PolicyHandle);
    [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true),
    SuppressUnmanagedCodeSecurityAttribute]
    public static extern uint LsaEnumerateAccountsWithUserRight(LSA_HANDLE PolicyHandle,
    LSA_UNICODE_STRING[] UserRights,
    out IntPtr EnumerationBuffer,
    out int CountReturned);
    [DllImport("advapi32")]
    public static extern int LsaNtStatusToWinError(int NTSTATUS);
    [DllImport("advapi32")]
    public static extern int LsaClose(IntPtr PolicyHandle);
    [DllImport("advapi32")]
    public static extern int LsaFreeMemory(IntPtr Buffer);
    public class LsaWrapper : IDisposable
    public enum Access : int
    POLICY_READ = 0x20006,
    POLICY_ALL_ACCESS = 0x00F0FFF,
    POLICY_EXECUTE = 0X20801,
    POLICY_WRITE = 0X207F8
    const uint STATUS_ACCESS_DENIED = 0xc0000022;
    const uint STATUS_INSUFFICIENT_RESOURCES = 0xc000009a;
    const uint STATUS_NO_MEMORY = 0xc0000017;
    const uint STATUS_NO_MORE_ENTRIES = 0xc000001A;
    IntPtr lsaHandle;
    public LsaWrapper()
    : this(null)
    // local system if systemName is null
    public LsaWrapper(string systemName)
    LSA_OBJECT_ATTRIBUTES lsaAttr;
    lsaAttr.RootDirectory = IntPtr.Zero;
    lsaAttr.ObjectName = IntPtr.Zero;
    lsaAttr.Attributes = 0;
    lsaAttr.SecurityDescriptor = IntPtr.Zero;
    lsaAttr.SecurityQualityOfService = IntPtr.Zero;
    lsaAttr.Length = Marshal.SizeOf(typeof(LSA_OBJECT_ATTRIBUTES));
    lsaHandle = IntPtr.Zero;
    LSA_UNICODE_STRING[] system = null;
    if (systemName != null)
    system = new LSA_UNICODE_STRING[1];
    system[0] = InitLsaString(systemName);
    uint ret = Win32Sec.LsaOpenPolicy(system, ref lsaAttr,
    (int)Access.POLICY_ALL_ACCESS,
    out lsaHandle);
    if (ret == 0) { return; }
    if (ret == STATUS_ACCESS_DENIED)
    throw new UnauthorizedAccessException();
    if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY))
    throw new OutOfMemoryException();
    throw new Win32Exception(Win32Sec.LsaNtStatusToWinError((int)ret));
    public SecurityIdentifier[] ReadPrivilege(string privilege)
    LSA_UNICODE_STRING[] privileges = new LSA_UNICODE_STRING[1];
    privileges[0] = InitLsaString(privilege);
    IntPtr buffer;
    int count = 0;
    uint ret = Win32Sec.LsaEnumerateAccountsWithUserRight(lsaHandle, privileges, out buffer, out count);
    if (ret == 0)
    SecurityIdentifier[] sids = new SecurityIdentifier[count];
    for (int i = 0, elemOffs = (int)buffer; i < count; i++)
    LSA_ENUMERATION_INFORMATION lsaInfo = (LSA_ENUMERATION_INFORMATION)Marshal.PtrToStructure(
    (IntPtr)elemOffs, typeof(LSA_ENUMERATION_INFORMATION));
    sids[i] = new SecurityIdentifier(lsaInfo.PSid);
    elemOffs += Marshal.SizeOf(typeof(LSA_ENUMERATION_INFORMATION));
    return sids;
    if (ret == STATUS_ACCESS_DENIED)
    throw new UnauthorizedAccessException();
    if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY))
    throw new OutOfMemoryException();
    throw new Win32Exception(Win32Sec.LsaNtStatusToWinError((int)ret));
    public void Dispose()
    if (lsaHandle != IntPtr.Zero)
    Win32Sec.LsaClose(lsaHandle);
    lsaHandle = IntPtr.Zero;
    GC.SuppressFinalize(this);
    ~LsaWrapper()
    Dispose();
    public static LSA_UNICODE_STRING InitLsaString(string s)
    // Unicode strings max. 32KB
    if (s.Length > 0x7ffe)
    throw new ArgumentException("String too long");
    LSA_UNICODE_STRING lus = new LSA_UNICODE_STRING();
    lus.Buffer = s;
    lus.Length = (ushort)(s.Length * sizeof(char));
    lus.MaximumLength = (ushort)(lus.Length + sizeof(char));
    return lus;
    Add-Type -TypeDefinition $csharp
    # Here's the code that uses the C# classes we've added.
    $lsa = New-Object LsaSecurity.LsaWrapper
    $sids = $lsa.ReadPrivilege('SeInteractiveLogonRight')
    # ReadPrivilege() returns an array of [SecurityIdentifier] objects. We'll try to translate them into a more human-friendly
    # NTAccount object here (which will give us a Domain\User string), and output the value whether the translation succeeds or not.
    foreach ($sid in $sids)
    try
    $sid.Translate([System.Security.Principal.NTAccount]).Value
    catch
    $sid.Value
    You do need to know the proper string for each user right, and they are case sensitive. 
    Edit:  You can get a list of right / privilege names from
    https://support.microsoft.com/kb/315276?wa=wsignin1.0 ; they're the same values used for NTRights.exe.

  • Powershell script to Get members of AD group members with first, last, email address

    I'm running a powershell script to retrieve AD users from a specific AD group and pipe specific attributes to a csv file. The script is working perfectly except for one detail. I want the script to ignore any users who have a null value in any of the values
    I'm piping to the spreadsheet. Meaning that if any of the users found in the queried groups have a null value in the attributes givenname, sn or mail, ignore the user and do not pipe to the csv.
    Get-ADGroupMember -identity adgroup -recursive | get-adobject -Properties givenname,sn,mail | select givenname,sn,mail |export-csv -path c:\powershell\groupmembers.csv
    –NoTypeInformation

    Hi,
    You can pipe your user objects through ForEach-Object and then use if to verify all three properties exist. If so, output the object. If not, move to the next object. After you've processed all user objects, then pipe into Export-Csv.
    EDIT: See below.
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • Convergence group members for invitations

    Dear all,
    we use Convergence with latest patch level. For invitations of groups and using check availability the group members are not resolved and therefore the busy/free time of group members is not displayed. Instead the group name is displayed but the group itself have not calendar.
    Is there any possibility - maybe in the config of convergence of ldap settings groups - that the individual calendars of the invited group members with showing free/busy time show up and in consequence the auto select time will work, too.
    The invitation of the group members itself works fine.
    Thanks for any help

    How are the group members defined in the LDAP entry for the group?
    With the assumption that you are using Calendar 7 with Convergence, the Calendar configuration considers the following attributes for members in an LDAP group:
    <tt>
    davcore.ldapattr.dngroupmember=uniquemember
    davcore.ldapattr.urlgroupmember=memberurl
    davcore.ldapattr.mailgroupmember=mgrprfc822mailmember
    </tt>
    Only <tt>uniqueMember</tt> is considered for ACL checking, along with invitation and free/busy scheduling.
    The <tt>mgrprfc822mailmember</tt> attribute is taken into account only when inviting the group.
    This is because, when doing the ACL check, we are relying on the LDAP Directory to provide us with the <tt>isMemberOf</tt> attribute directly on the logged in user LDAP entry (as opposed to looking at all the members of the group). The <tt>isMemberOf</tt> operational attribute is itself derived from the <tt>uniqueMember</tt> attribute only.
    Doing a group expansion for ACL purposes would be too expensive an operation.
    As a side note, we also check for dynamic group membership through the <tt>memberurl</tt> LDAP attribute of the group, both for scheduling and ACL purposes.
    Reference KM Doc:
    Calendar 7: Allowing Members Of A Migrated LDAP Group To Subscribe To Calendars (Doc ID 1483916.1)
    -Deb

  • How can I use PowerShell 3.0 cmdlets or script to list all the local groups and local users of a server?

    Using PowerShell 3.0 (And if possible the CIM, not WMI cmdlet), how can I script with | out-file C:\<filename>.txt or .csv option to list all local user accounts & local groups
    on remote computers? 
    Thank You!

    I don't recall PowerShell V3 introducing anything new to handle local users and groups. You need to use PowerShell V1 methods, using the [ADSI] accelerator and the WinNT: provider. The scripts linked above show this. No need to use WMI (which would probably
    be slower).
    Here is a script I've used to enumerate all local groups and their members:
    $Computer
    = "MyServer"
    $Computer =
    [ADSI]"WinNT://$Computer"
    $Groups =
    $Computer.psbase.Children | Where {$_.psbase.schemaClassName
    -eq "group"}
    ForEach ($Group
    In $Groups)
        "Group: "
    + $Group.Name
        $Members
    = @($Group.psbase.Invoke("Members"))
        ForEach ($Member
    In $Members)
            $Class
    = $Member.GetType().InvokeMember("Class",
    'GetProperty', $Null,
    $Member, $Null)
            $Name
    = $Member.GetType().InvokeMember("Name",
    'GetProperty', $Null,
    $Member, $Null)
            "-- Member: $Name ($Class)"
    A similar script to enumerate all local users would be:
    $Computer
    = "MyServer"
    $Computer =
    [ADSI]"WinNT://$Computer"
    $Users =
    $Computer.psbase.Children | Where {$_.psbase.schemaClassName
    -eq "user"}
    ForEach ($User
    In $Users)
        "User: "
    + $User.Name
    Richard Mueller - MVP Directory Services

  • Domain local groups with members from other (same forest) domains?

    I'm confused about granting access to a share via a domain local group that contains members from other domains. Consider this scenario:
    Joe Smith logs into his own domain (DALLAS.CORP.COM) and his token gets the DALLAS\sales global group.
    A share (named sales) in a different domain within the same forest (FORTSMITH.CORP.COM) assigns ntfs modify on its DACL via the FORTSMITH\sales_modify domain local group, which contains the DALLAS\sales global group.
    Joe goes to access the sales share...what happens, exactly?
    Since Joe logged into a DC in the DALLAS domain (outside the replication scope of the sales_modify group), his token does not contain sales_modify, right? So when he goes to access the sales share, that file server in FORTSMITH checks his token, doesn't
    see FORTSMITH\sales_modify in his token, and boom: access denied...right?

    Universal group is ok within the same forest but different domain.
    Domain local is ok between separate forest (Trust should be in place).
    Global is ok for same domain.
    See this for more details.
    http://msmvps.com/blogs/acefekay/archive/2012/01/06/using-group-nesting-strategy-ad-best-practices-for-group-strategy.aspx 
    Written by Ace Fecay-DS MVP.
    Regards~Biswajit
    Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights.
    MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, MCTS, Enterprise Admin
    MY BLOG
    Domain Controllers inventory-Quest Powershell
    Generate Report for Bulk Servers-LastBootUpTime,SerialNumber,InstallDate
    Generate a Report for installed Hotfix for Bulk Servers

  • Export AD group members to csv powershell with full details

    Hi,
    please help me...
    How to Export AD group members to csv powershell with full details
    fasil cv

    Yep, that's true. Even if we try:
    $GroupName = "group1"
    Get-ADGroupMember -Identity $GroupName | where { $_.objectClass -eq "user" } | % {
    Get-ADUser -Identity $_.distinguishedName -Properties * | select * |
    Export-Csv -Path "$GroupName.csv" -NoTypeInformation -Append -Force
    By scoping the Get-ADGroupMember to user objects, we may still have mismatched columns since some users may have properties that others do not; like 'isCriticalSystemObject'
    I suppose one solution is to enumerate the properties before the Export, and add the consistent ones to a custom PSObject, and export that to CSV. It would help if the task requirement specifies what user properties are needed instead of the blanket "full
    details", or if we export to XML instead of CSV.
    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________
    Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    Filtering the object type to just user objects is already implicit in Get-ADUser. If you really want information on all the members you'll need to run Get-ADUser on the user objects, and Get-ADGroup on the group objects.
    Edit: There might also be computer account objects in there, too.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • AD group Members list

    I can use GET-ADGroupMemeber AD powershell command to list the groups of what I need. However, I need a way that if someone adds a person to a group that it will trigger an email alert and send me an email with the new person added to that group. For
    example,  if using a power shell script where if someone adds a person to the domain admins group would it be able to trigger an email alert as soon as the person get added and send me an email of who the new user was added to the group.
    Is this possible using a power shell script with schedule task?

    you can do this in different ways
    for example, create 2 files or arrays and compare both and output the differences.
    Keep track of the count of Members in the admin group. When there's a positive difference it means a user was added.
    Below you can find some helpfull things to achieve what you want.
    Compare-Object :
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/21/3610554.aspx
    I've used it in the following way:
    Compare-Object (Get-Content $file1) (Get-Content $file2) | where {$_.SideIndicator -eq "<="}
    for the Send-MailMessage see
    -> http://technet.microsoft.com/en-us/library/hh849925.aspx
    I also found this script where they also use the compare option to get this done
    -> http://www.lazywinadmin.com/2012/03/powershell-monitor-membership-change-to.html
    or
    -> http://gallery.technet.microsoft.com/Monitor-Active-Directory-4c4e04c7

  • Members of Domain Local Groups not showing up through net group command

    Hello,
    I am trying to get the list of members in a Domain Local Group using "NET GROUP" command, but unable to get the member list.
    I get the message "group not found", whereas members of Global Groups  are visible.
    Thank you in advance !

    Unfortunately your post is off topic here, in the TechNet Site Feedback forum, because it is not Feedback about the TechNet Website or Subscription. 
    This is only one forum among the many that are on the TechNet Discussion Forums, and given your post, you likely chose the wrong forum. 
    This is a standard response I’ve written up in advance to help many people (thousands, really.) who post their question in this forum in error, but please don’t ignore it. 
    The links I share below I’ve collected to help you get right where you need to go with your issue.
    For technical issues with Microsoft products that you would run into as an
    end user of those products, one great source of info and help is
    http://answers.microsoft.com, which has sections for Windows, Hotmail, Office, IE, and other products. Office related forums
    are also here: http://office.microsoft.com/en-us/support/contact-us-FX103894077.aspx
    For Technical issues with Microsoft products that you might have as an
    IT professional (like technical installation issues, or other IT issues), you should head to the TechNet Discussion forums at
    http://social.technet.microsoft.com/forums/en-us, and search for your product name.
    For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), you should head to the
    MSDN discussion forums at http://social.msdn.microsoft.com/forums/en-us, and search for your product or issue.
    If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here:
    http://community.dynamics.com/
    If you really think your issue is related to the subscription or the TechNet Website, and I screwed up, I apologize! 
    Please repost your question to the discussion forum and include much more detail about your problem, that could include screenshots of the issue (do not include subscription information or product keys in your screenshots!), and/or links to the problem
    you’re seeing. 
    If you really had no idea where to post this question but you still posted it here, you still shouldn’t have because we have
    a forum just for you!  It’s called the Where is the forum for…? forum and it’s here:
    http://social.msdn.microsoft.com/forums/en-us/whatforum/
    Moving to off topic. 
    Thanks
    MSDN and TechNet Subscriptions Support
    Did Microsoft call you out of the blue about your computer?
    No, they didn't.

  • Copy global group members to local groups

    I have an AD environment with a lot of global groups, all named G-FG-groupname and I would like to move (or copy) the members of these groups to already existing domain local groups with a similar groupname but
    with another prefix which is L-RG-groupname.
    Example, in which Testn can be replaced by any name.
    Members of domain global group G-FG-Test1 have to be moved or copied to domain local group L-RG-Test1
    Members of domain global group G-FG-Test2 have to be moved or copied to domain local group L-RG-Test2
    Members of domain global group G-FG-Test3 have to be moved or copied to domain local group L-RG-Test3
    etc..
    Many thanks!

    Hi Hoffer,
    as Mike already said, use the Searchbase parameter. Here's an example how it could look like in the previous script:
    # Import Module
    Import-Module ActiveDirectory
    # Get old Groups
    $GroupsOld = Get-ADGroup -Filter { name -like "G-FG-*" } -Properties Members -SearchBase "OU=OU TestOU,DC=intra,DC=netzwerker,DC=de"
    # Then for each group do ...
    foreach ($GroupOld in $GroupsOld)
    # Get the name of the new group
    $NewName = "L-RG-" + $GroupOld.Name.SubString(5)
    # Add Group Members
    Add-ADGroupMember -Identity $NewName -Members $GroupOld.Members -ErrorAction 'SilentlyContinue'
    # Remove Members from old group
    Remove-ADGroupMember -Identity $GroupOld -Members $GroupOld.Members -Confirm:$false
    Basically, use the Distinguished name of an Organizational Unit as the searchbase parameter.
    If you want to know the Distinguished Name of a given OU, you can either use the AD Console, or use this command (change the name as necessary):
    Get-ADOrganizationalUnit -filter { name -eq "OU TestOU" } | Select -ExpandProperty DistinguishedName
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Export Skill Group Members list for UCCE 8.5

    Hello,
    We are working with UCCE 8.5 and will be making some major bulk skill group changes.  We are looking to do the following:
    -Export a list of the members of specific skill groups so that we can revert to original skilling if necessary.
    -Bulk editing the members of specific skill groups.  The current method of adding/removing skills via Agent Explorer or Skill Group Explorer will not be scalable in the future.
    I've tried a variety of SQL queries and manipulation of the Bulk Insert/Edit tools, but have not come up with a solution yet and am hitting my head against the desk at this point.  Any direction or advice is appreciated.  Thanks!

    Hi,
    exporting is easy with SQL. The simplest query may be:
    USE [icmInstance]_awdb
    GO
    SELECT
    ag.*, sg.*
    FROM Skill_Group_Member sgm
    LEFT OUTER JOIN Agent ag ON sgm.AgentSkillTargetID = ag.SkillTargetID
    LEFT OUTER JOIN Skill_Group sg ON sgm.SkillGroupSkillTargetID = sg.SkillTargetID
    The Database Schema docs contain all the necessary info:
    http://www.cisco.com/en/US/products/sw/custcosw/ps1844/prod_technical_reference_list.html
    Bulk editing: this is what the various "Bulk edit" options are within ICM Configuration Manager. Yes, that's it.
    Before you start experimenting with writing into the configuration tables: that's an excellent way of losing Cisco's support. And no, there's no public configuration API available.
    G.

  • Set "peoples or groups" field with current user "login name" in sharepoint list form using javascript

    hi friends
    i am trying to set peoples or groups field in sharepoint  list form with current user login name
    here my code
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
    <script type="text/javascript">
    $(document).ready(function NewItemView () {
    var currentUser;
        if (SP.ClientContext != null) {
          SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');
        else {
          SP.SOD.executeFunc('sp.js', null, getCurrentUser);
        function getCurrentUser() {
          var context = new SP.ClientContext.get_current();
          var web = context.get_web();
          currentUser = web.get_currentUser();
          context.load(currentUser);
          context.executeQueryAsync(onSuccessMethod, onRequestFail);
        function onSuccessMethod(sender, args) {
          var account = currentUser.get_loginName();
          var accountEmail = currentUser.get_email();
          var currentUserAccount = account.substring(account.indexOf("|") + 1);
        SetAndResolvePeoplePicker("requester",account);
    // This function runs if the executeQueryAsync call fails.
        function onRequestFail(sender, args) {
          alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
     function SetAndResolvePeoplePicker(fieldName, userAccountName) {
       var controlName = fieldName;
        var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
        var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");
        var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];
        peoplePickerEditor.val(userAccountName);
        spPeoplePicker.AddUnresolvedUserFromEditor(true);
    </script>
    but it is not working
    please help me

    Hi,
    According to your post, my understanding is that you wanted to set "peoples or groups" field with current user "login name" in SharePoint list form using JavaScript.
    To set "peoples or groups" field with current user "login name”,  you can use the below code:
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
    <script type="text/javascript">
    function SetPickerValue(pickerid, key, dispval) {
    var xml = '<Entities Append="False" Error="" Separator=";" MaxHeight="3">';
    xml = xml + PreparePickerEntityXml(key, dispval);
    xml = xml + '</Entities>';
    EntityEditorCallback(xml, pickerid, true);
    function PreparePickerEntityXml(key, dispval) {
    return '<Entity Key="' + key + '" DisplayText="' + dispval + '" IsResolved="True" Description="' + key + '"><MultipleMatches /></Entity>';
    function GetCurrentUserAndInsertIntoUserField() {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    this._currentUser = web.get_currentUser();
    context.load(this._currentUser);
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
    Function.createDelegate(this, this.onFailure));
    function onSuccess(sender, args) {
    SetPickerValue('ctl00_m_g_99f3303a_dffa_4436_8bfa_3511d9ffddc0_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', this._currentUser.get_loginName(),
    this._currentUser.get_title());
    function onFaiure(sender, args) {
    alert(args.get_message() + ' ' + args.get_stackTrace());
    ExecuteOrDelayUntilScriptLoaded(GetCurrentUserAndInsertIntoUserField, "sp.js");
    </script>
    More information:
    http://alexeybbb.blogspot.com/2012/10/sharepoint-set-peoplepicker-via-js.html
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Excel with powershell and this big problem of locale

    Hi Folks, I'm getting C R A Z Y with this Excel/Powershell Stuff...
    MY display language is EN
    My input language is fr_CH
    the following code : 
    function Invoke([object]$m, [string]$method, $parameters)
    $m.PSBase.GetType().InvokeMember(
    $method, [Reflection.BindingFlags]::InvokeMethod, $null, $m, $parameters,$ciUS)
    $ciUS = [System.Globalization.CultureInfo]'fr-CH'
    $objExcel = New-object -com Excel.Application
    $objExcel.visible = $True
    $ci = [System.Globalization.CultureInfo]'fr-CH'
    $objWorkbook = Invoke $objExcel.Workbooks Add
    $objWorksheet = $objWorkbook.Worksheets.Item(1)
    $objWorksheet.Cells.Item(1,1).FormulaLocal = "A value in cell A1."
    Invoke $objWorkbook SaveAs "C:ScriptsTest.xls" > $null
    Invoke $objWorkbook Close 0 > $null
    $objExcel.Quit()
    throw me the error : 
    Exception calling "InvokeMember" with "6" argument(s): "Object does not match target type."
    At line:3 char:1
    + $m.PSBase.GetType().InvokeMember(
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : TargetException
    You cannot call a method on a null-valued expression.
    At line:11 char:1
    + $objWorksheet = $objWorkbook.Worksheets.Item(1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    Basically this happend when you have english Excel with non english locale.
    My OS is in english but my Keyboard is in French-Swiss.
    Please help me I'm getting crazy...
    MCITP Enterprise Administrator / Server Administrator

    This might be helpful.
    http://dmitrysotnikov.wordpress.com/2008/02/22/powershell-help-broken-on-localized-versions-of-windows/
    The problem seems to be that PowerShell v1 for Windows Vista and PowerShell v2 CTP for all systems are storing the language neutral (English) help system in the en-US subfolder of the PowerShell folder.
    On a localized versions of Windows, PowerShell seems to be looking for a subfolder with its own locale (e.g. de-DE for Germany, ru-RU for Russia, and so on) and does not fail over to en-US if the folder is not found.
    RESOLUTION
    Apply the language pack for your language so your local version of help gets added to the system.
    If the language pack is not available, copy or rename the en-US folder to match your Windows locale. To learn your locale run the following command in the PowerShell prompt:
    [System.Globalization.CultureInfo]::CurrentUICulture
    Thanks Azam When you see answers please Mark as Answer if Helpful..vote as helpful.

  • Add custom local group with similar power as Windows BUILTIN\Administrators group

    In windows 7 or windows 8
    Is there any possibility to create a custom Local group having the same power/privileges as it does the BUILTIN\Administrators group.
    If yes; how?
    For instance:  I created a new local group, then in Local Security Policy(secpol.msc) \Security Settings\Local Policies\User Rights Assignments I added all the available policies where the Administrators group was also there, then I create a normal
    local user and assigned this new customized group, however the user never obtained the sufficient power as it does a user from Administrators group.
    Can anyone help?
    Thanks in advance.

    I don't think you can create a replica for Admin group.
    Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
    the thread.

  • CustomRealm without listing Group Members

    Hi,
    we are considering to implement a custom security realm. We have a fixed number
    of groups to be used in ACLs. Users are stored in an LDAP server.
    Group membership depends on some information on the individual user which needs
    to be gathered from a separate backend system. Therefore, it is not feasible to
    implement the getMembers() method on the Group class since that means iterating
    over all "user records" in the backend system.
    Here my question:
    1. Is the getMembers() method needed for Authorization and/or Authentication or
    can we simply make it return an empty list? (We do not mind if we do not see group
    members in the administration console.)
    2. Is it a good idea at all to have this kind of group definition?
    3. What about the method "getUsers" for the ListableRealm? Is this one needed
    for Authorization/Authentification. This method poses a similar problem.
    Regards,
    Andreas

    1. Is the getMembers() method needed for Authorization and/orAuthentication or
    can we simply make it return an empty list? (We do not mind if we do notsee group
    members in the administration console.)I think this method is not needed at all for authentication and
    authorization, it's only used to list the users in the WL admin page.
    3. What about the method "getUsers" for the ListableRealm? Is this oneneeded
    for Authorization/Authentification. This method poses a similar problem.Same answer.

Maybe you are looking for