Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:31:24+00:00 2026-05-25T20:31:24+00:00

I have a script(Let’s call it myPSScript.ps1) which takes two parameters and performs predefined

  • 0

I have a script(Let’s call it myPSScript.ps1) which takes two parameters and performs predefined steps. Script is located in a Windows Server box which people login and execute the script. Supports two users to be logged in at the given time.

I want to find out who invoked the script.

(Get-WmiObject -Class Win32_Process | Where-Object {$_.ProcessName -eq 'explorer.exe'}).GetOwner() | Format-Table Domain, User 

This works when the user is logged in currently and trying to run the script. But what if I have a batch file in scheduled tasks and run the same script?

In that case the same command returns a null exception, as there is no one logged into the machine.

Is there a way to find out who/which process invoked the powershell script. I vaguely remember Start-Transcript records which user the command is run from etc, so this should be possible?

Thanks!
Sanjeev

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:31:24+00:00Added an answer on May 25, 2026 at 8:31 pm

    Interesting question. I wrote a script with three different ways to get the user like so:

    ([Environment]::UserDomainName + "\" + [Environment]::UserName) | out-file test.txt
    "$env:userdomain\$env:username" | out-file -append test.txt
    [Security.Principal.WindowsIdentity]::GetCurrent().Name | out-file -append test.txt
    notepad test.txt
    

    Saved it as test.ps1 and called it using runas as:

    runas /user:domain\user "powershell e:\test.ps1"
    

    And I got the domain\user all three times in the output. Used runas to just distinguish between the user I am logged in as (me!!) and the domain\user with which I was running it as. So it does give the user that is running the script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Bash script called foo.sh . I'd like to call
Let's imagine I have a bash script, where I call this: bash -c some_command
I have a bash-script (let's call it /usr/bin/bosh ) using the following she-bang line:
I have a script, which let's users submit e message. But I want to
I have a PHP script (let's call it execute.php ) that draws the whole
Let's assume I have a main script, main.py, that imports another python file with
Google is failing me on this one. Let's say I have some ECMA script
Let's say i have an image uploader script, i want to prevent the upload
I'm trying to solve the following problem: Say I have a Python script (let's
Greetings, I have a class (let's call it Car) that has a property of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.