Elevated function()

by Jul 10, 2012

Is it posible to elevate a single function call? I know the credentiels for the AD user i want to elevatem so is it possible to do somting like this:

Function RunAsElevated() {
  $credential = New-Object System.Management.Automation.PsCredential($username,$securePassword)
  ElevateSessionRights($credential)
  // Do somthing as elevated user
  ClearSessionElevated()
}