Current logged on user using Powershell script

Hi,
i found a vb script which works fine and gives me desired output however i am looking to get this converted to powershell, so that i can add this to an existing shell script
Purpose : the shell script should display/Echo currently logged on user, by reading the wmi
Below is the vb script which i found, also i dont want its first line because i will be running the script locally on the computer with admin rights
strComputer = "atl-ws-01"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'explorer.exe'")
If colItems.Count = 0 Then
Wscript.Echo "No one is logged on to the computer."
Else
For Each objProcess in colItems
objProcess.GetOwner strUser, strDomain
Wscript.Echo strDomain & "\" & strUser
Next
End If--------RegardsTanoj
OSLM ENGINEER - SCCM 2007 & 2012

Thank you for the reply
yes mjolinor you caught me, i am working with sccm 2012 trying to create a universal script which will work flawlessly on VM, windows 8, Windows 7 etc ....
so which one you think is good to fullfill my need,
Get-WmiObject
-Class win32_process
-filter "Name = 'explorer.exe'" -computer VMNAME    ?
 also it will be great help if you could help me get the complete script wich includes the above line,
i get following error when executing the above command
Regards
Tanoj

Similar Messages

  • OIM11gr2 - How to get currently logged in user details using oim api

    Hi All,
    I have a requirement to retrieve currently logged in users profile in the process adapter.
    I have tried with getSelfProfile in tcUserOperation and also ContextManager.getOIMUser API's however, in both the cases i am getting xelsysadm details only.
    Also as know request details in Process task mapping doesnot work for OIM11g onwards (its returning column not found exception )
    DOes any one has idea how to achieve this.
    PS. - i am using platform to retrieve API's.
    Thanks & Regards
    Swati Pandey

    You can get the logged in user name using the below java code:
    ADFContext adfCtx = ADFContext.getCurrent();
    SecurityContext secCntx = adfCtx.getSecurityContext();
    String user = secCntx.getUserPrincipal().getName();
    HTH

  • Need query to determine current logged in user

    Because I see no way in sccm 2012 to determine if someone is currently logged into a domain joined computer.  Does anyone have a query or know of a way to get the current logged in user of a computer? I am surprised that SCCM does not show that information
    when looking at the particular device.  I did find a powershell query that I use that tells me the last logged in user but it gives me no indication if the user is currently logged in or if it was a week ago.
    Thank you.

    This PowerShell script queries a remote machine to obtain the current logged on user.  It's available on the Repository (https://gallery.technet.microsoft.com/scriptcenter/d46b1f3b-36a4-4a56-951b-e37815a2df0c).
    function Get-LoggedOnUser {
    #Requires -Version 2.0
    [CmdletBinding()]
    Param
    [Parameter(Mandatory=$true,
    Position=0,
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
    [String[]]$ComputerName
    )#End Param
    Begin
    Write-Host "`n Checking Users . . . "
    $i = 0
    }#Begin
    Process
    $ComputerName | Foreach-object {
    $Computer = $_
    try
    $processinfo = @(Get-WmiObject -class win32_process -ComputerName $Computer -EA "Stop")
    if ($processinfo)
    $processinfo | Foreach-Object {$_.GetOwner().User} |
    Where-Object {$_ -ne "NETWORK SERVICE" -and $_ -ne "LOCAL SERVICE" -and $_ -ne "SYSTEM"} |
    Sort-Object -Unique |
    ForEach-Object { New-Object psobject -Property @{Computer=$Computer;LoggedOn=$_} } |
    Select-Object Computer,LoggedOn
    }#If
    catch
    "Cannot find any processes running on $computer" | Out-Host
    }#Forech-object(Comptuters)
    }#Process
    End
    }#End
    }#Get-LoggedOnUser

  • Login to Jabber Client (Windows/Mac) with current logged in user account.

    We are deploying Jabber Client for Windows and will eventually be deploying for Macintosh.  I have no problem building the thinapp deployment package for the Jabber client.  However, when the thinapp is ran, it always shows the account that was used to initially login to the client and setup the server connection.
    Is there a way for the client to use the current logged in user in the sign in field?  I am trying to automate or SSO the process of logging into Jabber.
    Any and all ideas, tips, and/or tricks are greatly appreciated!
    Thank you,
    Wes

    This is nothing to do with the TC. This is your user issues on the Mac.
    I would do a major fix on the computer.. copy your user files to another location.. create a new administrator account.. login with the new admin account and delete the old one. Delete all the files associated with that account, so you are effectively starting with a clean Mac.
    I have just sold off a couple of computers and that is how I prepared it for the next person.. it seemed to work easily and removed all my stuff from the computer whilst still giving them full admin access.
    Please I am far from expert in doing this kind of stuff in OSX so just look up deleting original user accounts in whatever OS you run.

  • My Tasks View in my custom task list fails to display the tasks assigned to me (that is the currently logged in user)

    Hi
    I am new to sharepoint 2010.
    I created a custom task list, where I  have many tasks assigned to users (I had tasks assigned to me as well). I created a view as "My tasks "and having a filter as Assigned To is equal to [Me]. When I do that my view fails to show the
    tasks assigned to me. This happens same with the Sharepoints 'My Tasks' view as well. I tested by creating some test tasks under my name and when I selected 'My Tasks' view no tasks are getting displayed.
    Please help.
    Thanks,
    Gokulkumar.

    Hi,
    According to your post, my understanding is that you wanted to display the tasks assigned the current logged in user.
    In my environment, if I used the System Account, My Task view didn’t display any tasks.
    However , if I used other users except the System Account, My Task view could display current user tasks correctly.
    I recommend to use other accounts except System Account to log in site. Then everything will work well.
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to get current logged in user's star rating in SharePoint 2013

    Hi,
    Currently,  I am developing a custom web part to show star rating for documents, everything is done.
    However,when user hover on the star I want a tooltip message("Your current rating is 1..."), similar to what we have 
    in libraries(or what the sharepoint by default provides in libraries) . So can I get the user specific rating depending upon 
    the logged in user using code(.net or CSOM anything will work)

    using the below code you can get the rated by user along with the rating , it's easier to just notify the user that her already rated the document 
    var acontext = new SP.ClientContext.get_current();
    var lists=acontext.get_web().get_lists();
    var l =lists.getByTitle("Documents"); //your document libraty
    var aitem=l.getItemById(27);//Item id
    acontext.load(aitem, "RatedBy", "ID", "Ratings");
    acontext.executeQueryAsync(function(){
    var RatedBy= aitem.get_item('RatedBy');
    if (!SP.ScriptHelpers.isNullOrUndefined(ratings)) {
    for (var i = 0; i < RatedBy.length; i++) {
    var user = RatedBy[i];
    if (user.get_lookupId() == _spPageContextInfo.userId) {
    //show that you already rate it
    break;
    },function(s,e){alert(e.get_message());});
    another way is to use CAML query to check if the current user id is within the RatedBy multi user field
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • How to get current logged-in user name in data access driver or in universe

    In universe, to get the current log in user is via @Variable('BOUSER').
    Right now, I need to be able to get the user name in the data access driver. I am writing a customized data access driver because we need to patch some where clause on the the query generated by the universe based on the logged-in user info. I only think of using end_sql parameter or adding an universe level filter to patch the @Variable('BOUSER') to the query, which would not work if user want to use customized query.
    Can anyone tell me how to get currentBO user name from connection server ? or how @Variable('BOUSER') is translated into the logged-in user name in the universe?

    I do not know your EJB Service. But you should pass the credentials of the current logged on portal user to your service. That's not by default I think.
    I had a similar problem with CAF developed webservices. I had to turn on permission checks in my web service and passed the credentials via logon ticket.
    Regards, Bernd

  • Identity User( Find Current Logged in User) Windows Forms

    I have implemented dummy code for logging in to a windows Forms Application using Identity (Owin Auth). part of my code is as follows:
    private bool validateuser()
    bool isAuthorised = false;
    Login1 log = new Login1();
    if (DialogResult.OK == log.ShowDialog())
    Splasher.Show(typeof(frmSplash));
    userC = log.usernameTextBox.Text;
    PassC = log.passwordTextBox.Text;
    if (userC == "" || PassC == "")
    count++;
    //isAuthorised = false;
    if (count > 0) log.LoginStatus.Text = "Empty passwords or usernames are not allowed. please try again";
    if (count == 2) MessageBox.Show("You have one try remaining");
    if (count == 3) { MessageBox.Show("You have exosted your tries application will now close"); Application.Exit(); }
    validateuser();
    else
    var userStore = new UserStore<IdentityUser>();
    var userManager = new UserManager<IdentityUser>(userStore);
    var user = userManager.Find(userC, PassC);
    if (user != null)
    var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
    isAuthorised = userIdentity.IsAuthenticated;
    userIdentity.AddClaim(new Claim("FullName", user.UserName));
    userIdentity.AddClaim(new Claim("User_Id", user.Id));
    return isAuthorised;
    else
    count++;
    //Application.Exit();
    if (count > 0) log.LoginStatus.Text = "You may have entered a wrong password or username. Please try again";
    if (count == 2) MessageBox.Show("You have one try remaining");
    if (count == 3) { MessageBox.Show("You have exosted your tries, application will now close"); Application.Exit(); }
    validateuser();
    count = 0;
    return isAuthorised;
    When the code works fine and is able to authenticate from the database. In the current form, I'm able to get the current user by using user.UserName or id by using user.Id
    How do I get to retrieve the name or Id of the current logged in user from another form. Please Help
    Thanks
    My ASP

    Type in c.Type is giving an error. could I be missing any important reference?
    My ASP
    Hi,
    Looks from Aram's code, I found a blog from Leandro Boffi.
    http://leandrob.com/2012/02/claims-identity-c-4-0-dynamics/
    Some similar code like Aram's. You should install
    Windows Identity Foundation and the companion
    WIF SDK
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get login of currently logged in user in OIM?

    Hi,
    I am developing JSP in OIM and I would like to obtain data of currently logged in user*, it is possible through getSelfProfile() method ( tcUserOperationsIntf ), so far I have written the following code:
    tcResultSet loggedUser = null;
    tcUtilityFactory utilityFactory = null;
    ConfigurationClient.ComplexSetting myConfig =
    ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
    final Hashtable env = myConfig.getAllSettings();
    tcSignatureMessage moSignature = tcCryptoUtil.sign("xelsysadm", "PrivateKey");
    utilityFactory = new tcUtilityFactory(env, moSignature);
    tcUserOperationsIntf userIntf;
    userIntf = (tcUserOperationsIntf)utilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
    loggedUser = userIntf.getSelfProfile();
    String userLogin;
    try
    userLogin = loggedUser.getStringValue("Users.User ID");
    System.out.println("User = "+userLogin);
    catch (tcColumnNotFoundException e)
    // TODO
    The problem that this code always returns XELSYSADM, and NOT data for user who is really currently logged in. I think that this is because of the one line on code (marked as bold) where xelsysadm is passed to the moSignature variable. But without this line of code it is impossible (I think so...) to initialize tcUserOperationsIntf and use the getSelfProfile() method... and the circle is closed...
    Had anyone similar scenario?
    Thanks in advance!

    Through the tcUtilityFactory class, you can just use the api getUserName.
    Obviously if you pass the value "xelsysadm" to the line you have bolded, it's always going to use that user for everything. If you login with another user, they need to have permissions to the pieces of oim for the APIs you use. If you use a user search api, they must have permissions to the organization where the users are at.
    -Kevin

  • How to get Current Logged in user in Java

    Hi All ,
    I have written a code in to get the current logged in user in the portal in an EJB service.  I have used the code
    *IUser user= UMFactory.getAuthenticator().getLoggedInUser();*. But surprisingly the userId which it returns is always is Guest. Can you please help on this issue.
    Thanks & Regards,
    Rohit

    I do not know your EJB Service. But you should pass the credentials of the current logged on portal user to your service. That's not by default I think.
    I had a similar problem with CAF developed webservices. I had to turn on permission checks in my web service and passed the credentials via logon ticket.
    Regards, Bernd

  • Current Logged On User

    What I am needing to do is create a file with a name based on the currently logged on user in order to store some logging data.  I am using the single sign on method with the connection context cookie.  Is there a way to determine who is currently logged on with this method?  I am not interested in passwords, just the current logged on user.
    Thank You,
    Greg Johnson

    The company object in both the UI and DI have a UserName property that will contain the name of the currently logged in user.
    sboApp.MessageBox sboCompany.UserName & ":" & sboApp.Company.UserName
    John.

  • Get the current Logged on User on Mobile Client

    Hi
    I have to display the current logged in User of the Mobile client in my application. I think I have to use the User and UserManager API for that. But the thing is I am not able to instantiate the class to use the methods in it.I think I have to create a session object for using these classes, but in Session API I can see that I will have to create a new session and I want to use the current session.
    Please tell me how to use these APIs and get the instance of User or UserManager.
    Regards,
    Priya

    Hi Priya,
    You can try with:
    User user = UserManager.getInstance().getCurrentUser();
    The User interface has methods to get relevant information (for ie. getName() or getFirstName()), take a look on the [javadocs|http://help.sap.com/javadocs/nwmobile/SP3/laptops/com/sap/ip/me/api/user/User.html]
    Best Regards,
    Simon.

  • GPUpdate /force in Task Sequence as current logged on user

    Hi,
    I am currently trying to "upgrade" around 800 installations of Microsoft Office Standard 2010 to Microsoft Office 2010 Professional Plus. To do this, I'll have to:
    1: Install Office 2010 ProPlus
    2: Uninstall Office 2010 Standard
    3: Repair Office 2010 ProPlus
    Due to these steps, I've decided to make a task sequence to do the magic.
    So far, so good, the "upgrade" is installing, and the MAP toolkit reports are showing the correct results from my test lab.
    During the repair of Office 2010 ProPlus, the Office applications cannot
    run, so I've created a task to copy a custom group policy to %systemroot%\System32\GroupPolicy to deny the affected users to start the applications.
    After applying the group policies, I manually run a gpupdate /force on my test computer. The applications are not starting. Also - so far so good.
    Ok, so here is my challenge:
    Since the Task Sequence is running in context of the SYSTEM account, the applied group policy will not refresh the GPO's of the current logged on user. Meaning; during the installation / repair of Office 2010, the user can open all the applications regardless
    of the applied GPO's, and I'd very much like to avoid that. The TS will fail otherwise. Yes, I know I can perform a restart to apply the policies, but I'd like to avoid that as well.
    Any idea how can I solve this?

    I think you're making it very complex for yourself. I think that the PowerShell App Deployment Toolkit would be very benificial for a situation like this. For more information have a look here:
    https://psappdeploytoolkit.codeplex.com/
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

  • Get username and password of the currently logged-in user in CRM and pass it to the plugin

    Hi,
    I am integrating CRM Online and SharePoint Online. Right now I am using Office365 trial version for both. Hence, the same username and password works for both.
    I want to create sub-site in SharePoint on create of an entity record. Currently, I am passing the admin credentials. But, I want to pass the credentials of the currently logged-in user in CRM to the plugin which is getting executed on create of account entity.
    So that I can then create sub-site in SharePoint using the current user credentials instead of admin credentials.
    Is there way to achieve this?

    Hello,
    You would not be able to get login/password of currently logged in user. I believe usage of admin credentials is the best way to achieve your goal.
    Dynamics CRM MVP
    My blog

  • Current logged-in user in workflow-task

    Hi,
    I'm working on an approval task where I've got some problems in determining the items an aprovee may approve.
    The structure is as followed:
    A user requests something that his manager and the manager's manager have to approve sequentially. The manager and the manager's manager should only be able to approve requests of users that have a direct connection to them (regarding business units).
    What I am now searching for is a variable oder method to determine the current logged-in user (MSKEY or Unique ID) in the worklow system so that I can create a filter for approvees (SQL statement) to filter out all not direct linked users.
    I hope somebody can help me.
    Regards,
    Andreas Dietrich

    Andreas,
    Good question.  You need to have some sort of "Managed by" Attribute.  This attribute does exist in most LDAP directories and HCM packages, however there is NO guarantee that these attribues are populated.  The other possible thing to do is setup a relationship as follows:
    All members of the Sales Team are in the SALES
    The Sales Manager can be identified with a role of SALES MGR
    The Sales VP can be identified with the role SALES VP
    In the workflow, use an approval task and write a query that would reflect the fact that the SALES MGR can approve requests from SALES
    Use the Access control tab and set it up a filter sot that SALES MGR can execute on behlaf of SALES and so on.
    Hope this helps,
    Matt

Maybe you are looking for

  • Help need to create a query

    I need to fetch records from a table. Please help me to create a query The Tablename is Employee. It has the following records Department Empname Gender Finance Tom Male Finance Rick Male Finance Stacy Female Corporate Tom Male Corporate Rob Male I w

  • Open Other Project not closing original file

    Hello All, I have a total of 55 exe files that are all accessed through one captivate file called "Interface". I am experiencing some inconsistent errors with the "Open other project" feature when testing this on a computer other than my own. Basical

  • New PDF and Excel export functions in 3.0 - ARE FANTASTIC!

    Hello Guys! You know my management wants always to have an ability to export everything they see on our ApEx based intranet site to Excel and PDF files - so this feature you've made in upcoming 3.0 are really usefull! Thanks a lot! Is the schedule fo

  • Access through internet

    Hi all,        Currently we are having an mainframe application which is accessed through internet. In the website of client there is a link which navigates to this application. Once the user enter the VPN credentials it lets us to access the data. B

  • How do I get my iTunes content into iCloud and back to devices?

    ?