Open Powershell in elevated mode, without any prompt - powershell

We have many solutions which opens the PowerShell in elevated mode using self-elevating batch file, self-elevating PowerShell Scripts as well.
But My question is how do we open PowerShell in elevated mode using PowerShell without any admin prompt.
Basically all the solutions given to this question help us open in admin mode, but there we need to press okay on the prompt.
Is there any way to disable the prompt using PowerShell itself?

Related

Powershell run Script in ISE full window

Is there a was for a Powershell script to be launched from Scheduler and run full ISE window and close when done.
I am using ZeeDrive to map a SharePoint Drive but running the Script in Scheduler, it cannot see the Drive. Yet if I open in ISE and run, it finds it fine. What I got back from ThinkScape :
'Zee Drive needs to run in a Windows session. It is designed for end users – if it is running as a service, or “headless” i.e. no Windows session, or being accessed from a different Windows session it won’t work.
We don’t support Zee Drive running as a service or for service type workloads – it is designed for end users working with documents'.
Any help would be greatly appreciated.
Thanks
The only way I can think of, would be to add your script to the Microsoft.PowerShellISE_profile.ps1 and then start ISE with the scheduler and your file as parameter, like this:
powershell_ise .\Check-Process.ps1
In your profile you would want to make sure, that the script only runs, when you open that file:
if($psISE.PowerShellTabs.Files.FullPath -eq '\\fileserver\path$\to\my\Powershell\Check-Process.ps1')
{
& '\\fileserver\path$\to\my\Powershell\Check-Process.ps1'
}
But be carefull! The script runs now everytime you open it in ISE unless you use the switch -noprofile.
So far I did not find a way to close the ISE window with the profile script.

start process as administrator in powershell without prompt

I startet to look around but only found usage with a prompt. But as this is for the users I was wondering if I can make it run without a prompt still with elevated privileges behind.
Start-Process powercfg.cpl -Verb runas
this is a simple oneline but this prompts for creds can I somehow tell it just to run elevated without a prompt
Update1: We are thinking of creating a AD User which has only rights for the needed task than can be shared for this prompt.
Update2: WE figured out that pre installed Toshiba software was causing it to jump back after restart and after every edit. We deinstalled the software and since there was no need to run it as admin anymore.

Powershell close without warning user if there is a program still running

Allow me to first address this: I am not asking "powershell close when script finish running". I know a lot of people are asking about this, but that have nothing to do with this question.
In ubuntu, terminal will prompt user to confirm the close of a terminal window if something is still running, so that user will not terminate their script by mistake. I've long been benefit from this mechanism.
Does powershell have similar setting? How to enable it?
Edit: I'm using powershell as a terminal, I may running a python script, powershell script or something else other than a script.
And although powershell does not accept the alt+F4 shortcut, powershell ISE does, still with no user prompt. And the whole powershell ISE can even exit entirely by simply typing 'exit' in one powershell tab within the ISE. Is there a way to prevent this?

Is it possible to know if a PowerShell script is launched from GUI or console?

Is it possible to know if a PowerShell script is launched from GUI e.g. double-click in the explorer or manually in a powershell console?
I would like to use an interactive console mode if it's launched in GUI / explorer.
Query $host automatic variable
$host.name
return the name of the actual host.

How can I execute scripts in a code created powershell shell that has Host.Ui.prompt commands in it?

I have a Powershell Commandlet which prompts a user from a secure string based on a condition. Now I want to automate the testing of this commandlet for which I use a Powershell Remote Runspace to Invoke the commandlet. Currently it fails with this error.
Write-Host : A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
How can I automate this?
It sounds like you are running powershell via c#. You can't prompt the user for input from the powershell script. You either need to pre-provide the necessary info in the script, or prompt for the info from your application and then pass the info to the powershell script.
As ojk mentioned the easiest way to accomplish this would probably be to use a powershell function then pass the necessary parameters to it via the code.