{"id":1376,"date":"2013-10-22T20:50:20","date_gmt":"2013-10-22T18:50:20","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=1376"},"modified":"2013-10-23T11:48:08","modified_gmt":"2013-10-23T09:48:08","slug":"powershell-check-for-administrator-rights","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-check-for-administrator-rights\/","title":{"rendered":"Powershell: Check for Administrator rights"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_1376 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_1376')){$('.twoclick_social_bookmarks_post_1376').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20Check%20for%20Administrator%20rights\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Afor%20a%20lot%20of%20powershell%20scripts%20Administrator%20permissions%20are%20necessary.%20In%20powershell%2C%20you%20can%20check%20if%20you%20are%20elevated%20by%20the%20following%20script%20code.%0D%0AInsert%20the%20snippet%20at%20the%20top%20of%20your%20script.%20It%20checks%20the%20credentials%20and%20exits%20the%20script%20if%20the%20administrator%20permissions%20are%20missing.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-check-for-administrator-rights\\\/\",\"post_id\":1376,\"post_title_referrer_track\":\"Powershell%3A+Check+for+Administrator+rights\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>for a lot of powershell scripts Administrator permissions are necessary. In powershell, you can check if you are elevated by the following script code.<br \/>\nInsert the snippet at the top of your script. It checks the credentials and exits the script if the administrator permissions are missing.<br \/>\n<!--more--><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oIdent= &#x5B;Security.Principal.WindowsIdentity]::GetCurrent()\r\n$oPrincipal = New-Object Security.Principal.WindowsPrincipal($oIdent)\r\nif(!$oPrincipal.IsInRole(&#x5B;Security.Principal.WindowsBuiltInRole]::Administrator )){\r\n\tWrite-Warning &quot;Please start script with Administrator rights! Exit script&quot;\r\n\texit 1\r\n}\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, for a lot of powershell scripts Administrator permissions are necessary. In powershell, you can check if you are elevated by the following script code. Insert the snippet at the top of your script. It checks the credentials and exits the script if the administrator permissions are missing.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,4],"tags":[357,356,99,358,133,359,20],"class_list":["post-1376","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-windowsscripts","tag-administrator","tag-check","tag-credentials","tag-permissions","tag-powershell","tag-rights","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=1376"}],"version-history":[{"count":6,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1376\/revisions"}],"predecessor-version":[{"id":1382,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1376\/revisions\/1382"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=1376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=1376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=1376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}