आप एक पावरशेल फ़ंक्शन को कैसे परिभाषित करते हैं जिसे ऊंचाई की आवश्यकता होती है?

विषयसूची:

आप एक पावरशेल फ़ंक्शन को कैसे परिभाषित करते हैं जिसे ऊंचाई की आवश्यकता होती है?
आप एक पावरशेल फ़ंक्शन को कैसे परिभाषित करते हैं जिसे ऊंचाई की आवश्यकता होती है?

वीडियो: आप एक पावरशेल फ़ंक्शन को कैसे परिभाषित करते हैं जिसे ऊंचाई की आवश्यकता होती है?

वीडियो: आप एक पावरशेल फ़ंक्शन को कैसे परिभाषित करते हैं जिसे ऊंचाई की आवश्यकता होती है?
वीडियो: Lyft & DoorDash Earnings | What This Means For Drivers - YouTube 2024, अप्रैल
Anonim
PowerShell बहुत सारे रोज़गार कार्यों के लिए बेहद उपयोगी हो सकता है, लेकिन यदि आपको कुछ कार्यों को ध्यान में रखते हुए कुछ कार्यों को ट्विक करने की आवश्यकता है, तो आप एक फ़ंक्शन को कैसे परिभाषित करते हैं ताकि उसे ऊंचाई की आवश्यकता हो? आज के सुपर यूज़र क्यू एंड ए पोस्ट में एक जिज्ञासु पाठक के सवाल का जवाब है।
PowerShell बहुत सारे रोज़गार कार्यों के लिए बेहद उपयोगी हो सकता है, लेकिन यदि आपको कुछ कार्यों को ध्यान में रखते हुए कुछ कार्यों को ट्विक करने की आवश्यकता है, तो आप एक फ़ंक्शन को कैसे परिभाषित करते हैं ताकि उसे ऊंचाई की आवश्यकता हो? आज के सुपर यूज़र क्यू एंड ए पोस्ट में एक जिज्ञासु पाठक के सवाल का जवाब है।

आज का प्रश्न और उत्तर सत्र हमारे पास सुपरयूसर की सौजन्य है - स्टैक एक्सचेंज का एक उपविभाग, क्यू एंड ए वेब साइट्स का एक समुदाय संचालित समूह।

प्रश्न

सुपरयूसर रीडर Vlastimil एक PowerShell फ़ंक्शन को परिभाषित करने के बारे में जानना चाहता है जिसके लिए ऊंचाई की आवश्यकता है:

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).

आप PowerShell फ़ंक्शन को कैसे परिभाषित करते हैं जिसके लिए ऊंचाई की आवश्यकता होती है?

उत्तर

सुपरयूसर योगदानकर्ता एश्टन का जवाब हमारे लिए है:

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]

स्पष्टीकरण में जोड़ने के लिए कुछ है? टिप्पणियों में विचार व्यक्त करो। अन्य तकनीक-समझदार स्टैक एक्सचेंज उपयोगकर्ताओं से अधिक उत्तरों पढ़ना चाहते हैं? यहां पूर्ण चर्चा धागा देखें।

सिफारिश की: