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