May 10, 2009

Power WebPart 3.0 – Runas-System

In general code in SharePoint runs with the privileges of the current user, but sometimes you need to run code with elevated privileges. The SharePoint object model covers this scenario with the SPSecurity.RunWithElevatedPrivileges. In Power WebPart you can use the “Runas-System” function to run script with elevated privileges. Usage: Runas-System –script
Example 1: Output Current Identity
function render($writer)
{
   $identiy1 = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
   $identiy2 = Runas-System "[System.Security.Principal.WindowsIdentity]::GetCurrent().Name"

   $writer.Write($identiy1)
   $writer.Write($identiy2)
}
Example 2: Call a Function with Parameters
function Render-Identity($writer)
{
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
    $writer.Write($identity)
}  
function render($writer)
{
   Render-Identity $writer
   Runas-System "Render-Identity `$writer"
}
Example 3: Call a Function with Return Value
function Get-Identity
{
    return [System.Security.Principal.WindowsIdentity]::GetCurrent().Name 
}

function render($writer)
{
   $identity1 = Get-Identity
   $identity2 = Runas-System "Get-Identity"

   $writer.Write($identity1)
   $writer.Write($identity2)
}
Example 4: Impersonate SPWeb
function render($writer)
{
   $writer.Write($web.CurrentUser.LoginName)

    $impersonatedWeb = Runas-System "Get-SPWeb $($web.Url)"
    $writer.Write($impersonatedWeb.CurrentUser.LoginName)
    $impersonatedWeb.Dispose()
}

17 comments:

lin liyi said...

Kids that want to get honest though chanel replica handbags Chanel medication eye glasses enjoy analyzing, bifocals, monovision along with varifocals, a very good set to look into is simply not that local picture hold; definitely, it doesn't possibly even want to result in the household. Caused by concept, every they should be achieve is without a doubt first start up ones own Laptop or pc to check out Chanel medication eye glasses web based and even auto-magically steps brought about a large submission site in website pages that comes with some of these replica rolex glasses. They may flick through every one of online sites and even buy a shop with the best selection easy for unique stylish glasses designed for medication fake hublot watches. Designed for quite a few discounted Chanel medication swiss replica rolex, you can even examine web based picture outlets that comes with quite possibly the most delightful bargains and even advertisements for a lot of stylish eyewear. Belonging to the most recently released design to help you quite a lot of 40's versions which will countless adult females in recent times can be checking available designed for, each individual are available around the cartier replica uk. And also a lot of these, press announcements browse fails to really sell-it in addition customises eye glasses to stay in that implied standard designed for prospect static correction.

swiss replica watches said...

Edmond Jaeger made an incredible ultra-thin class, and he / she inhibited Switzerland watchmakers for making these. It was eventually Jacques-David LeCoultre, Antoine's grandson, whom required task and been successful. Your LeCoultres added their outstanding view developing art skills, even nevertheless Jaeger, an outstanding developer, provided their own combined level shows a classic fashion that's the unshakable Jaeger-LeCoultre name. This unique alliance afforded replica watches UK climb to a couple horological secret, and likewise in 1937 the exact Jaeger-LeCoultre type themselves. Each independently in conjunction with jointly the two of these adult adult males forged relationships by making use of adequately regarded makers regarding best replica Patek Philippe watches luxury timepieces. Via 1902, then for many thirty a long time then, LeCoultre & Cie formulated replica audemars piguet O'Neal watches view movements with regards to Patek Philippe connected with Geneva. Ahead connected with Jaeger together high quality Replica Breitling Watches with replica Balenciaga Giant handbags LeCoultre commenced working in concert, Jaeger can't experienced amidst his clientele the exact renowned custom made Cartier.

pdf digital signature said...

I have learned so much from your post. I would definitely bookmark your site to be updated with your upcoming articles. Great job! So much information.

Олег Кієнко said...

I am very enjoyed for this blog. http://topassignmentwriters.com/Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. I think it may be help all of you. Thanks a lot for enjoying this beauty blog with me. I am appreciating it very much! Lhttp://topassignmentwriters.com/ooking forward to another great blog. Good luck to the author! all the best!http://topassignmentwriters.com/

amine lahragui said...

Your work is very good and I appreciate you and hopping for some more informative posts. happy new year 2016 new year 2016 happy new year 2016 images feliz año nuevo 2016 imagenes de año nuevo 2016 feliz año 2016 happy new year images 2016

Bogdan Yanov said...

The postings on your site are always excellent. Thanks for the great share and keep up this great work! All the best to you. look at my profile

Hug Day said...

happy hug day Images
hug day 2016 Wishes cards greetings
Hug day Gift Ideas For Him/Her
hug day sms for bf

风骚达哥 said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
hollister
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
converse
prada outlet
reebok shoes
true religion
burberry outlet

Movers5th In said...

For Finest Movers and Packers in Hyderabad
For Top Movers and Packers in Bangalore

For Greatest Movers and Packers in Pune
For Foremost Movers and Packers in Mumbai

For Leading Movers and Packers in Delhi
For Premier Movers and Packers in Gurgaon

Fangyaya said...

louis vuitton handbags
tory burch shoes
adidas trainers
christian louboutin sneakers
nike roshe flyknit
louis vuitton handbags
toms wedges
concord 11
asics shoes for women
oakley outlet
coach outlet
adidas shoes
basketball shoes
michael kors outlet
michael kors outlet
christian louboutin outlet
michael kors outlet
jordan shoes
kate spade outlet
coach outlet online
coach outlet store
beats by dre
oakley vault
celine outlet
michael kors outlet online
ray ban sunglasses outlet
jordan concords
michael kors outlet online
gucci outlet online
christian louboutin sale
toms wedges
abercrombie clothing
michael kors outlet online
toms outlet
rolex watches
red bottom shoes
celine handbags
michael kors outlet online
abercrombie & fitch outlet
louis vuitton purses
20168.8chenjinyan

dada24 Xu said...

ugg outlet
christian louboutin shoes
ray ban sunglasses
birkenstock sandals
oakley sunglasses
ralph lauren outlet online
coach outlet
oakley sunglasses outlet
kate spade
ugg boots
2061921caiyan

chenlina said...

louis vuitton
coach factory outlet
christian louboutin uk
golden state warriors jerseys
uggs outlet
michael kors purses
canada goose outlet
cheap jordan shoes
uggs sale
hermes bags
chenlina20160923

Ashok Malik said...

packers and movers gurgaon
packers and movers noida
packers and movers delhi
packers and movers delhi
packers and movers mumbai
packers and movers kolkata
packers and movers chennai
packers and movers delhi

Meiqing Xu said...

ugg boots on sale
converse outlet
rolex daytona
polo ralph lauren outlet online
coach outlet
cheap nfl jerseys
timberland boots outlet
rolex watches
true religion jeans
gucci outlet
2016121caiyan

Globeservations said...

Check out the internet’s greatest source for cat names or look find the perfect for girl cat names and boy cat names.

raybanoutlet001 said...

cheap basketball shoes
ugg outlet
nike store
ray ban sunglasses outlet
ugg boots
ray ban sunglasses outlet
oakley sunglasses
ralph lauren uk
cheap ugg boots
ray ban sunglasses outlet

Home Improvement NYC said...

Ajrin Construction Inc. is a licensed New York general construction firm working as General Contractors in NYC, truly devoted to our services and remain firm until our Clients’ purposes are served to satisfaction. We feel much concerned of the value of your property, safety and security more than our profit or anything else.Home Improvement NYC