Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Checking prerequisites things before filling in parameters

$
0
0

I want to be able to check a few things like if it is running powershell in an elevated mode or a particular user account is being used

e.g

Powershell
If(-NOT([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")){Write-Warning"Powershell is not running as Administrator! Please re-run this script in powershell in Administrator Mode! "Exit}

How would I go about this (if at all) given the sample powershell script below as an example?

Powershell
Param(# Pass the Server name [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]$ServerName)Begin{}Process{# This is a simple get of all instances of CCM_SoftwareUpdate from root\CCM\ClientSDK $MissingUpdates=Get-WmiObject-ClassCCM_SoftwareUpdate...

Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>