Powershell V2 - Futurecom interactive AG

gayheadtibburInternet και Εφαρμογές Web

5 Φεβ 2013 (πριν από 4 χρόνια και 8 μήνες)

316 εμφανίσεις

Fabrice Romelard [MVP]

Intranet


Extranet CTO

SGS


MVP since 2003

ASP.NET 2003
-
2006

SQL Server 2006
-
2008

SharePoint since 2008

French communities member

ASP
-
PHP

Codes Sources

GUSS

SharePoint Expert, SQL Server
DBA and .NET developer

Coworkers SGS at Geneva
(Suisse)

Who know
PowerShell

?


Who know SharePoint ?

What’s SGS ?


What’s
PowerShell

?


What’s New in
PowerShell

V2


PowerShell

and SharePoint

HISTORY
Founded in Rouen in 1878, under the name of
Goldstück
,
Hainzé

& Co.

First registration as
Société

Générale

de Surveillance in
Geneva in 1919

Growth by agglomerations of various companies which
until 2002 had great degree of autonomy

Listed publicly in 1985

Single share structure introduced in 2001

Four significant shareholder groups

Famille

A. Von
Finck


IFIL investment

Allianz SE

FMR Corp


INDUSTRIES
GEOGRAPHIES

Inspection

Verification

Testing

Certification

LEADING
More than
50'000 employees

Europe, Middle East & Africa: 23’000 employees

Americas: 11’300 employees

Asia/Pacific: 15’700 employees

A network of over 1’000 offices & laboratories


AGRICULTURAL

SERVICES

MINERALS

SERVICES

OIL, GAS & CHEMICALS

SERVICES

AUTOMOTIVE

SERVICES

LIFE SCIENCE

SERVICES

INDUSTRIAL

SERVICES

SYSTEMS & SERVICES

CERTIFICATION

GOVERNMENTS

AND
INSTITUTIONS

SERVICES

What’s SGS ?


What’s
PowerShell

?


What’s New in
PowerShell

V2


PowerShell

and SharePoint

New command
-
line shell and scripting language


As
interactive

and
composable

as BASH/KSH


As
programmatic

as Perl/Python/Ruby


As
production oriented
as AS400 CL/VMS DCL


Allows access to data stores as
easy to access
as
filesystem

Automation Frameworks

Automation Frameworks

Automation Frameworks

Cmdlets

In
-
Proc, Local,
Remote

In
-
Proc, Local,
Remote

Runtime Engines

In
-
Proc, Local,
Remote

Runtime Engines

Automation Platform (API)

ScriptingLanguage

Type

Normalizers

Type

Normalizers

Type

Normalizers

Providers

Events,
Jobs,
Transactions

Shells, ISEs, GUI s, Applications

Universal



Interactive or programmatic



Wide range of
OSes



Local or Remote



Single or Multi Machine



Synch or
Asynch



Wide range of authentication


mechanisms



.NET, native code, COM, WMI,
ADSI, XML, ADO,
WebServices
, WSMAN, etc



Simple scripting to systems


programming


Powered by a strong community


Have better solution than standard
«

cmd.exe

» (Evolution of MS
-
DOS)

Replace Perl,
KixStart

or VBScript scripts,
for execute simple tasks


PowerShell

:

Object Oriented

Can use
.Net

objects

Give many command



In classical environment, command
execution results in text


In PowerShell each result is object. We can
use also the attributes and methods



.Net powered


Can call WSH, COM, and WMI objects with
.Net objects


Many Commandlets


Standard in commands and parameters


Version 1.0

Pre
-
requisites
:
Framework
.Net

2.0

Available for:


Windows

Server

2008



A feature



乯琠慶慩l慢a攠i渠n
=
卥牶敲e䍯牥
=
»
=

x㠶
=

x㘴
=

䥁㘴
=
=
Windows Server
2003 SP1



An update between
SP1 and SP2 (KB926139, 140,
141)


=
T漠摯d湬潡o
=

x㠶
=

x㘴
=

䥁㘴
=
Windows

Vista



Update
(KB928439)



To download


x86


x64

Windows XP SP2



Need an

update (KB926139, 140, 141)


=
T漠摯d湬潡o
=

x㠶
=

x㘴
=
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx



PowerShell commands named
«

cmdlets

»


(ie: command
-
applets).


One verb and a name with a dash (
-
),


Generic verb list

(
Get
,
Set
,
Add
,
Remove
, etc.) with diferent name
like
Path
,
Variable
,
Item
,
Object

etc.


Lot of name possible for commands


Diferent

solutions for use
parameters

get
-
command
-
Name [string]
-
Type
[
CommandTypes
]
-
Verb [string]
-
Noun [string]



Use “” if parameter have a space or special
char



First of all: «

Get
-
Command

».


For help:
Get
-
Help
with

command.


More help on command:

«
Get
-
Help
Get
-
Command

detailed

»
with

some

examples


«
Get
-
Help
Get
-
Command

full »
with

all
technical

informations



Command «

Short Name»


Alias «
my_cmd
» for the command «
very
-
long
-
command
-
to
-
write
».


Help
shell

Unix or cmd.exe
users

with

their

uses …

ls
, more,
pwd
, etc.

ls

is

the command alias for
Get
-
ChildItem

which

shows the file or
folder

list
.



A
PowerShell

variable
is

define

by the
prefix

$
with

the
name

and
can

receive

value


We

can

create

the
named

variable $
current
-
process

and store the active
process

list


$current_process = Get
-
Process



Action
between

commands


PowerShell

built

for transition data
between

commands

without

change (more
text

transform
)


Get
-
Process

|
where

{ $_.
handlecount

-
gt
400 } | Format
-
List



Condition in
PowerShell
,
we

can

use
operators

If
,
ElseIf

and
Else

$
current_process

=
Get
-
Process

If

($
current_process.count

-
lt

50)

{



Write
-
Host «

Low

server
load
";

}

Elseif

(($
current_process.count

-
ge

50)
-
and
($
current_process.count

-
lt

80))

{



Write
-
Host «

Middle server
load
";

}

Else

{



Write
-
Host «

High server
load
";

}


We

can

create

loop

in
PowerShell

as
While
,
Do
While
, For or
Foreach
.


$var = 1

// One variable set to 1

while

($var
-
le 50) {$var; $var += 1}

//
while

the
value
is

not
equal

to 50,
we

add

1


for ($var = 1; $var
-
le 50; $i++)
//


{$var}

//
each

steps

we

show the variable value



WMI
objects

Include

in
PowerShell

in standard, no
creation

need

Get
-
WmiObject


list


.NET and COM
objects

Create

a new
object

for a variable

PS C:
\
> $
xls

= New
-
Object
-
ComObject

Excel.Application

We

can

use the
methods

and
properties



Basic Scripts for Services and file management

What’s SGS ?


What’s
PowerShell

?


What’s New in
PowerShell

V2 ?


PowerShell

and SharePoint

Reduce the cost and effort to:

Use PowerShell

Get, learn, share scripts

Layer applications on PowerShell

GUI, web, workflow, etc.

Manage anything/everything

Servers, clients, distributed systems,
applications,
web services
,

cloud services
,

raw
HW, other OSes, everything

Using any and all mechanisms (WMI, .Net,
native code, web services, WSMAN)

Microsoft .NET Framework 2.0


Windows
PowerShell

remoting

et
background jobs needs
WinRM

2.0 CTP3 :
Only for Vista SP1 and W2008


Windows
PowerShell

Integrated Scripting
Environment (ISE) and Out
-
GridView

cmdlet

needs Microsoft .NET Framework 3.5 SP1


Windows
PowerShell

Remoting

1:1 et 1:plusieurs

Background Jobs

Advanced Functions

Modules

Transactions

Script Debugging

Nouvelles

Cmdlets

Windows
PowerShell

Integrated Scripting
Environment (ISE)

Nouveaux
opérateurs

Splatting

(@)

Split

Join


V1

V2

Developer


䍭摬整e⁡湤⽯爠灲潶p摥牳
=

=
䡥ep
=

偯m敲卨敬l=c浤m整e
=
=

T牡湳慣瑩潮⁳異灯牴
=
偯m敲卨敬l
=

=
䍌C
=
☠䅐f
=


=
剩c栠h慮杵慧攠w⽡/c敳s⁴漠
c潭Ⱐ
w浩

⹎整

慤ai
Ⱐ,浬=☠慤o
=
=

=
啴rli瑩敳=瑯t浡湩灵p慴攬⁦潲浡琬a
i浰潲琯數灯mt
=
=


129 Cmdlets



Web service

&

workflow activities



剩c桥爠污h杵慧攠w⽡/c敳s=瑯tw敢es敲癩c敳Ⱐ
畮浡u慧敤ac潤攬o
ws浡m
=
=
=

=
剩c桥爠畴楬i瑩敳=i湣l畤u湧n
敶敮瑩湧
Ⱐ,潢o
c潮瑲潬Ⱐ牥浯瑥r數散畴u潮
=
=


241 Cmdlets



Graphical ISE to create/debug scripts


Users


卩浰m攠慤⁨潣⁳c物灴r
=

卯灨is瑩c慴敤a=灲潤畣瑩潮o
sc物灴r湧
=

卹s瑥浳=灲潧p慭ai湧
=

䅣牯獳畬瑩灬攠浡m桩湥n
=
䍯浭畮u瑹
=

=
t物瑥r慮搠a桡牥hsc物灴r
=

=
t物瑥r慮搠a桡牥h䵯摵M敳
=
V1 Scripts and Cmdlets run on PowerShell V2

Management initiative driven by DMTF

Platform independent, interoperable & industry

standard management solution

CIM based standards for Server and Desktop management

WS
-
Management (WSMAN)


WSMAN


Power control and boot control


HW/ SW inventory


Alerts and lifecycle events


Config
/manage BIOS


Software and Firmware update


Health monitoring

Power Off Command

Invoke
-
WSManAction

-
CN $
svr

-
cred

$
cred

-
port 16992 `

-
Auth digest
CIM_ComputerSystem

`


䅣瑩潮
=
剥煵敳瑓瑡t敃桡湧e
=
}
=

卥p散瑯牓整
=
䁻乡浥k?
䵡湡M敤卹s瑥t
≽=}
=
-
v慬略卥t
=

剥煵敳瑥摓瑡瑥
㴢㌢=
=
Chassis

Class

Get
-
WSManInstance
-
CN $svr
-
cred $cred
-
port 16992
-
Auth digest
-
enum CIM_Chassis

Chip Class

Get
-
WSManInstance


CN $
srv

-
cred

$
cred

-
port 16992
-
Auth digest
-
enum

CIM_Chip

Power On Command

Invoke
-
WSManAction

-
CN $
svr

-
cred

$
cred

-
port 16992 `

-
Auth digest
CIM_ComputerSystem

`


Action

RequestStateChange

`


SelectorSet

@{Name="
ManagedSystem
"} `

-
valueSet

@{
RequestedState
=“2"}




Remote WMI


Remote Command/Script Execution


Remote Background Jobs


Remote Interactive Session

-
ComputerName

<string[]> # txt format list

-
Throttle <
int
> # fix parallel session number

-
AsJob

#
execut

in background


PS>
gwmi

-
CN (cat servers.txt)
Win32_Bios
-
Throttle 64
|


Select __Server, Name, Manufacturer, Version |


ConvertTo
-
Html > BiosInventory.htm



PS> $job =
gwmi

-
CN (cat servers.txt) Win32_Bios
-
Throttle
64

AsJob

PS> Wait
-
job $j # or go do something else

PS> Receive
-
Job $j | Select __Server, Name, Manufacturer,
Version |
ConvertTo
-
Html > BiosInventory.htm


xxxxx

What’s SGS ?


What’s
PowerShell

?


What’s New in
PowerShell

V2 ?


PowerShell

and SharePoint

Load the SharePoint DLL

[
System.Reflection.Assembly
]::
LoadWithPartialName
("
Microsoft.S
harePoint
") > $null


Set the variable

$site = new
-
object
Microsoft.SharePoint.SPSite
(“http://myWebApp”)


Use the MSDN site as the .NET SharePoint
Development


Scripts for SharePoint management

Technical Blog

http://blogs.developpeur.org/fabrice69/

Online Articles

http://www.asp
-
php.net

SharePoint Management
PowerShell

scripts

http://sharepointpsscripts.codeplex.com

PowerShell

Blogs

http://blogs.technet.com/powershell/

http://blogs.msdn.com/powershell/

http://scriptingof.blogspot.com/



14


15
avril

2010, CICG


Classic
Sponsoring Partners

Premium
Sponsoring Partners