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

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?

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.

Powershell ISE breaks when using CMD /C Pause

I'm newer to PowerShell, transitioning from batch, so forgive me if I make a stupid mistake. I really like using Powershell ISE. But with the current script I'm trying to run, I use the cmd /c pause | Out-Nul command and it breaks ISE by not allowing me to continue any further.
I was trying for a long time to find some way to pause but not show output from the command and I found the cmd /c pause command. I can run it fine in a normal PowerShell prompt but ISE just isn't having it.
Anyone have any ideas why this happens or a better alternative to cmd /c pause Out-Nul? Thanks and any advice is more than welcome!
Powershell ISE doesn't redirect STDIN (which pause needs).
Shelling out to cmd for the pause command is unneeded.
See this post for more info on the ISE not being able to take stdin. You won't find your specific issue but the problem is the EXACT same problem.
On that page, you will also find a better/native way to do "pause" from powershell...
(aka [System.Console]::ReadKey($false) )

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.

Open Powershell in elevated mode, without any prompt

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?

CmdLet works in PowerShell but not in PowerShell ISE

Lately I have been developing PowerShell scripts on a Window 8 machine instead of on a Windows Server 2012R2 which I normally do.
I have encountered two very strange things that never happened on the server.
I know, two questions in one post, but I believe they might be connected.
After a while cmdlets just stop producing any output whatsoever, no error messages, no verbose output. It doesn't matter if I run it in the "lower" command part or in the "upper" script editor, and no difference if I run a selected part of the script or the whole thing. If I switch to a "normal" PowerShell the cmdlet works fine. If I restart PowerShell ISE, the cmdlet start working again, but only for a like 2-5 execution (not at all exact number) after which it stops working again. Not all cmdlets behave this way, mostly had problems with Storage related cmdlets (Format-Partition, Get-Disk, Get-Volume and so on).
After a while cmdlets that used to work fine in the "upper" script part of PowerShell ISE just stops working. The cmdlets still work fine in the "lower" command part of the ISE GUI, but does not work when used in the "upper" script editor, even though they did just a second ago. And it doesn't matter if I run the whole script or just a selected part. And by not working I mean it can't even find the cmdlet (The term '' is not recognized as the name of a cmdlet). The cmdlet is available in the Commands Side-Bar where it show up without any problem and I can access help for it.
So any ideas what is going on here?