
 
 N A M E 
 
         I n v o k e - A s A d m i n i s t r a t o r 
 
         
 
 S Y N O P S I S 
 
         E x e c u t e   c o m m a n d s   w i t h   e l e v a t e d   A d m i n i s t r a t o r   p r i v i l e g e s . 
 
         
 
         
 
 S Y N T A X 
 
         I n v o k e - A s A d m i n i s t r a t o r   [ - S c r i p t B l o c k ]   < S c r i p t B l o c k >   [ [ - A r g u m e n t L i s t ]   < O b j e c t [ ] > ]   [ - F i l e P a t h   
 
         < S t r i n g > ]   [ - V e r b   < S t r i n g > ]   [ - C a p t u r e d S t r e a m   < I n t 3 2 > ]   [ < C o m m o n P a r a m e t e r s > ] 
 
         
 
         I n v o k e - A s A d m i n i s t r a t o r   [ - C o m m a n d ]   < S t r i n g >   [ - F i l e P a t h   < S t r i n g > ]   [ - V e r b   < S t r i n g > ]   [ - C a p t u r e d S t r e a m   
 
         < I n t 3 2 > ]   [ < C o m m o n P a r a m e t e r s > ] 
 
         
 
         
 
 D E S C R I P T I O N 
 
         T h e   I n v o k e - A s A d m i n i s t r a t o r   f u n c t i o n   e x e c u t e s   a   c o m m a n d   a s   a n   e l e v a t e d   u s e r . 
 
         
 
         I t   d o e s   t h i s   b y   c r e a t i n g   a   c h i l d   p r o c e s s   r u n n i n g   w i t h   A d m i n i s t r a t o r 
 
         p r i v i l e g e s   a n d   p a s s i n g   i t   a   s p e c i a l   c o m m a n d .   T h i s   c o m m a n d   e n c o d e s   t h e 
 
         a r g u m e n t s   t o   t h e   I n v o k e - A s A d m i n i s t r a t o r   f u n c t i o n   u s i n g   . N E T ' s   s e r i a l i z a t i o n 
 
         f r a m e w o r k   a n d   a   b a s e 6 4   e n c o d i n g .   I t   t h e n   c r e a t e s   a   n a m e d   p i p e   t o   i n i t i a t e 
 
         a   c o n n e c t i o n   b a c k   t o   t h e   c h i l d   p r o c e s s ,   w i t h   w h i c h   i t   s e n d s   o u t p u t   f r o m 
 
         t h e   c o m m a n d s   b e i n g   i n v o k e d   -   a g a i n   u s i n g   . N E T ' s   s e r i a l i z a t i o n   f r a m e w o r k   - 
 
         b a c k   t o   t h e   h o s t   p r o c e s s .   T h i s   a l l o w s   u s   t o   e x e c u t e   c o m m a n d s   i n   a n 
 
         A d m i n i s t r a t o r - l e v e l   p r o c e s s   a n d   h a v e   t h e   o u t p u t   a c c e s s i b l e   i n   t h e   h o s t 
 
         t e r m i n a l ,   " j u s t   l i k e   s u d o " . 
 
         
 
         A d d i t i o n a l l y ,   i t   d e f i n e s   a   n u m b e r   o f   f u n c t i o n s   a n d   s h a d o w i n g   a l i a s e s   f o r 
 
         c o m m o n   o u t p u t   c o m m a n d s : 
 
         
 
         -   W r i t e - O u t p u t 
 
         -   W r i t e - E r r o r 
 
         -   W r i t e - D e b u g 
 
         -   W r i t e - V e r b o s e 
 
         -   W r i t e - W a r n i n g 
 
         -   W r i t e - I n f o r m a t i o n 
 
         -   W r i t e - H o s t 
 
         -   W r i t e - P r o g r e s s 
 
         
 
         N a i v e   c a l l s   t o   t h e s e   c o m m a n d s   w i l l   b e   c a p t u r e d   a n d   t h e i r   c o r r e s p o n d i n g 
 
         p a r a m e t e r s   w i l l   b e   s e n t   t o   t h e   h o s t   p r o c e s s ,   w h e r e   t h e   c o r r e s p o n d i n g   " r e a l " 
 
         c o m m a n d   w i l l   b e   c a l l e d . 
 
         
 
 
 
 P A R A M E T E R S 
 
         - S c r i p t B l o c k   < S c r i p t B l o c k > 
 
                 W h e n   d e f i n e d ,   t h i s   g e t s   e v a l u a t e d   i n   t h e   A d m i n i s t r a t o r   p r o c e s s   w i t h   t h e 
 
                 c a l l   o p e r a t o r   ( & ) . 
 
                 
 
                 R e q u i r e d ?                                         t r u e 
 
                 P o s i t i o n ?                                         1 
 
                 D e f a u l t   v a l u e                                 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         - C o m m a n d   < S t r i n g > 
 
                 W h e n   d e f i n e d ,   t h i s   g e t s   e v a l u a t e d   i n   t h e   A d m i n i s t r a t o r   p r o c e s s   w i t h 
 
                 I n v o k e - E x p r e s s i o n . 
 
                 
 
                 R e q u i r e d ?                                         t r u e 
 
                 P o s i t i o n ?                                         1 
 
                 D e f a u l t   v a l u e                                 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         - A r g u m e n t L i s t   < O b j e c t [ ] > 
 
                 A r g u m e n t s   t o   b e   p a s s e d   t o   t h e   s c r i p t   b l o c k . 
 
                 
 
                 R e q u i r e d ?                                         f a l s e 
 
                 P o s i t i o n ?                                         2 
 
                 D e f a u l t   v a l u e                                 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         - F i l e P a t h   < S t r i n g > 
 
                 A n   o p t i o n a l   p a t h   t o   a   P o w e r S h e l l   e x e c u t a b l e .   T h i s   d e f a u l t s   t o   t h e 
 
                 e x e c u t a b l e   b e i n g   u s e d   t o   r u n   t h e   p a r e n t   p r o c e s s ;   h o w e v e r   i t   c a n   b e 
 
                 o v e r r i d d e n   t o   r u n   t h e   A d m i n i s t r a t o r   p r o c e s s   w i t h   a   d i f f e r e n t 
 
                 e x e c u t a b l e   t h a n   t h e   o n e   c u r r e n t l y   r u n n i n g . 
 
                 
 
                 R e q u i r e d ?                                         f a l s e 
 
                 P o s i t i o n ?                                         n a m e d 
 
                 D e f a u l t   v a l u e                                 [ D i a g n o s t i c s . P r o c e s s ] : : G e t C u r r e n t P r o c e s s ( ) . P a t h 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         - V e r b   < S t r i n g > 
 
                 I n   a d d i t i o n   t o   t h e   R u n A s   v e r b ,   e x e s   a l s o   s u p p o r t   t h e   R u n A s U s e r   v e r b .   T h i s 
 
                 a l l o w s   f o r   u s i n g   t h i s   a l t e r n a t e   v e r b . 
 
                 
 
                 R e q u i r e d ?                                         f a l s e 
 
                 P o s i t i o n ?                                         n a m e d 
 
                 D e f a u l t   v a l u e                                 R u n A s 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         - C a p t u r e d S t r e a m   < I n t 3 2 > 
 
                 B y   d e f a u l t ,   t h e   ' e r r o r '   s t r e a m   ( s t r e a m   2 )   i s   c o m p l e t e l y   c a p t u r e d   a n d   a l l 
 
                 E r r o r R e c o r d s   a r e   r e - e m i t t e d   o n   t h e   h o s t   E r r o r   s t r e a m .   T h i s   a l l o w s   f o r 
 
                 c a p t u r i n g   e r r o r s   t h a t   a r e   e m i t t e d   b y   c a l l i n g   $ P S C m d l e t . W r i t e E r r o r   o r   b y 
 
                 n a t i v e   c m d l e t s . 
 
                 
 
                 T h i s   v a l u e   c a n   b e   s e t   t o   c a p t u r e   o t h e r   s t r e a m s .   F o r   e x a m p l e , 
 
                 s e t t i n g   t h i s   v a l u e   t o   6   w o u l d   c a p t u r e   a l l   d a t a   e m i t t e d   o v e r   t h e   I n f o r m a t i o n 
 
                 s t r e a m .   T h i s   b e h a v i o r   c a n   b e   c o m p l e t e l y   d i s a b l e d   b y   s e t t i n g   t h i s   v a l u e   t o   1 
 
                 ( t h e   o u t p u t   s t r e a m ) . 
 
                 
 
                 R e q u i r e d ?                                         f a l s e 
 
                 P o s i t i o n ?                                         n a m e d 
 
                 D e f a u l t   v a l u e                                 2 
 
                 A c c e p t   p i p e l i n e   i n p u t ?               f a l s e 
 
                 A c c e p t   w i l d c a r d   c h a r a c t e r s ?     f a l s e 
 
                 
 
         < C o m m o n P a r a m e t e r s > 
 
                 T h i s   c m d l e t   s u p p o r t s   t h e   c o m m o n   p a r a m e t e r s :   V e r b o s e ,   D e b u g , 
 
                 E r r o r A c t i o n ,   E r r o r V a r i a b l e ,   W a r n i n g A c t i o n ,   W a r n i n g V a r i a b l e , 
 
                 O u t B u f f e r ,   P i p e l i n e V a r i a b l e ,   a n d   O u t V a r i a b l e .   F o r   m o r e   i n f o r m a t i o n ,   s e e   
 
                 a b o u t _ C o m m o n P a r a m e t e r s   ( h t t p s : / g o . m i c r o s o f t . c o m / f w l i n k / ? L i n k I D = 1 1 3 2 1 6 ) .   
 
         
 
 I N P U T S 
 
         
 
 O U T P U T S 
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   1   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   {   " h e l l o   w o r l d ! "   } 
 
         
 
         T h i s   w i l l   e x e c u t e   a   s c r i p t   b l o c k   a s   A d m i n i s t r a t o r   a n d   o u t p u t   t h e   s t r i n g 
 
         " h e l l o   w o r l d ! " . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   2   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   ' " h e l l o   w o r l d ! " ' 
 
         
 
         T h i s   w i l l   e v a l u a t e   a   s t r i n g   a s   A d m i n i s t r a t o r   a n d   o u t p u t   t h e   s t r i n g 
 
         " h e l l o   w o r l d ! " . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   3   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   {   p a r a m ( $ F r i e n d )   " h e l l o   $ F r i e n d ! "   }   - A r g u m e n t L i s t   ' K o r b e n ' 
 
         
 
         T h i s   w i l l   e x e c u t e   a   s c r i p t   b l o c k   a s   A d m i n i s t r a t o r   a n d   p a s s   a n   a r g u m e n t   t o 
 
         i t ,   o u t p u t t i n g   t h e   s t r i n g   " h e l l o   K o r b e n ! " . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   4   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   {   $ E n v : A p p D a t a   } 
 
         
 
         T h i s   w i l l   o u t p u t   t h e   h o s t   u s e r ' s   A p p D a t a   d i r e c t o r y .   V a r i a b l e s   i n   s c r i p t 
 
         b l o c k s   a r e   e v a l u a t e d   b e f o r e   t h e y ' r e   r a n   i n   t h e   A d m i n i s t r a t o r   p r o c e s s . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   5   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   {   t h r o w   ' b a b y '   } 
 
         
 
         T h i s   w i l l   t h r o w   a n   e x c e p t i o n   o n   t h e   h o s t   p r o c e s s .   E x c e p t i o n s   a r e   c a p t u r e d 
 
         a n d   p r o x i e d . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   6   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         I n v o k e - A s A d m i n i s t r a t o r   {   W r i t e - E r r o r   ' t h i s   i s   a   t e s t   e r r o r ! ' ;   W r i t e - I n f o r m a t i o n   ' t h i s   i s   s o m e   
 
         I M P O R T A N T   I N F O R M A T I O N ! ' ;   W r i t e - H o s t   " I ' m   w r i t i n g   t o   y o u r   h o s t ! "   }   6 > & 1 
 
         
 
         T h i s   w i l l   w r i t e   a n   e r r o r   t o   t h e   h o s t   e r r o r   s t r e a m ,   i n f o r m a t i o n   t o   t h e 
 
         i n f o r m a t i o n   s t r e a m   ( r e d i r e c t e d   t o   t h e   o u t p u t   s t r e a m   o n   t h e   h o s t ) ,   a n d 
 
         w r i t e   a   m e s s a g e   d i r e c t l y   t o   t h e   h o s t .   T h e   f u n c t i o n s   W r i t e - O u t p u t , 
 
         W r i t e - D e b u g ,   W r i t e - V e r b o s e ,   W r i t e - W a r n i n g   a n d   W r i t e - P r o g r e s s   w o r k 
 
         s i m i l a r l y . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   7   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   {   G e t - P r o c e s s   - I n c l u d e U s e r n a m e   |   S o r t - O b j e c t   - P r o p e r t y   V M   - D e s c e n d i n g   
 
         |   S e l e c t - O b j e c t   - F i r s t   1   } 
 
         
 
         T h i s   w i l l   g e t   a l l   p r o c e s s e s ,   i n c l u d i n g   p r o c e s s e s   n o t   o w n e d   b y   t h e   u s e r   - 
 
         w h i c h   i s   i n f o r m a t i o n   o n l y   a c c e s s i b l e   t o   t h e   A d m i n i s t r a t o r   -   a n d   t h e n   f i n d 
 
         t h e   o n e   u s i n g   t h e   m o s t   m e m o r y ,   f i n a l l y   s e n d i n g   d a t a   b a c k   t o   t h e   h o s t 
 
         o u t p u t   s t r e a m .   P r o c e s s   o b j e c t s   a r e   n o n - s e r i a l i z a b l e ,   s o   t h e   o b j e c t   r e t u r n e d 
 
         b y   I n v o k e - A s A d m i n i s t r a t o r   i s   a   P S O b j e c t   w i t h   t h e   s a m e   p r o p e r t i e s . 
 
         
 
         
 
         
 
         
 
         - - - - - - - - - - - - - - - - - - - - - - - - - -   E X A M P L E   8   - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
         
 
         P S   C : \ > I n v o k e - A s A d m i n i s t r a t o r   ( G e t - H i s t o r y   - C o u n t   1 ) . C o m m a n d L i n e 
 
         
 
         R e - r u n   t h e   p r i o r   c o m m a n d   w i t h   A d m i n i s t r a t o r   p r i v i l e g e s .   N o t e   t h a t 
 
         C o m m a n d L i n e   i s   a   s t r i n g ,   n o t   a   s c r i p t   b l o c k . 
 
         
 
         
 
         
 
         
 
         
 
 R E L A T E D   L I N K S 
 
         a b o u t _ P s e u d o   
 
         a b o u t _ P S e u d o _ A d m i n i s t r a t o r _ S c o p e   
 
         h t t p s : / / g i t h u b . c o m / j f h b r o o k / P S e u d o 
 
 
 
 
 
 
 
 