Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?

Tartalomjegyzék:

Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?
Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?

Videó: Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?

Videó: Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?
Videó: 7 Best Ways to Watch College Football Without Cable (Watch Football for Cheap!) - YouTube 2024, Április
Anonim
A PowerShell rendkívül hasznos lehet a mindennapi feladatokhoz hasonlóan, de ha valamilyen funkciót be kell csípnie egy kis biztonsággal, akkor hogyan határozza meg a függvényt, hogy megkövetelje a magasságot? A mai SuperUser Q & A hozzászólás a kíváncsi olvasó kérdéseire ad választ.
A PowerShell rendkívül hasznos lehet a mindennapi feladatokhoz hasonlóan, de ha valamilyen funkciót be kell csípnie egy kis biztonsággal, akkor hogyan határozza meg a függvényt, hogy megkövetelje a magasságot? A mai SuperUser Q & A hozzászólás a kíváncsi olvasó kérdéseire ad választ.

A mai Kérdések és válaszok munkamenetét a SuperUser - a Stack Exchange, a Q & A weboldalak közösség által irányított csoportosulásának részlegével - köszönheti.

A kérdés

A SuperUser olvasó Vlastimil azt szeretné tudni, hogyan kell egy PowerShell függvényt meghatározni, amely megköveteli a magasságot:

Since I cannot find any alternatives to Linux’s sudo elevation command, I have the following question. How do I define a PowerShell function that requires elevation, as in activating a UAC prompt on my Windows 8.1 Pro, 64-bit system? For example, say I run the following function:

With the following results:
With the following results:
Image
Image

To be completely clear, if I run PowerShell as “user”, then run the aforementioned function system-check, I want the function to elevate in order to be able to execute the command (I want the UAC prompt to appear).

Hogyan határozza meg a PowerShell funkciót, amely megköveteli a magasságot?

A válasz

Ashton a SuperUser munkatársa számára a válasz:

To run a specific command from an elevated window:

For example:
For example:
To run a specific script from an elevated window:
To run a specific script from an elevated window:
To run an entire PowerShell session that prompts the UAC:
To run an entire PowerShell session that prompts the UAC:
Image
Image

A function to return $True or $False if the current window is running with elevated permissions:

To ensure a script is only run As Admin, add this to the beginning:
To ensure a script is only run As Admin, add this to the beginning:
Image
Image

In PowerShell v4.0, the above can be simplified by using a #Requires statement:

Image
Image

Source: Run with Elevated Permissions [SS64.com]

Van valami a magyarázathoz? Hangzik ki a megjegyzésekben. Szeretne többet válaszolni a többi technikus-tudós Stack Exchange felhasználóiról? Nézze meg a teljes vitafonalat itt.

Ajánlott: