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 7672401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:16:37+00:00 2026-05-31T16:16:37+00:00

I have a script that may be run manually or may be run by

  • 0

I have a script that may be run manually or may be run by a scheduled task. I need to programmatically determine if I’m running in -noninteractive mode (which is set when run via scheduled task) or normal mode. I’ve googled around and the best I can find is to add a command line parameter, but I don’t have any feasible way of doing that with the scheduled tasks nor can I reasonably expect the users to add the parameter when they run it manually.
Does noninteractive mode set some kind of variable or something I could check for in my script?

Edit:
I actually inadvertently answered my own question but I’m leaving it here for posterity.

I stuck a read-host in the script to ask the user for something and when it ran in noninteractive mode, boom, terminating error. Stuck it in a try/catch block and do stuff based on what mode I’m in.

Not the prettiest code structure, but it works. If anyone else has a better way please add it!

  • 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-31T16:16:38+00:00Added an answer on May 31, 2026 at 4:16 pm

    You can check how powershell was called using Get-WmiObject for WMI objects:

    (gwmi win32_process | ? { $_.processname -eq "powershell.exe" }) | select commandline
    
    #commandline
    #-----------
    #"C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" -noprofile -NonInteractive
    

    UPDATE: 2020-10-08

    Starting in PowerShell 3.0, this cmdlet has been superseded by Get-CimInstance

    (Get-CimInstance win32_process -Filter "ProcessID=$PID" | ? { $_.processname -eq "pwsh.exe" }) | select commandline
    
    #commandline
    #-----------
    #"C:\Program Files\PowerShell\6\pwsh.exe"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that works fine when I run it manually in R
I have a script being run in a document that may or may not
I have a script that successfully encrypts a credit card. I need it to
I have a PHP script that needs to run some pretty hefty imagemagick commands.
I have a script file for MySQL that needs to be run on about
I have a Ruby script that I built in TextMate and can successfully run
I have a batch script I run before our performance tests that does some
I have a script that needs to determine the charset before being read by
I have a CakePHP script that should hopefully be run by a cron job.
I have some scripts that I need to run that I want to access

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.