SlideShare a Scribd company logo
1 of 341
Download to read offline
1
Windows PowerShell による
Windows Server 管理 V 4.0 2014.3.13 版
日本マイクロソフト株式会社
エバンジェリスト
安納 順一
http://blogs.technet.com/junihia/
第1部 基礎から学ぼう
Part1 基礎の基礎編
Part2 リモーティング編
Part3 バックグラウンドジョブ編
Part4 ワークフロー編
Part5 開発者編
第2部 Hyper-V の管理
Part1 Hyper-V の立ち上げまで
Part2 ライブマイグレーション
2
第1部 PowerShell を基礎から学ぼう
Part1 基礎の基礎編
Part2 リモーティング編
Part3 バックグラウンドジョブ編
Part4 ワークフロー編
Part5 開発者編
3
第1部 ~ PowerShell を基礎から学ぼう
Part1 基礎の基礎編
1.Windows PowerShell の位置づけ
2.基本的なコマンドレットと書式の基礎
3.基本的な文法とスクリプトの作り方
4.Tips
Part2 リモーティング編
5.リモーティングの準備と基礎
6.-ComputerNameを使用したリモート操作
7.PS セッションとは
8.コネクションの永続化と再利用可能なPSセッション
9.Windows PowerShell Web Access(PSWA)
Part3 バックグラウンドジョブ
10. バックグラウンドジョブ
Part4 ワークフロー編
11. Windows PowerShell Workflow とは
12. Windows PowerShell Workflow の基礎
13. ワークフロー特有の記述
14. ワークフロージョブとデータの永続化
Part5 開発者編
15. 開発者にとっての Windows PowerShell とは
16. 開発者のための Windows PowerShell 基礎知識
17. 開発者として必要な情報の取得
18. コマンドレット以外からオブジェクトのインスタン
スを作成する
19. Visual Studio(C#)から PowerShell を呼び出す
Windows PowerShell には他にもさまざまなテクニックが用意されています。特に、バック
グラウンドジョブの概念はシステム管理を行う上で重要です。
4
Part 1 基礎の基礎編
5
基礎編
1. Windows PowerShell の位置づけ
6
Windows PowerShell の位置づけ
Windows Familiar – インフラエンジニアから見ると
• Windows Script(WSH)に変わる管理プラットフォーム
• 高機能なスクリプティング機能による自動管理
• WinRM を介したリモートサーバー管理
Windows Familiar – 開発者 から見ると
• 高機能なクラスライブラリ
• コーディング、テスティングの大幅なコスト削減
Non-Windows Familiar から見ると
• OMI(Open Management Infrastructure)を実装したリモートサーバー
• 手元のプラットフォームからリモート管理が可能
• 使い慣れた言語からリモート管理が可能
7
代表的なスクリプト言語
バッチファイル(拡張子 .bat)
VBScript(拡張子 .vbs)
PowerShell(拡張子 .ps1)
Jscript(拡張子 .js)
MS-DOS時代から使われてきたコマンドシェル上のスクリプト。脈々と現代に引き継がれて
おり、利用者が多い。豊富なコマンド群によって支えられており、案外使い出がある。複数
のスクリプトを取りまとめる役割としても便利。
Visual Basic のスクリプト版。「Visual」とあるが、Visual ではない。わかりやすい文法と、
緩い規則によって根強いファンが多い。亜種として VBA もあるが微妙に文法は異なる。
JavaScript のMS 実装版として、VBScript とともに登場。JavaScript を Microsoft の独自
仕様によって拡張することで、汎用性を増している。
いわずと知れた高機能スクリプト言語。.NET Framework が使えると言うメリットから、利
用者は爆発的に増殖中。多くの製品がPowerShell用のコマンドレットを提供しており、
Windows Script Host は Server Coreのメニュー程度でしかお目にかかれなくなりつつある。
Windows
Script
今後エンハンスの予定は無い
OSに合わせて継続的なエンハンス
今後エンハンスの予定は無い
8
Windows
.NET Framework
PowerShell スクリプト
exe
bat VBScript JScript
Script Engine
CLR(共通言語ランタイム)
Class Library
スクリプトの実行環境
PowerShell エンジン
COM
cmd/
command
Windows Script Host
Cscript.exe Wscript.exe
C
O
M
9
コマンドシェルの進化と機能の包含
cmd.exe
command.com
高機能
NT
低機能
DOS/
Win31 2000
XP/2003
Vista/2008
Windows Script Host
PowerShell 上では
bat/vbs/js も実行可能
Win9x/
Me
Win7/
2008R2
Windows PowerShell
8
100
200
約
2300
コマンドレットの数
10
VBScript vs PowerShell
Exchange 2003 (VBScript) Exchange 2007(PowerShell)
メール
ボックス
統計
Set listExchange_Mailboxs =
GetObject("winmgmts:{impersonationLevel=impersonate}!¥¥COMPUTERNAME¥ROOT¥MicrosoftExchangeV2").InstancesOf("Excha
nge_Mailbox")
For Each objExchange_Mailbox in listExchange_Mailboxs
WScript.echo "AssocContentCount =” + objExchange_Mailbox.AssocContentCount
WScript.echo " DateDiscoveredAbsentInDS =” + objExchange_Mailbox.DateDiscoveredAbsentInDS
WScript.echo " DeletedMessageSizeExtended =" + objExchange_Mailbox.DeletedMessageSizeExtended
WScript.echo " LastLoggedOnUserAccount =" + objExchange_Mailbox.LastLoggedOnUserAccount
WScript.echo " LastLogoffTime =" + objExchange_Mailbox.LastLogoffTime
WScript.echo " LastLogonTime =" + objExchange_Mailbox.LastLogonTime
WScript.echo " LegacyDN =" + objExchange_Mailbox.LegacyDN
WScript.echo " MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayName
WScript.echo " MailboxGUID =" + objExchange_Mailbox.MailboxGUID
WScript.echo " ServerName =" + objExchange_Mailbox.ServerName
WScript.echo " Size =" + objExchange_Mailbox.Size
WScript.echo " StorageGroupName =" + objExchange_Mailbox.StorageGroupName
WScript.echo " StorageLimitInfo =" + objExchange_Mailbox.StorageLimitInfo
WScript.echo " StoreName =" + objExchange_Mailbox.StoreName
WScript.echo " TotalItems =" + objExchange_Mailbox.TotalItems
Next
get-mailboxstatistics
–server $servername
データ
ベース
管理
Dim StorGroup as New CDOEXM.StorageGroup
StorGroup.DataSource.Open "LDAP://" + DCServer + "/ CN=First Storage Group,CN=InformationStore,CN=" +
Server + ",CN=Servers,CN=First Administrative Group, CN=Administrative Groups,CN=First Organization,
CN=Microsoft Exchange,CN=Services, CN=Configuration," + DomainName
StorGroup.MoveLogFiles("C:¥newlogPath", 0)
move-storagegrouppath
-identity "First Storage
Group"
–log "C:¥newlogPath"
受信者
管理
Dim objMailbox As CDOEXM.IMailboxStore
Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName)
objMailbox.CreateMailbox "LDAP://" + DCServer + "/CN=Private MDB,CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group, CN=Administrative
Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services, CN=Configuration," + DomainName
enable-mailbox
-identity domain¥FOO
–database "First Storage
Group¥Private MDB"
11
WBEM - Web Based Enterprise Management
http://www.dmtf.org/standards/wbem
マイクロソフトやインテル、シスコシステムズ、旧コンパック・コンピュータなどによって提案され、標準化
団体DMTF(Desktop Management Task Force)によって標準化された規格である。その名の通り、「Web ベー
スのエンタープライズ管理」のための仕様であり、ネットワーク上に存在するサーバーや OS、ネットワーク
機器などの統合管理に必要なプロトコルやデータ構造を規定する。要するに、従来の SNMP(Simple Network
Management Protocol)や syslog に代わる、HTTP と XML をベースとした新世代のネットワーク管理プロトコ
ルである。すでにマイクロソフト Windows や HP-UX などのおもなOSをはじめ、サーバー製品、ストレージ製
品、ネットワーク機器、そしてHP OpenView をはじめとするネットワーク管理ツールにおいて、業界標準の
ネットワーク管理プロトコルとしてサポートされている。
出典 http://h50146.www5.hp.com/products/software/oe/hpux/developer/column/smh_02/
12
出典 http://h50146.www5.hp.com/products/software/oe/hpux/developer/column/smh_02/
HP における
WBEM の実装
13
出典
http://docs.oracle.com/cd/E19455-01/806-
7119/6jg10nqef/index.html
Solaris における WBEM の実装
14
Microsoft の
実装
15
History of Microsoft Management Framework
2000年 Windows 2000 に WMI をインプリメント
– 29 WMI プロバイダを含む
– 同時に Windows NT, 98, 95 用の WMI もダウンロード開始
(15 WMI プロバイダー)
※どちらかといえば ”プロバイダー” 提供ベンダー向けのテクノロジー
※ Windows ファミリ間の相互運用性に留まる
2005年 WS-Management が DMTF へ提出、承認
2007年 Windows Server 2008 に WS-Management を実装(WinRM)
• HTTP/S を介して他プラットフォームとの接続が可能に
• Windows PowerShell で WinRM を介したリモートサーバー管理が標準手法
として取り込まれる
WS-Management とは Web Services
for Management のこと。Windows
Server ではない。
16
Windows Management Framework
http://www.microsoft.com/downloads/
前提条件
• Windows PowerShell ISE がインストールされていること
• Microsoft .NET Framework 4.0 がインストールされていること
OS WMF 3.0 WMF 4.0
Windows 7 SP1 以降 SP1 以降
Windows Server 2008 SP2 以降 ×
Windows Server 2008 R2 SP1 以降 SP1 以降
Windows 8 標準 8.1にアップグレード
Windows 8.1 ー 標準
Windows Server 2012 標準 ○
Windows Server 2012 R2 ー 標準
17
Windows Management Framework
Windows Management Framework
IT Pro IT Developer
Solution
Developer
Storage Network DevicesCPU
Windows PowerShell
CIMOM、SMI-S
標準化されたアクセス
標準化されたプロトコル
標準化された
オブジェクトモデル
WS-Management(WinRM)
(Web Service for Management) http
他の
プラットフォーム
Service
Provider
開
発
WS-Man
CIMOM、
SMI-S
SMI-S(Storage Management Initiative - Specification)
誰が作るの?
18
The Open Group Membership 2012/10/5 時点
Platinum - 5
• Capgemini Netherlands
• Hewlett-Packard USA
• IBM USA
• Kingdee Software (China) Co. Ltd China
• Oracle Corporation USA
Gold – 44(抜粋)
• Microsoft Corporation USA
• NTT Data Corporation
• ReGIS Inc.
Silver – 256 (Japan のみ抜粋)
• Asahi Techneion Co., Ltd
• AXE, Inc.
• eflow Inc.
• Information-technology Promotion Agency,
Japan
• Japan Aerospace Exploration Agency (JAXA)
• Mizuho Information and Research Institute, Inc.
• Nissan Motor Co., Ltd.
• Nomura Research Institute, Ltd.
• Rococo Co Ltd
• SIOS Technology, Inc.
• Sony CSL
• Symphony Ltd.
Academic – 38 (Japan のみ抜粋)
• Aoyama Gakuin University
• Kyoto University
• Nagoya University
• The University of Tokyo Information Technology
Center
19
Open Management Infrastructure(nanoWBEM)
• オープンソース版 CIM Server
• 軽量 250KB、C で開発されている
Windows PowerShell、その他
Providers : CIMOM,SMI-S
WS-Management(OMI)
Providers : CIMOM,SMI-S
Storage Network DevicesCPUStorage Network DevicesCPU
WS-Management(WinRM)
各種言語
WinRM Client
WinRM Server
OMI Client
OMI Server
20
21
OMI サポート プラットフォーム
• HP-UX 11i v2 and v3 (PA-RISC and IA64)
• Sun Solaris 8 and 9 (SPARC) and Solaris 10 (SPARC and x86)
• Red Hat Enterprise Linux 4 (x86/x64) and 5 (x86/x64) Server
• Novell SUSE Linux Enterprise Server 9 (x86) and 10 SP1 (x86/x64)
• IBM AIX v5.3 and v6.1 (POWER)
• MacOS 10.5 (Intel)
• Windows(限定的)
最新版は OMI Source - v.1.0.7a (2013年5月)
22
http://www.opengroup.org/
23
マイクロソフト製品と Windows PowerShell の関係
• 製品ごとに専用の”コマンドレット”が用意されている
• 多くの管理 GUI は裏でコマンドレットを呼んでいる
• インフラ担当者に、各製品への”標準化されたアクセス方法”を提供する
Active Directory
Active Directory
PowerShell Module
Active Directory
管理センター
Hyper-V
Hyper-V
PowerShell Module
System Center
Virtual Machine Manager
PowerShell
コンソール
24
Windows PowerShell ISE
• Powershell_ise.exe
• Windows PowerShell 専用エディタ
• IntelliSense に対応
スクリプトエディタ
スクリプト実行画面
コマンドレットを直接実行
コ
マ
ン
ド
レ
ッ
ト
検
索
英語圏の人たちは”アイス”
と読むらしい
25
基礎編
2. 基本的なコマンドレットと書式の基礎
26
事前準備
• コンソールの環境設定
• 簡易編集を有効に
• エクスプローラー(フォルダー)の環境設定
• 「拡張子を表示しない」を無効に
• 実行ポリシーの設定
※オンプレミスの”署名無しスクリプト”を実行できるようにする
• リモートからの操作を有効にする(リモーティングの有効化)
• 必要に応じて自分専用の初期設定ファイルを作成(規定では存在しない)
PS C:¥>Set-ExecutionPolicy RemoteSigned
PS C:¥>Enable-PSRemoting –force
PS C:¥>notepad $profile
27
実行ポリシーの設定~ Set-ExecutionPolicy
• “管理者として実行” する必要がある
• 実行ポリシー
– Restricted:制限つき (オペレーターモード)(規定値)
• 対話形式のみ
• スクリプトは実行できない
– AllSigned:署名
• スクリプトは、信頼された発行元による署名が必要
– RemoteSigned:リモートの署名(2012R2 の規定値)
• “インターネットゾーン” のスクリプトは信頼された発行元による署名が必要
– Unrestricted:無制限
• すべてのスクリプトを実行可能
• リモートのスクリプトについては常に警告
– Bypass:バイパス
• 何もブロックされず警告も表示されない
http://technet.microsoft.com/ja-jp/library/dd347628.aspx
“ポリシーの設定”は、規定では
コンピューター全体に影響する。
適用範囲を制限するには、
Scope も同時に定義する。
28
コマンドレットの構造
Checkpoint-VM
Compare-VM
Export-VM
Get-VM
Import-VM
Measure-VM
Move-VM
New-VM
Remove-VM
Rename-VM
Repair-VM
Restart-VM
Resume-VM
Save-VM
Set-VM
Start-VM
Stop-VM
Suspend-VM
<動詞>-<名詞>
(例)
29
コマンドレットとモジュール
• PowerShell の実行単位は「コマンドレット」
• コマンドレットはモジュール(Module)によって提供される
• モジュールが読み込まれていないとコマンドレットを使用することは
できない(Import-Module <モジュール名>)
Module
CmdLet
CmdLet
CmdLet
CmdLet
Hyper-V
Add-VMDvdDrive
Add-VMFibreChannelHba
Add-VMHardDiskDrive
Add-VMMigrationNetwork
Add-VMNetworkAdapter
Add-VMNetworkAdapterAcl
・
・
・
Microsoft.PowerShell.
Management
Add-Computer
Add-Content
Checkpoint-Computer
Clear-Content
Clear-EventLog
Clear-Item
Clear-ItemProperty
Complete-Transaction
構造 規定のモジュール 例
30
モジュールに関するコマンドレット
• 読み込まれているモジュール一覧の取得
• 使用可能なモジュール一覧の取得
• モジュールを読み込む
• 使用可能なモジュールを全て読み込む
PS C:¥> Get-Module
PS C:¥> Get-Module -ListAvailable
PS C:¥> Import-Module <モジュール名>
PS C:¥> Import-Module Hyper-V
PS C:¥> Import-Module (Get-Module -ListAvailable).Name
31
コマンドレット情報を取得する
• 使用可能なコマンドレット一覧を取得する
• “-VM” という文字列を含むコマンドレットの一覧
• 特定のモジュール内のコマンドレット一覧
• コマンドレットの書式
PS C:¥> Get-Command
PS C:¥> Get-Command *-vm* -CommandType Cmdlet
PS C:¥> Get-Command -Module Hyper-V
PS C:¥> Get-Help <コマンドレット> -detailed
PS C:¥> Get-Help Move-VM -detailed
32
コマンドレットにはエイリアスが用意されているものがある
• 入力の簡易化
• DOSコマンドやLinux系シェルとの互換性
• エイリアスの一覧を取得する
エイリアス
PS C:¥> Get-Alias
33
コマンドレットの戻り値
• コマンドレットの戻り値は“オブジェクト”である
• PowerShell はオブジェクトを操作する言語
• 戻り値を「どのように操作できるか」を知っていることが重要
• オブジェクトには「メソッド」と「プロパティ」が用意されている
戻り値を直接、”操作”することが可能
Get-Service サービス一覧
オブジェクト
stop()
34
操作
メソッド
メソッド
プロパティ
プロパティ
もしも”オブジェクト”が自転車だったら...
色
サイズ
型
ブランド
パーツ
ペダルをこいで前に進む
ハンドルを右に切る
ハンドルを左に切る
フロント ブレーキをかける
リア ブレーキをかける
35
メソッドプロパティ
もしも”オブジェクト”が「Windows のサービス」だったら。。。
DisplayName
Status
DependentServices
Stop()
Start()
Pause()
MachineName
Windows
サービス
36
メソッドとプロパティを調べるには
• コマンドレットのメソッドとプロパティを表示
※ COMのメンバーも取得できる
New-Object -com scripting.filesystemobject | Get-Member
• サービスに対して行える操作を取得する
• 仮想マシンに対して行える操作を取得する
<コマンドレット> | get-member
<コマンドレット> | get-member | sort-object Name | format-list
Get-Service | Get-Member
Get-VM | Get-Member
37
TIPS オブジェクトであるということは...
PS C:¥>$a = “abc”
#普通ならば $a は”文字列” になるけれど...
#オブジェクトだからメソッドとプロパティが用意されている
PS C:¥>$a.ToUpper()
PS C:¥>ABC
PS C:¥>$a.ToUpper().Split("B")[0]
PS C:¥>A
38
コマンドからの出力もオブジェクト化される
PS C:¥> (ipconfig)[18].Split(":")[1].Trim()
object
ipconfig の
出力結果
の18行目
(0から数えて)
IPv4 アドレス . . . . . . . . . . : 192.168.1.100
ipconfig の出力結果からIPアドレスを取りだす
コロンで分割した
(0から数えて)2
つ目の値 前後の空白を
トリミング
39
PSドライブ
ファイルシステムだけではなく、さまざまなオブジェクトがドライブとしてアク
セス可能(CD コマンドで移動可能)
モジュールが読み込まれて
いないと使えないドライブ
もある
(例)ActiveDirectory
 ファイルシステム
 エイリアス(Alias:)
 レジストリ(HKLM:、HKCU:)
 証明書(Cert:)
 環境変数(Env:)
 変数(Variable:)
 WSMAN設定(Wsman:)
 Active Directory(AD:)
 IIS(IIS:)
 Remote Desktop Service(RDS:)
PS C:¥> Get-PSDrive
40
基礎編
3. 基本的な文法とスクリプトの作り方
さまざまな使用例から使い方を学びましょう
41
スクリプトの拡張子は .ps1
$Server = $env:COMPUTERNAME
$Adapter = "1"
Do {
$NIC = (Get-NetAdapter)[$Adapter] | Select-Object InterfaceDescription
$NICName = $NIC.InterfaceDescription.Replace("#","_")
$NICName = $NICName.Replace("(","[")
$NICName = $NICName.Replace(")","]")
$Perf = Get-Counter -Counter "¥¥$Server¥Network Interface($NICName)¥bytes total/sec"
$TimeStamp = $Perf.Timestamp.ToString()
$PValue = $Perf.CounterSamples.CookedValue * 8 / 1024 / 1024
$PerfData = $TimeStamp + "," + $Server + "," + $NICName + "," + [int]$PValue
$PerfData
} While(-1)
GetNetCounter.ps1
C:¥tmp> .¥GetNetCounter.ps1
42
1. 起動中のサービス一覧
 パイプライン
 Where-Object による条件指定
2. 特定のサービスを停止する
 () でオブジェクトを表現する
3. ネットワーク情報を取得する
 出力結果のフォーマット変換
4. ネットワークの設定を変更する
5. ローカルコンピューター名を変更する
 変数の宣言
 変数の遅延展開
 Array 値
 ハッシュテーブル
 環境変数
6. リモートからコンピューター名を変更する
※標準コマンドレット or WMI
 クレデンシャルの使い方
 WMI に必要なアクセス権
7. ドメインに参加させる
※標準コマンドレット or WMI
8. 複数のコンピューターをドメインに参加させる
 スクリプトの継続行
 ファイルの入出力方法
 ファイルのコード変換
 CSV のヘッダー行について
 繰り返し処理
9. イベントログを収集する
 Select-Object により必要な要素のみを取り出す
10. イベントログをバックアップする
11. 独自のイベントログを登録する
12. 仮想マシンを作成して起動する
 スクリプトの引数を定義する
 名前付き引数
13. Hyper-V ライブマイグレーションを実行する
14. パフォーマンスログを取得する
15. 役割と機能をインストールする
16. 仮想ドメインコントローラを複製する
17. Hyper-V 仮想スイッチを作成する
18. リモートコンピューターから機能を一括で削除する
19. リモートコンピューターを一括でシャットダウンする
20. すべての Hyper-V ホストの仮想マシンを強制的にシャッ
トダウンする
21. すべてのHyper-V ホストのライブマイグレーションを有効
化する
43
PS C:¥>get-service | where-object {$_.Status -eq "Running"}
1.起動中のサービス一覧を取得する
パイプ
サービス一覧
を出力
object
サービス一覧
オ
ブ
ジ
ェ
ク
ト
の
ま
ま
渡
さ
れ
る
object
サービス一覧
44
PS > Get-Service | Where-Object Status -EQ "Running" | Select-Object Name,
Servicetype | Sort-Object ServiceType
コマンドレット1 コマンドレット2
入力パラメタ
コマンドレット3
結果 結果
入力パラメタ
• サービスの一覧を取得
• Status が Running のみを抽出
• Name プロパティとServiceType プロパティを抽出
• ServiceType でソート
オブジェクト
パイプラインについて
PS > Get-Service | Where-Object {$_.Status -EQ "Running"} | Select-Object
-Property Name, Servicetype | Sort-Object -Property ServiceType
V3ではこう書ける
45
TIPS 条件を指定して結果を絞り込む Where-Object
#サイズが1024バイト以上のファイルを検索する
Dir | Where-Object {$_.length -GT 1024} `
|Select-Object Name,length
#Active Directory のユーザー名に”a”を含むユーザーを取得する
Get-ADUser -Filter * `
|Where-Object {$_.name -Like “*a*”} `
| ForEach-Object name
46
TIPS PS 3.0 では書式を簡略化できます
PS C:¥>get-service | where-object {$_.Status -eq "Running"}
PS C:¥>get-service | where-object Status -eq "Running"
V3 ではこう書ける
47
2.特定のサービスを停止する
PS C:¥>(Get-Service -Name WSearch).Stop()
メソッド
Windows Search サービスの
インスタンスを取得
object
Windows Search
インスタンスに対して
メソッドを実行
PS C:¥>Stop-Service WSerarch
48
TIPS()で括るとオブジェクトを表す
#Dir の出力結果の最初の行から
#Nameプロパティだけを取り出す
(dir)[0].Name
#変数を使用すると以下のように書き換えられる
$D = Dir
$D[0].Name
49
3.ネットワーク情報を取得する
PS C:¥> Get-NetAdapter | FL Name, InterfaceIndex, MacAddress
PS C:¥> Get-NetIPAddress -InterfaceIndex 28 -AddressFamily IPv4
ネットワークアダプタの一覧
IP アドレスの取得
Format-List の略
50
TIPS 出力結果のフォーマットを変換
dir | format-table Name,Length
dir | format-list Name,Length
dir | format-wide Name -column 6
dir | out-gridview
51
4.ネットワークの設定を変更する
PS C:¥>New-NetIPAddress -InterfaceIndex 24 -IPAddress 192.168.205.102
-AddressFamily IPv4 -PrefixLength 24 -DefaultGateway 192.168.205.254
PS C:¥> Remove-IPAddress -InterfaceIndex 24 -AddressFamily IPv4
静的なIPV4アドレスを設定する
IP アドレスの削除
PS C:¥>Set-DnsClientServerAddress -Interface 24
-ServerAddress 192.168.205.1, 192.168.205.3
DNS の設定
既存の静的アドレスを変更する場合には Set-NetIPAddress を使用する
PS C:¥> Set-DnsClientServerAddress -Interface 24 -ResetServerAddress
DNSの設定を削除する
PS C:¥> Set-NetIPInterface -InterfaceIndex 24 -Dhcp Enabled
DHCP を有効にする
52
5.ローカルコンピューター名を変更する
PS C:¥> $Env:ComputerName
ローカルコンピューター名の取得
PS C:¥> (Get-WmiObject -Class Win32_ComputerSystem).Name
PS C:¥> $New_ClientName = “New_ClientName”
PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem
PS C:¥> $SysInfo.Rename($New_ClientName)
PS C:¥> Restart-Computer
ローカルコンピューター名の変更
方法1
方法2
C:¥> Rename-Computer -NewName “tfwin8-xx” -Force -Restart
WMI を使用する場合
標準のコマンドレットを使用する場合
53
TIPS 変数を使うには
$FirstName = "Junichi"
$LastName = "Anno"
$FullName = $FirstName + " " + $LastName
Write-Output $FullName
$arrFullName = $FullName.Split(" ")
Write-Output $arrFullname[0]
PS C:¥> C:¥hogehoge.ps1
Junichi Anno
Junichi
出力結果
54
TIPS 変数の宣言について
通常は自動判別
PS > $A = 1
PS > $B = “1”
PS > $A + $B
2
PS > $B + $A
11
PS > $A = “abc”
PS > $A + $B
abc1
System.Int32
System.String
先にある System.Int32 に自動変換
先にあるSystem.String に自動変換
System.String で置き換えが可能
自動変換できない値で
あればエラーとなる
55
明示的に宣言することも可能
PS > [System.Int32] $A = 1
PS > [System.String] $B = “abc”
PS > [System.Array] $C = “今年は”, 2012, “年です”
PS > $A = 987.654
PS > $A
988
PS > $A = “Hello”
Cannot convert value "Hello" to type "System.Int32“
PS > [System.String] $A = “Hello”
明に宣言すると自動変換はできない
Int32 にキャストされる
0: 今年は
1: 2012
2: 年です
[System.String]
[System.Int32]
[System.String]
56
変数を削除する
PS > [System.Int32] $A = 1
PS > Remove-Variable A
PS > Get-Variable | Remove-Variable
自分で作成した変数を全て削除
※削除できないものについてエラーが出る
57
TIPS 変数の展開について
PS >$FirstName = "Junichi"
PS >$LastName = "Anno"
PS >$FullName = “$FirstName $LastName”
PS >Write-Output $FullName
Junichi Anno
PS >$FullName = ‘$FirstName $LastName’
PS >Write-Output $FullName
$FirstName $LastName
ダブルクオーテーションで
括った場合は変数は展開さ
れる
シングルクオーテーション
で括った場合には変数は展
開されない
58
TIPS 変数の遅延展開
PS > $Name = “Junichi”
PS > $Message = “Hello $Name”
PS > $Message
Hello Junichi
PS > $Name = “Junichi”
PS > $Message = { “Hello $Name” }
PS > $Name = “Taro”
PS > $Message
Hello $Name
PS > & $Message
Hello Taro
{} で括ると変数は展開されない
Echo の代わりに & を使用
通常
遅延展開
$Message を定義した後で $Name に値を入れているこ
とに注意
この時点で変数は展開される
59
PS > $Message = { Param( $Name ) “Hello $Name” }
PS > & $Message Junichi
Hello Junichi
遅延展開を利用して関数として定義
60
TIPS Array 値
PS > $Users = @()
PS > $Users = “Junichi”, ”Naoko”, “Kazunori”
PS > $Users.Count
3
PS > $Users
Junichi
Naoko
Kazunori
PS > $Users += “Maki”
PS > $Users += 512
PS > $a = { [system.math]::Pow( 2, $N ) }
PS > $Users += $a
Array の作り方
空のアレイを作成(あえてしなくてもよい)
値を追加
数値を追加
遅延展開変数を追加
{}で括っているので遅延展開変数
61
Array 値の参照
PS > $Users[3]
Maki
PS > $Users[-1]
PS > $N = 6
PS > & $Users[5]
64
PS > Foreach ($u in $Users) { New-ADUser -Name $u }
PS > $Users[2..4]
PS > ($Users -eq “Kazunori”).Count
PS > $Users -ne “Kazunori”
PS > $Users -like “*M*”
$users から値を取りだし
ながらユーザーを作成
配列の2番から4番を取りだす
遅延展開変数の入った行を参照
配列の一番最後
Kazunori 以外のものを抽出
kazunori と一致するものがあるかどうかを検査
M が含まれる行を抽出
62
PS > $arrINT = 1,2,3,4,5,6,7,8,9
PS > $arrINT -ge 5
PS > $Users += $arrINT
PS > $Users | Sort-Object $_
PS > $Users = $Users -ne “Kazunori”
PS > [System.Array]::Reverse($Users)
2つの配列を合成
昇順に並べ替えて出力
Kazunori を削除
Users の中の並び順を逆にする
2つの配列を合成
63
空白を文字列で埋める(PadLeft / PadRight)
## $N[] に、001 ~ 100 の文字列を格納する
PS > $N = @()
PS > 001..100 | % { $N += ("$_").Padleft(3,"0")}
PS > User$N
001
002
・
100
PS > $VMs = $N | % {echo VM$_}
PS > $VMs
VM001
VM002
・
VM100
64
TIPS HashTable
PS > $Users = @{}
PS > $Users.0001 = “Junichi”
PS > $Users.”0001” = “Junichi”
PS > $Users.Add( “0001”, “Junichi” )
PS > $Users.Remove(“0001”)
HashTable の作り方
注意 Array は ()
キー 1 に 値 Junichi を登録
キー 0001 に 値 Junichi を登録
キー 0001 の行を削除
65
PS > $USDJPY = Import-CSV -Path C:¥tools¥USDJPY.csv –Encoding Default
PS > $HT = @{}
PS > While ( $i -lt $USDJPY.Count ) {$HT.Add( $USDJPY.日付[ $i ], $USDJPY.終値
[ $i ] ) ; $i++ }
PS > $HT.”2012/2/10”
77.65
CSV ファイルから値を読み込んでHashTable を作成
66
TIPS 環境変数の取得
#環境変数の一覧を取得
cd env:
dir
#特定の環境変数を取得
$env:computername
$env:username
$env:userdomain
$env:SessionName
67
6.コンピューター名を変更する(リモートから)
##スタンドアロンのコンピューターの場合
PS C:¥> $ClientName = “ClientName”
PS C:¥> $Cred = Get-Credential
PS C:¥> $New_ClientName = “New_ClientName”
PS C:¥> Rename-Computer -ComputerName $ClientName -LocalCredential $Cred
-NewName $New_ClientName -Force -Restart
##ドメインに参加しているコンピューターの場合
PS C:¥> $ClientName = “ClientName”
PS C:¥> $Cred = Get-Credential
PS C:¥> $New_ClientName = “New_ClientName”
PS C:¥> Rename-Computer -ComputerName $ClientName -DomainCredential $Cred
-NewName $New_ClientName -Force -Restart
標準のコマンドレットを使用する
68
PS C:¥> $ClientName = “ClientName”
PS C:¥> $Cred = Get-Credential
PS C:¥> $New_ClientName = “New_ClientName”
PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem
-ComputerName $ClientName -Credential $Cred
PS C:¥> $SysInfo.Rename($New_ClientName)
PS C:¥> Restart-Computer -ComputerName $ClientName -Credential $cred -Force
WMI を使用する
Server Client変更
WMI
69
TIPS クレデンシャルの作成
その1
PS C:¥> $Cred = Get-Credential
その2
PS C:¥> $user = “administrator“
PS C:¥> $pass = ConvertTo-SecureString "P@ssw0rd“
-AsPlainText -Force
PS C:¥> $Cred = New-Object
System.Management.Automation.PSCredential $user, $pass
ポップアップが表示される
70
TIPS WMI Tester
http://technet.microsoft.com/en-us/library/cc782719(v=ws.10)
• WMI への接続性をテストするツール
• リモートコンピューターへの接続も
テストできる
71
TIPS 非ドメインメンバーから WMI接続 が拒否される原因と対処
代表的なエラー番号
• 0x800706ba
• 0x80041003
• 0x80070005
代表的な原因
• Firewall の設定
• アクセス権
72
必要なアクセス権
• Distributed COM Users メンバーである
こと
• (規定では)システム管理者であること
※wmimgmt.msc で変更可能
73
必要な Firewall の設定
• Windows Management Instrumentation のルール
74
7.ドメインに参加させる
PS C:¥> $Domain = “tf.com”
PS C:¥> $Client = “ClientComputer”
PS C:¥> $LocalCred = Get-Credential junichia
PS C:¥> $DomainCred = Get-Credential tf¥administrator
PS C:¥> $Admin = “tf¥administrator”
PS C:¥> $Pass = “P@ssword”
PS C:¥> Add-Computer -ComputerName $Clienit -LocalCredential $Cred
-Credential $DomainCred -DomainName $Domain -OUPath “OU=営業部” -Restart -Force
Server
AD Domain
参加指示 Client Client
Workgroup
Client
標準のコマンドレットを使用する
75
PS C:¥> $Domain = “tf.com”
PS C:¥> $Client = “ClientComputer”
PS C:¥> $Cred = Get-Credential junichia
PS C:¥> $Admin = “tf¥administrator”
PS C:¥> $Pass = “P@ssword”
PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem
-ComputerName $ClientComputer -Credential $Cred -Authentication PacketPrivacy
PS C:¥> $SysInfo.JoinDomainOrWorkgroup($Domain, $Pass, $Admin, “OU=xx”, 3 )
PS C:¥> Restart-Computer -ComputerName $Client -Credential $Cred -Force
認証に関する通信を暗号化する
これを指定しないと以下のエラー
“Client connection to WINMGMT
needs to be encrypted for this
operation. Please adjust your
IWbemServices proxy security settings
and retry. ”
1: ドメインに参加
+
2: コンピューターアカウントの作成
WMIのクラスを直接使用する
76
8.複数のコンピューターをドメインに参加させる
# 各種定数の設定
$Cred = Get-Credential junichia
$Domain = "tf.com"
$Admin = "tf¥administrator"
$Pass = "P@ssword"
# いったん、SJISで作成したファイルを読み込み、UNICODEで保存する
$InputFile = "C:¥Tools¥Computers.csv"
$OutputFile = "C:¥Tools¥Computers_unicode.csv"
Get-Content $InputFile -Encoding String | Out-File $OutputFile -Encoding unicode
# CSVファイルを読み込む
$Computers = Import-Csv -Path $OutputFile -Header ComputerName,IPAddress,Department -Delimiter ","
# コンピューター名と部署を取り出し、ドメインに参加させる
ForEach ($c in $Computers)
{
$Client = $c.ComputerName
$OU = "OU=" + $c.Department + ",DC=TF,DC=COM
$SysInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Client `
-Credential $Cred -Authentication PacketPrivacy
$SysInfo.JoinDomainOrWorkgroup($Domain, $Pass, $Admin, $OU , 3 )
Restart-Computer -ComputerName $Client -Credential $Cred -Force
}
ServerCSV Client Client
tfwin8-01,192.168.205.101,経理部
tfwin8-02,192.168.205.102,営業部
・
・
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
77
TIPS 行継続
アクサン グラーブ記号 (`) を使用する
copy-item C:¥tmp¥*.txt `
-destination C:¥
こ
い
つ
78
TIPS 入出力方法
#標準出力
Write-Output “Hello”
Echo “Hello”
#標準入力
$InputData = Read-Host
#ファイルに出力
Out-File -filepath C:¥tmp¥list.txt -inputobject
$Record
#ファイルから入力
$file = Get-Content -Path c:¥tmp¥list.txt
$file = type c:¥tmp¥list.txt
#CSVファイルから入力
$file = Import-CSV -Path c:¥test.csv
これを抑えておけば、ひとまずたいていのことはできます
79
TIPS 出力方法の違い
PS C:¥> 1 + 2 + 3
6
PS C:¥> Echo “Windows PowerShell”
Windows PowerShell
PS C:¥> Write-Output 1 + 2 + 3
1
+
2
+
3
PS C:¥> Echo Windows PowerShell
Windows
PowerShell
空白で区切られる
PS C:¥> Windows PowerShell
<エラー>
※ Echo は Write-Output のAlias
PS C:¥> “1” + “2” + “3”
123
80
TIPS ファイルのコード変換
SJIS作成したファイルは日本語が正しく扱われないことがある
∴ Get-Content で読み込み、Out-File でUnicodeで保存する
Get-Content -Path $Input -Encoding String | `
Out-File -Encoding UNICODE
指定可能な文字コード
String
Unicode
Byte
BigEndianUnicode
UTF8
UTF7
UTF32
Ascii
Default
Oem
81
TIPS Import-CSV でのヘッダーの取り扱いについて
• 規定では、1行目はヘッダーとして扱われる
• ヘッダーが無い場合には -Header パラメタで指定可能
• -Header を指定すると1行目はデータとして扱われる
• ヘッダー単位(列単位)で取り出しが可能
ComputerName, IPAddress, Department
tfwin8-01,192.168.205.101,経理部
tfwin8-02,192.168.205.102,営業部
・
・
$Computers = Import-Csv -Path $OutputFile -Header ComputerName,IPAddress
$Computers.IPAddress
82
TIPS Out-GridView を使用して出力結果をながめる
入力したグリッド形式データを参照するための EXCEL VIEWER 的ツール
Import-CSV -Path $File | Out-GridView
83
TIPS 繰り返し処理1
#ForEach-Object
Get-ADUser -Filter * | ForEach-Object {$_.name}
Get-ADUser -Filter * | ForEach-Object name
#foreach
$Users = Get-ADUser -Filter *
foreach ($user in $Users) { $user.name }
Active Directory ユーザー一覧から name プロパティをリストする
V3
84
TIPS 繰り返し処理2
#1から10までを出力
1..10
#1から10 をリダイレクトして出力
1..10 | % {echo $_ }
#User1 から User10 を作成
1..10 | % {New-ADUser “User$_” }
※ % は foreach のエイリアス
85
TIPS 繰り返し処理3
$i = 0
do
{
Write-Host $i
$i++
}
while ($i -lt 10)
$i = 0
do
{
Write-Host $i
$i++
}
until ($i -ge 10)
86
9.イベントログを収集する
C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -Newest 10
リモートコンピューターのセキュリティログから、最新10個のログを取りだす
特定の日時範囲のログを取りだす
C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -After “2012/6/1
00:00:00” -Before “2012/6/1 00:10:00”
特定のイベントIDを取りだす
C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -InstanceID 4632
失敗した監査を取りだす
C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -EntryType FailureAudit
メッセージに “ログオン” という言葉が含まれているログを取りだす
C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -Message “*ログオン*”
87
C:¥> Get-EventLog -LogName Application | Group-Object -Property EntryType
-NoElement
イベントログを集計する
C:¥> Get-EventLog -LogName Application |Group-Object -Property Source,EntryType
-NoElement | Select-Object Name,Count
88
TIPS Select-Object で必要な要素のみを取りだす
結果から必要な要素だけを抜き出して処理する
パイプの後ろで使用することをお勧め(なんかおかしい...)
PS C:¥> $Data = Dir
× PS C:¥> Select-Object -InputObject $Data -Property Name
○ PS C:¥> $Data | Select-Object -Property Name
重複データを除く
$data |Select-Object -Unique -Property Name
最後の10個だけ取得
$data | Select-Object -Last 10
最初の5個だけ取得
$data | Select-Object -First 5
89
10. イベントログをバックアップする
C:¥> $logFileName = "Security"
C:¥> $exportFileName = "C:¥tmp¥" + $logFileName + (get-date -f yyyyMMddhhmmss) + ".evt"
C:¥> $exportfilename
C:¥> $logFile = Get-WmiObject Win32_NTEventlogFile | Where-Object {$_.logfilename -eq
$logFileName}
C:¥> $logFile.backupeventlog($exportFileName)
セキュリティイベントログをローカルにバックアップする(EVT形式)
PowerShell は管理者モードで起動してください
90
11.独自のイベントログを登録する
C:¥> New-EventLog -Source "TechFielders" -LogName "TechFielders"
ログファイル名 TechFielders、イベントソース TechFielders を新規に登録する
C:¥> Write-EventLog -LogName TechFielders -Source “TechFielders”
-EntryType Information -EventId 5963 -Message “元気出せこの野郎!1,2,3 ダァ!"
TechFielders ログにイベントログを書き込む
91
12. 仮想マシンを作成して起動する
param([string] $VMName = "NA", [int] $CPU = 1, [int] $Mem = 10MB)
echo -InputObject $VMName, $CPU, $Mem
$SwitchName = "Intel(R) 82579LM Gigabit Network Connection - Virtual Switch"
New-VM -BootDevice CD `
-MemoryStartupBytes $Mem `
-Name $VMName `
-SwitchName $SwitchName `
-VHDPath ¥¥junichia-vdi¥$VMName¥$VMName.vhdx
Set-VM -ProcessorCount $CPU -DynamicMemory -Name $VMName
Add-VMNetworkAdapter -VMName $VMName -SwitchName $SwitchName
Start-VM -Name $VMName
1
2
3
4
5
6
7
8
9
10
11
PS C:¥> .¥CreateVirtualMachine.ps1 -VMName “VM01" -Mem 1024mb
CreateVirtualMachine.ps1
92
TIPS 引数を受け取る
Write-Output $args[3]
foreach ( $a in $args )
{
Write-Output $a
}
C:¥> .¥hogehoge.ps1 My name is “Junichi Anno” .
5つの引数
My
name
is
Junichi Anno
.
Junichi Anno
93
TIPS 名前付き引数の使い方(Param 句)
param([string] $UserID = “ID", [string] $Password =“PASS")
Write-Output $userid
Write-Output $Password
引数を所定の名前の変数に格納することで、文法チェック等が行いやすくなる
C:¥> .¥hogehoge.ps1 -userid anno
anno
PASS
実行結果
規定値
94
13. Hyper-V ライブマイグレーション
$Source = “HostSV01”
$Dist = “HostSV02”
$VMs = get-vm -ComputerName $Source -Name VM*
foreach ($VMName in $VMs.Name) {
Move-VM -ComputerName $Source -Name $VMName -DestinationHost $Dist
}
Guest
メモリ内データ
¥¥Server¥Share¥xxx.vhdx
構成情報 Guest
Host01 Host01
$Source の中の VM で始ま
るゲストOSを検索している
95
14. パフォーマンスログを取得する
Do
{
$perf =Get-WmiObject -Class win32_perfformatteddata_perfos_processor `
-Property PercentProcessorTime
foreach ($p in $perf) {
$outrec = "Processor" + $i + ":" + $p.PercentProcessorTime
echo $outrec
}
Start-Sleep -Seconds 1
cls
} while (-1)
1
2
3
4
5
6
7
8
9
10
11
プロセッサー(コア単位)の利用率を1秒に1回取得して表示する
1秒スリープ
画面をクリア
目的のパフォーマンスカウン
タ(今回はCPU使用率)が含ま
れているWMIクラスを指定する
96
TIPS パフォーマンスカウンターの調査方法
パフォーマンスカウンタークラスの一覧を取得するには
win32_perfformatteddata_perfos_processor クラスが持ってい
るカウンターの一覧を取得する
C:¥> Get-CimClass Win32_PerfFormatted* |ft CimClassName
C:¥> Get-CimClass Win32_PerfRaw* |ft CimClassName
C:¥> $PerfMon = Get-CimClass Win32_PerfFormattedData_perfos_processor
C:¥> $PerfMon.CimClassProperties |ft Name
97
$Server = $env:COMPUTERNAME
$Adapter = "1"
Do {
$NIC = (Get-NetAdapter)[$Adapter] | Select-Object InterfaceDescription
$NICName = $NIC.InterfaceDescription.Replace("#","_")
$NICName = $NICName.Replace("(","[")
$NICName = $NICName.Replace(")","]")
$Perf = Get-Counter -Counter "¥¥$Server¥Network Interface($NICName)¥bytes total/sec"
$TimeStamp = $Perf.Timestamp.ToString()
$PValue = $Perf.CounterSamples.CookedValue * 8 / 1024 / 1024
$PerfData = $TimeStamp + "," + $Server + "," + $NICName + "," + [int]$PValue
$PerfData
} While(-1)
ネットワークアダプターのログを取得する
1
2
3
4
5
6
7
8
9
10
11
12
13
98
15. 役割と機能をインストールする
役割/機能の一覧を取得する
C:¥> Get-WindowsFeature
C:¥> Get-WindowsFeature |Select-Object Name
99
PS C:¥> Add-WindowsFeature -Name User-Interfaces-Infra -IncludeAllSubFeature
-IncludeManagementTools
ServerCore にすべての GUI をインストールする(フルインストール)
PS C:¥> Add-WindowsFeature –Name Server-gui-mgmt-infra -IncludeManagementTools
ServerCore に管理ツールだけをインストールする(MinShell)
100
(参考)Windows Server 2012 GUI オプション
Server Core MinShell Server W/GUI Desktop Experience
コマンドプロンプト Available Available Available Available
Windows PowerShell Available Available Available Available
サーバーマネージャー Not Available Available Available Available
MMC Not Available Available Available Available
コントロールパネル Not Available Not Available Available Available
コントロールパネル内
のアプレット
Not Available Some Available Available Available
Windows Explorer Not Available Not Available Available Available
タスクバー Not Available Not Available Available Available
通知エリア Not Available Not Available Available Available
Internet Explorer Not Available Not Available Available Available
ヘルプ Not Available Not Available Available Available
テーマ Not Available Not Available Not Available Available
スタートスクリーン Not Available Not Available Not Available Available
WinRTアプリ Not Available Not Available Not Available Available
メディアプレーヤー Not Available Not Available Not Available Available
101
ServerManager モジュールでサポートされている
コマンドレット
PS C:¥> Import-Module ServerManager
PS C:¥> Get-Command -Module ServerManager
Alias Add-WindowsFeature servermanager
Alias Remove-WindowsFeature servermanager
Function Disable-ServerManagerStandardUserRemoting servermanager
Function Enable-ServerManagerStandardUserRemoting servermanager
Cmdlet Get-WindowsFeature servermanager
Cmdlet Install-WindowsFeature servermanager
Cmdlet Uninstall-WindowsFeature servermanager
102
16. DC を複製する
Windows Server 2012 以降では、仮想化されたドメインコントローラーを複製して展
開することがでる。
Hyper-V
ホスト
DC02 DC03Export
DC01
(pdc)
(条件)
• 複製元はPDCエミュレーターであってはならない
• 複製元は Clonable Domain Controllers グループのメンバーでなくてはならない
• Hyper-V ホストは Windows Server 2012
• DCは Windows Server 2012
VHD Import
Hyper-V
ホスト
Hyper-V
ホスト
103
$SourceDC = "DC02"
$DistDC = "DC03"
$distPDCEmu = DC01"
$HyperVHost = “ITCAMP-TMP"
Move-ADDirectoryServerOperationMasterRole -Identity $distPDCEmu -OperationMasterRole PDCEmulator
Get-ADComputer $SourceDC | %{Add-ADGroupMember -Identity "Cloneable Domain Controllers" -Members
$_.samAccountName}
Invoke-Command -ComputerName $SourceDC -ScriptBlock { Get-ADDCCloningExcludedApplicationList -GenerateXml
-Force }
$SB = "New-ADDCCloneConfigFile -Static `
-IPv4Address ""192.168.210.51"" `
-IPv4DNSResolver ""192.168.210.50"" `
-IPv4SubnetMask ""255.255.255.0"" `
-IPv4DefaultGateway ""192.168.210.254"" `
-CloneComputerName " + $DistDC + `
" -SiteName ""Default-First-Site-Name"""
Invoke-Command -ComputerName $SourceDC -ScriptBlock { $SB }
Stop-VM $SourceDC
新しいドメインコンローラーの
構成ファイルを作成
PDCエミュレーターを複製元となるDC以外に移動
複製元DCをClonable Domain Controllers グループのメンバーにする
複製元DCをシャットダウン
104
つづき
Get-VM $SourceDC | %{ Export-VM $_ -Path C:¥VMs}
Start-VM -Name $SourceDC
$CFG = (Dir “C:¥VMs¥$SourceDC¥Virtual Machines¥*.xml”).FullName
md E:¥$DistDC
Import-VM -Path "$CFG" -ComputerName $HyperVHost -GenerateNewId -Copy
-VhdDestinationPath E:¥$DistDC
Get-VM $SourceDC |Where-Object {$_.State -EQ "Off"} | Rename-VM -NewName $DistDC
Start-VM $DistDC
複製元DCをエクスポート
複製元DCを起動
エクスポートした仮想マシンをインポート
VMの名前が複製元と同じになってしまうので、変更する。ここでは同じHyper-Vホストを使用して
いるので、OffになっているほうのDCを変名している。
複製先を起動。起動後自動的にDC間複製が始まる。
105
17. 仮想スイッチを作成する
$PCName = "itcamp-pc01"
Invoke-Command -ComputerName $PCName -ScriptBlock {New-VMSwitch -Name "External" `
-AllowManagementOS $True -NetAdapterInterfaceDescription "Intel(R) 82579LM Gigabit Network Connection"}
New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Public" -SwitchType Private
New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-CorpNet" -SwitchType Private
New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Storage" -SwitchType Private
New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Internet" -SwitchType Private
New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-HA" -SwitchType Private
106
18. リモートコンピューターから機能を一括で削除する
Workflow RemoveFOCsWF {
$PCs = Import-Csv -Path pclist.txt -Header "PC","IP"
foreach -Parallel ($pc in $PCs) {
Write-Output -InputObject $pc.pc
Remove-WindowsFeature -ComputerName $pc.pc Failover-Clustering -IncludeManagementTools -
Restart
}
}
RemoveFOCsWF
ワークフローを使用してリモートコンピューターからフェールオーバークラス
タリングを削除する
itcamp-pc01,192.168.210.1
itcamp-pc02,192.168.210.2
itcamp-pc03,192.168.210.3
itcamp-pc04,192.168.210.4
itcamp-pc05,192.168.210.5
itcamp-pc06,192.168.210.6
・
・
107
19. リモートコンピューターを一括でシャットダウンする
Workflow RestartAllPCsWF {
$PCs = Import-Csv -Path pclist.txt -Header "PC","IP"
foreach -Parallel ($pc in $PCs) {
Write-Output -InputObject $pc.pc
##Restart-Computer -PSComputerName $pc.PC -Force
Stop-Computer -PSComputerName $pc.PC -Force
}
}
RestartAllPCsWF
itcamp-pc01,192.168.210.1
itcamp-pc02,192.168.210.2
itcamp-pc03,192.168.210.3
itcamp-pc04,192.168.210.4
itcamp-pc05,192.168.210.5
itcamp-pc06,192.168.210.6
・
・
108
20. すべての Hyper-V ホストの仮想マシンを強制的にシャットダウン
Workflow StopAllVMs {
$PCs = Import-Csv -Path pclist.txt -Header "PC","IP"
foreach -Parallel ($pc in $PCs){
##Get-VM -ComputerName $pc.pc |Start-VM
Get-VM -ComputerName $pc.pc |Stop-VM -Force
}
}
itcamp-pc01,192.168.210.1
itcamp-pc02,192.168.210.2
itcamp-pc03,192.168.210.3
itcamp-pc04,192.168.210.4
itcamp-pc05,192.168.210.5
itcamp-pc06,192.168.210.6
・
・
ワークフローを使用して一斉にシャットダウン
109
21. すべての Hyper-V ホストのマイグレーション設定を有効化
Workflow DisableMigrationWF {
$PCs = Import-Csv -Path c:¥tools¥ps¥HOLSetup¥pclist.txt -Header "PC","IP"
foreach -Parallel ($pc in $PCs) {
##Disable-VMMigration -ComputerName $pc.pc
##Set-VMHost -ComputerName $pc.pc -VirtualMachineMigrationAuthenticationType CredSSP `
-MaximumVirtualMachineMigrations 2 -UseAnyNetworkForMigration $true
Enable-VMMigration -ComputerName $pc.pc
Set-VMHost -ComputerName $pc.pc -VirtualMachineMigrationAuthenticationType Kerberos `
-MaximumVirtualMachineMigrations 2 -UseAnyNetworkForMigration $True
}
}
DisableMigrationWF
itcamp-pc01,192.168.210.1
itcamp-pc02,192.168.210.2
itcamp-pc03,192.168.210.3
itcamp-pc04,192.168.210.4
itcamp-pc05,192.168.210.5
itcamp-pc06,192.168.210.6
・
・
110
基礎編
5. その他の Tips
その他、知っていると便利な使用法について
111
True と False の指定
$True と $False は予約語である
C:¥> $MyNameIsJunichi = $True
C:¥> If ($MyNameIsJunichi -eq $True) {Echo 1}
1
112
日時を取得(Date オブジェクト)
Date
Day
DayOfWeek
DayOfYear
Hour
Kind
Millisecond
Minute
Month
Second
Ticks
TimeOfDay
Year
DateTime Add
AddDays
AddHours
AddMilliseconds
AddMinutes
AddMonths
AddSeconds
AddTicks
AddYears
CompareTo
Equals
GetDateTimeFormats
GetHashCode
GetType
GetTypeCode
IsDaylightSavingTime
Subtract
ToBinary
ToFileTime
ToFileTimeUtc
ToLocalTime
ToLongDateString
ToLongTimeString
ToOADate
ToShortDateString
ToShortTimeString
ToString
ToUniversalTime
プロパティ メソッド
PS C:¥> (Date).Year
2012
PS C:¥> (date).adddays(10)
24年 5月 23日 12:49:10
113
unix のあのコマンドは?
ls → get-ChildItem
cp → copy-Object
grep → select-String
sort → sort-Object
man → help
clear → clear-Host
cat → get-Content
kill → stop-Process
tee → tee-Object
tail → get-Content
「アレはあるかな?」と思った
ら
Get-Alias <unix 上のコマンド>
エイリアス tail は登録されてい
ないので、自分で登録する必要
がある(後述)。
114
Get-Content で Tail を模してみる
## 新しく追加された行を待ち合わせて表示
gc .¥test.txt -wait -tail 0
## テキストファイルの5行目から10行目までを表示
(gc .¥test.txt)[4..9]
## テキストファイルの最初の5行を表示
gc .¥test.txt -totalcount 5
## テキストファイルの最後の5行を表示
gc .¥test.txt | Select-Object -Last 5 ← 時間がかかる可能性があるので –tail をお勧め
gc .¥test.txt -tail 5
## 新しく追加された行に特定の文字列が含まれていたら表示
gc .¥test.txt -wait | Select-String -Pattern ^a
115
tail を Get-Content の Alias として登録する
Set-Alias tail Get-Content
一時的に使用する(現在のコンソール上でのみ)場合は以下のように入力
永続化するには、以下のようにプロファイルに書き込む
Add-Content $profile "Set-Alias tail get-content" -Force
116
基礎編
6. エラー処理
117
エラー処理の要素
1. エラー発生時のアクションとエラーの取得
 $ErrorActionPreference と $Error 変数
 -ErrorAction と -ErrorVariable パラメタ
2. より細かい処理の定義
 Try…Catch…Finally
118
$ErrorActionPreference
• エラー発生時の処理を判断するための環境変数
– Continue
• 規定値。エラーを表示するが処理は継続する。
– SilentlyContinue
• 処理は継続するが、エラーは表示しない
– Stop
• エラーを表示し、処理を停止する
– Inquire
• ユーザーに継続処理を問い合わせる
119
$Error
• 発生したエラーメッセージが蓄積される
1つ目のエラー
2つ目のエラー
• アレイ値である
PS C:¥> $Error.Count
PS C:¥> $Error[15]
120
コマンドレット(関数)単位にエラーを取得するには
• -ErrorAction または –EA
• -ErrorVariable または -EV
121
より詳細なエラー処理
Try{
}
Catch{
}
Finally{
}
処理の本体
エラー発生時の処理
終了時の処理(エラー発生にかかわらず実行される)
122
Part 2 リモーティング編
123
Agenda ~リモーティング編
6. リモーティングの基礎
7. PS セッション
• セッションと PS セッション
• テンポラリ PS セッション
8. 接続の永続化と再利用可能な PS セッション
9. Windows PowerShell Web Access
124
リモーティング編
6. リモーティングの準備
125
OS
リモーティングを有効にする
• 個々の PC で有効にする
PS C:¥>Enable-PSRemoting –force
WinRM
WindowsFirewall
Listener
受付窓口要求を透過
WindowsManagement
処理を受付
port 5985
126
Enable-PSRemoting とネットワークプロファイルの関係
※PowerShell 3.0 の場合
Windows Server 系
ドメイン
• ADドメインに参加
• DCと通信可能
プライベート
• DCと通信不可能
• ワークグループ
• 自宅、職場
パブリック
• インターネット
• 公共ネットワーク
Windows Client 系
WinRM 有効
ネットワークのプロファイル
WinRM 有効
WinRM 有効
WinRM 有効
同じサブネットのコン
ピューターに対しては
WinRM 有効
SkipNetworkProfileChec
k パラメタを指定して実行
すれば同じサブネットの
コンピューターに対して
有効になる
パブリックプロファイルの Firewall の制限をすべて取り払うには以下のコマンドで
Set-NetFirewallRule -Name “WINRM-HTTP-In-TCP-PUBLIC” -RemoteAddres Any
http://technet.microsoft.com/en-us/library/hh849694.aspx
127
• グループポリシーを使用する
[コンピューターの構成]-[ポリシー]-[管理用テンプレート]-[Windows コンポーネント]
└[Windows リモート管理(WinRM)]
WinRM リスナを作成
128
WinRM サービスを自動起動にする
129
Windows Firewall で WinRM の要求を受信する
[コンピューターの構成]-[ポリシー]-[Windows の設定]-[セキュリティの設定]
└[セキュリティが強化されたWindowsファイアウォール]
└[セキュリティが強化された Windows ファイアウォール(-------)]
└[受信の規則]
130
131
管理できるソースとターゲットを制限する(必要に応じて)
管理用のIPアドレス(ター
ゲット側)を指定
管理用のIPアドレス(ソース
側)を指定
132
リモーティングの設定を確認する
PS C:¥> cd WSMan:
PS WSMan:¥> cd localhost¥Listner¥Listener_1084132640
PS WSMan:¥localhost¥Listener¥Listener_1084132640> dir
WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Listener¥Listener_1084132640
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String Address *
System.String Transport HTTP
System.String Port 5985
System.String Hostname
System.String Enabled true
System.String URLPrefix wsman
System.String CertificateThumbprint
System.String ListeningOn_1038621592 10.168.133.49
System.String ListeningOn_1770022257 127.0.0.1
System.String ListeningOn_1055432771 192.168.205.1
System.String ListeningOn_1414502903 ::1
System.String ListeningOn_894013609 2001:4898:0:fff:0:5e...
System.String ListeningOn_1270366863 fe80::5efe:10.168.13...
System.String ListeningOn_1565265845 fe80::5efe:192.168.2...
System.String ListeningOn_2078661606 fe80::25a7:4656:665e...
System.String ListeningOn_1147683958 fe80::fc39:ec3b:d823...
PS WSMan:¥localhost¥Listener¥Listener_1084132640>
Listener 名は環境に
よって異なります
133
ドメイン外のコンピューターを操作するには
操作元の「TrustedHost」リストにターゲットコンピューターを追加する
※「ターゲット」を管理対象としてもいいかを明記するってこと
Active Directory ドメイン
Or ワークグループ
ワークグループ or
Active Directory ドメイン
OSCredential で認証
WinRM
WindowsFirewall
Litener
WindowsManagement
Trusted
Hosts
操作元 ターゲット
134
PS C:¥> Get-Item wsman:¥localhost¥Client¥TrustedHosts
WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Client
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String TrustedHosts
PS C:¥> Set-Item wsman:¥localhost¥Client¥TrustedHosts 192.168.205.* -Concatenate
WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Client
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String TrustedHosts 192.168.205.*
規定では未設定
135
TIPS:NIC のプロファイルが「識別されていない」場合
識別されていない = “パブリックネットワーク” である
• ターゲットが Windows クライアント(Windows 7/8 等)であれば、ターゲッ
ト PC で以下を実行(Server の場合には行う必要なし)
Enable-PSRemoting -Force -SkipNetworkProfileCheck
136
リモーティング編
7. -ComputerName パラメタの利用
137
リモートコンピュータの操作する3つの方法
<コマンドレット> -ComputerName パラメタ
※ -ComputerName では PSセッションは張られない
• リモートコンピューターに対して「リモート」から操作を行う
• 複数のコンピュータを指定可能
Enter-PSSession -ComputerName ・・・・・
• 対話モード(SSH のような使い方)
• Exit コマンドで接続を切断し、セッション消滅
Invoke-Command -ComputerName ・・・・・
• -ComputerName パラメタをもたないコマンドレットに対応
• リモートコンピューターの「中」で処理を行う
• 複数のコンピュータを指定可能
• コマンドやスクリプトの終了と同時にセッションと接続は消滅
138
-ComputerName を持つコマンドレット
PS C:¥> Get-Command -CommandType Cmdlet -ParameterName ComputerName
Invoke-Command
New-PSSession
Connect-PSSession
Receive-PSSession
Get-PSSession
Remove-PSSession
Receive-Job
Enter-PSSession
Add-Computer
Clear-EventLog
Get-EventLog
Get-HotFix
Get-Process
Get-Service
Get-WmiObject
Invoke-WmiMethod
Limit-EventLog
New-EventLog
Register-WmiEvent
Remove-Computer
Remove-EventLog
Remove-WmiObject
Rename-Computer
Restart-Computer
Set-Service
Set-WmiInstance
Show-EventLog
Stop-Computer
Test-Connection
Write-EventLog
Get-WindowsFeature
Install-WindowsFeature
Uninstall-WindowsFeature
(ほんの一部)
139
-ComputerName の利用
PS C:¥> Get-EventLog -ComputerName tfdc02 -LogName Security -Newest 10
リモートコンピューターのイベントログを取得する
PS C:¥> Restart-Computer -ComputerName tfsv02
リモートコンピューターを再起動する
PS C:¥> get-WindowsFeature -ComputerName tfsv02
リモートコンピューターにインストールされている役割/機能の一覧
PS C:¥> Add-WindowsFeature -ComputerName tfsv02 -Name RSAT-Hyper-V-Tools
-IncludeAllSubFeature -IncludeManagementTools
リモートコンピューターに Hyper-V 管理ツールをインストールする
140
リモーティング編
8. PS セッション
141
リモートコンピュータの操作する 3 つの方法
<コマンドレット> -ComputerName パラメタ
※ -ComputerName では PSセッションは張られない
• リモートコンピューターに対して「リモート」から操作を行う
• 複数のコンピュータを指定可能
Enter-PSSession -ComputerName ・・・・・
• 対話モード(SSH のような使い方)
• Exit コマンドで接続を切断し、セッション消滅
Invoke-Command -ComputerName ・・・・・
• -ComputerName パラメタをもたないコマンドレットに対応
• リモートコンピューターの「中」で処理を行う
• 複数のコンピュータを指定可能
• コマンドやスクリプトの終了と同時にセッションと接続は消滅
142
“セッション” と “PS セッション”
Local Computer
セッション
セッション
セッション
Remote Computer
PSセッション
PSセッション
Remote Computer
PSセッション
PSセッション
PSセッション
•PowerShell.exe が起動すると作られる。
•コンソールを閉じたらクリア。
•個々のセッションは独立
• ユーザー自身が作成し、管理と制御が可能
• 永続化が可能
• 個々のPSセッションは独立
• Windows PowerShell の実行環境
CALL
CALL
CALL
CALL
143
PS セッション
Source Targetコネクション
• PS セッション内でコマンドやスクリプトが実行される
• 変数もセッション内に保存される
• コネクションが「消滅」するとセッションも「消滅」する
• テンポラリ PS セッション
• -ComputerName を使用したときに作成されるセッション
• コマンドが終了するとセッションも終了する
• リユーザブル(Re-usable) PS セッション
• コマンド終了後もコネクションを維持し、セッションを継続
• 実行中の変数等もそのまま維持される
セ
ッ
シ
ョ
ン
144
Invoke-Command の特徴
• -ComputerName パラメタを持つ
• どんなコマンドでもリモートで実行可能
• -ComputerName パラメタを持たないコマンドレット
(Start-Service, Stop-Service など)
• 従来の DOS コマンド(netstat や gpupdate など)
• -Credential のサポート
• コマンドレットの中には -Credential を持たないものが多い
• -FilePath パラメタにスクリプトを指定可能
• スクリプトはローカルに存在していれば OK
※ただしコマンドレットはリモートに必要
• 複数のコンピューターを指定可能
145
Invoke-Command の利用
コマンドやスクリプトをリモートコンピューターに投げて、結果を受け取る
PS C:¥> Invoke-Command -ComputerName tfsv02 -ScriptBlock{ Get-Service }
リモートコンピューターのサービス一覧を取得する
PS C:¥>Invoke-Command -ComputerName tfsv02 -ScriptBlock{ Stop-Service -Name
wuauserv }
リモートコンピューターの Windows Update サービスを停止する
PS C:¥>Invoke-Command -ComputerName tfsv02 -ScriptBlock{ GPUpdate.exe }
リモートコンピューターで GPUpdate を実行する
PS C:¥> Invoke-Command -ComputerName tfsv02 -ScriptBlock{ cd env: ; dir }
リモートコンピューターの環境変数一覧を取得する
Get-Service -ComputerName と同じ
146
Invoke-Command -FilePath パラメタについて
-FilePath パラメタに指定するスクリプト(.ps1)は、ローカルのパス
Invoke-Command -ComputerName SV01 -FilePath .¥hogehoge.ps1
Invoke-Command -ComputerName SV01 -ScriptBlock {.¥hogehoge.ps1}
Target
Computer
hogehoge.ps1
Get-Service
・
・
スクリプトの中身がリモートに送られる
Target
Computer
hogehoge.ps1
ターゲット
に存在しな
いとエラー
147
param([string] $VMName = "VM01", [int] $CPU = 1, [int] $Mem = 10MB)
Stop-VM -Name $VMName -Force
Remove-VM -Name $VMName -Force
Remove-Item -Path ¥¥junichia-vdi¥VMs¥$VMName -Recurse -Force
$SwitchName = "Intel(R) 82579LM Gigabit Network Connection - Virtual Switch"
New-VM -BootDevice CD `
-MemoryStartupBytes $Mem `
-Name $VMName `
-SwitchName $SwitchName `
-NewVHDPath ¥¥junichia-vdi¥VMs¥$VMName¥$VMName.vhdx `
-NewVHDSizeBytes 40GB
Set-VM -ProcessorCount $CPU -DynamicMemory -Name $VMName
Add-VMNetworkAdapter -VMName $VMName -SwitchName $SwitchName
Start-VM -Name $VMName
1
2
3
4
5
6
7
8
9
10
11
12
13
14
リモートコンピューター上に仮想マシンを作成し起動する
PS C:¥> Invoke-Command -ComputerName "junichia-demo05"
-FilePath ".¥CreateVirtualMachine.ps1" -ArgumentList “Guest99",“2",“1024MB"
CreateVirtualMachine.ps1
148
Invoke-Command の注意点
• PS セッションは Invoke-Command ごとに作成され、実行後に消滅する
PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$A = 1}
PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$B = 1}
PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$C = $A + $B}
PS> Invoke-Command -ComputerName Server1 -ScriptBlock {“$A=1; $B=2 ;
$C=$A+$B” }
149
複数のリモートコンピューターに対する一括操作
PS > $ComputerList = “tfdc01”, “tfdc02”
PS > Get-Service -ComputerName $ComputerList | Sort-Object
MachineName, Name | Select-Object MachineName, Name, Status
PS > $ComputerList = “tfdc01”, “tfdc02”
PS > Invoke-Command -ComputerName $ComputerList {Get-Service |Sort-
Object PSComupterName, Name | Select-Object PSComputerName, Name,
Status} | FT
• 複数のコンピューターに対して処理を行い、結果をマージして出力
• 非同期に処理が開始され、全ての処理が終了するまで待ち合わせる
(シーケンシャルでないことに注意!)
• 規定では最大同時32台
-ComuterName パラメタに複数のコンピューターを指定する
MachineName と PSComputerName に注意!
150
$PSComputerName
Get-Service -ComputerName TARGET
Invoke-Command -ComputerName TARGET { Get-Service }
Source Target
コマンド
WMI
実
行
空
間
結果
Source Target
実
行
空
間
WMI
結果
Get-Service コマンドレットの
結果にはコンピューター名
(MachineName)が含まれる。
Get-Service コマンドレットの結
果に含まれるMachineNameには
ローカルコンピューター「.」が含
まれる。
Target コンピューター名を取得す
るには $PSComputerName を使
用する。
PSSession のターゲットとなったコンピューター名が格納される変数
151
CSVファイルから複数コンピューターを入力
Invoke-Command -ComputerName (Import-CSV computerlist.txt).HostName {get-
culture}
LCID Name DisplayName PSComputerName
---- ---- ----------- --------------
1041 ja-JP 日u本語e (日u本) tfdc01
1041 ja-JP 日u本語e (日u本) tfdc02
1042 ja-JP 日u本語e (日u本) tfsv02
1041 ja-JP 日u本語e (日u本) tfsv01
HostName,IPAddress
tfdc01,192.168.1.1
tfdc02,192.168.1.2
tfsv01,192.168.1.3
tfsv02,192.168.1.4
152
Enter-PSSession
• テンポラリ接続により対話型のセッションを開設する
• 複数のコマンドを実行可能
• 接続が生きている間はセッションも行き続ける
PS> Enter-PSSession -ComputerName Server1
[Server1]: PS > $A = 1
[Server1]: PS > $B = 2
[Server1]: PS > $C = $A + $B
PS> Exit-PSSession
153
リモーティング編
9. コネクションの永続化と PS セッションの再利用
154
リユーザブルな PS セッションを使用するには
PS > $S = New-PSSession -ComputerName CL01
PS > Invoke-Command -session $S -ScriptBlock {$A=1}
PS > Invoke-Command -session $S -ScriptBlock {$B=2}
PS > Invoke-Command -session $S -ScriptBlock {$C=$A+$B}
PS > Enter-PSSession $S
[CL01] PS > Echo $C
[CL01] 3
PS > Exit-PSSession
PS > Remove-Session $S
• セッションの作成 :New-PSSession
• セッションの削除 :Remove-PSSession
• セッション一覧 :Get-PSSession
• セッションへの接続 :Connect-PSSession
セッションを作成
セッション内
で実行される
155
複数ターゲットを含んだコネクションも可能
PS > $S = New-PSSession -ComputerName CL01,CL02
PS > $S
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
80 Session80 tfdc01 Opened Microsoft.PowerShell Available
81 Session81 tfdc02 Opened Microsoft.PowerShell Available
PS > Invoke-Command -Session $S {Get-Culture}
Target1コネクション セ
ッ
シ
ョ
ン
Target2セ
ッ
シ
ョ
ン
Source
156
ローカル変数をPSセッションで使用する
書式 $Using:<変数名>
PS C:¥> $S = New-PSSession -ComputerName tfdc01
PS C:¥> $MyName = “Junichi Anno”
PS C:¥> Invoke-Command -Session $S {Echo $Using:MyName}
Junichi Anno
157
PS セッション情報の取得 ~ Get-PSSession
Target1コネクション セ
ッ
シ
ョ
ン
Source1
Source2
PS C:¥tools¥ps> Get-PSSession -ComputerName Target1
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
65 tfdc01_Session target1 Opened Microsoft.PowerShell Available
80 Session80 taeget1 Opened Microsoft.PowerShell Available
109 Session109 target1 Opened Microsoft.PowerShell Available
• リユーザブルなセッション情報は他のコンピューターからも参照できる
• 他のユーザーが作成したセッションは、Credential が有効であれば参照可能
-Credential パラメタを使用可能
158
PS セッションへの再接続
Target1
セ
ッ
シ
ョ
ン
Source1
Source2
• リユーザーブルな PS セッションには他のコンピューターから再接続が可能
• State=Disconnected, Availability=None に対してのみ
• Disconnect-PSSession コマンドレットで明に Disconnect した場合
• ネットワークの切断や PC のハングアップ等で Disconnected になった場合
※ コンソールを明に落とした場合は強制終了したものとみなされる
• 同時に2台以上のコンピューターからは接続できない
State=Disconnected
Availability=None
再接続可能
Disconnect-PSSession
Connect-PSSession
159
PS > $S = New-PSSession -ComputerName Target1
PS > $Result = Invoke-Command -Session $S {Get-Service}
PS > Disconnect-PSSession -Session $S
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
121 Session121 Target1 Disconnected Microsoft.PowerShell None
Target
PC1
PC
2
PS > Get-PSSession -ComputerName Target1
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy
12 Session121 tfdc01 Disconnected Microsoft.PowerShell None
PS > $S = Get-PSSession -Name Session121 -ComputerName Target1
PS > Connect-PSSession -Session $S
160
State と Availability
Availability
State
Opened 自分自身が接続している
Disconnected 自分自身は接続していない
誰も接続していない
他の誰かが接続してる
自分が接続している
None
Busy
Available
こ
の
組
み
合
わ
せ
な
ら
ば
再
接
続
可
能
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy
12 Session121 tfdc01 Disconnected Microsoft.PowerShell None
161
もしソース PC がダウンしたら
ソースが死んでもセッション情報はターゲットに残されている...ただし...
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy
Availability が Busy なので、再接続できない
2
分
後
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
10 Session112 tfdc01 Disconnected Microsoft.PowerShell None
再接続可能!
162
PS セッションの有効期間
• PS セッションのターゲットの再起動、シャットダウン
• Remove-PSSession を実行するまで
• セッションがアイドルタイムアウトするまで
• Disconnect してからの時間
PS > Remove-PSSession -Session $S
PS C:¥> Get-PSSessionConfiguration | ft name,idletimeoutms,maxidletimeoutms
Name IdleTimeoutms MaxIdleTimeoutms
---- ------------- ----------------
microsoft.powershell 7200000 2147483647
microsoft.powershell.workflow 7200000 2147483647
microsoft.powershell32 7200000 2147483647
microsoft.windows.servermanagerworkflows 180000 180000
2時間 596時間
規定値
163
アイドルタイムアウト値の変更
PS C:¥> $SessionOption = New-PSSessionOption -IdleTimeOutMSec 60000
PS C:¥> $S = New-PSSession -ComputerName Target1 -SessionOption $SessionOption
設定方法
• 構成ファイルを変更
• Register-PSSessionConfiguration -TransportOption <$TransportOption>
• Set-PSSessionConfiguration -TransportOption <$TransportOption>
• PS セッション作成時(特定のセッションのみ)
• New-PSSession -SessionOption <$SessionOption>
• コマンド実行開始時(特定のセッションのみ)
• Invoke-Command -SessionOption <$SessionOption>
• PS セッション切断時(特定のセッションのみ)
• Disconnect-PSSession -IdeleTimeOutSec <秒>
164
出力バッファモード
出力バッファがFULLになった場合の対応モード
• Block : バッファがClearされるまでコマンドの実行をサスペンドする
• Drop:コマンドの実行は続けるが古い出力結果から捨てられる
現在のモードを調べる
PS C¥> Get-PSSessionConfiguration | ft Name, OutputBufferingMode
Name OutputBufferingMode
---- -------------------
microsoft.powershell Block
microsoft.powershell.workflow Block
microsoft.powershell32 Block
microsoft.windows.servermanagerworkflows Block
「現在の PS セッションでは Drop モードで実行する」を設定
PS C:¥> $o = New-PSSessionOption -OutputBufferingMode Drop
PS C:¥> New-PSSession -SessionOption $o
165
Source2 再接続可能
ループバック PS セッション
• LOCALHOST に対してリユーザーブルな PS セッションを作成すれば、
切断したあと別のマシンから再接続が可能
• 管理者モードで実行する必要がある
PS > $S = Get-PSSession -ComputerName localhost -Name Backup
PS > Receive-PSSession -Session $S
PS > Remove-PSSession -Session $S
Source1
/Target
セ
ッ
シ
ョ
ン
Connect-PSSession
PS> $S = New-PSSession -Name Backup
PS> Invoke-Command -Session $S -FilePath backup.ps1 -AsJob
PS> Disconnect-PSSession -Session $S
166
モジュールとコマンドのインポート
• リモートコンピューター上のコマンドレットを一時的に取り込むことができる
• “Invoke-Command -Session” を使用する必要が無くなる
• コマンドの実行中はセッションを生かしておく必要がある
PS C:> $s = New-PSSession -ComputerName Server1
PS C:> Import-PSSession -Session $s -Module HYPER-V
PS C:¥> Get-VM |ft name
Name
----
VM01
VM02
VM03
VM04
VM05
Windows Server
w/ Hyper-V
PS Session
Hyper-V Module
167
リモーティング編
10. PSWA
168
Windows PowerShell Web Access
再接続
WS-Man に接続するためのゲートウェイ
IntranetDMZInternet
Home
169
PowerShell Web Access のセットアップ
1.サーバーマネージャーから PowerShell Web Access をインストールする
170
2.IIS で自己署名証明書を作成してバインドを設定する(SSLを有効に)
ご自身のサーバーを指
定してください
バインドの設定で
作成した証明書を選択
171
2.PowerShell を管理者モードで起動
3.以下のコマンドを実行
PS C:¥> Set-ExecutionPolicy RemoteSigned
PS C:¥> Import-Module PowerShellWebAccess
PS C:¥> Install-PswaWebApplication -webSiteName "Default Web Site"
PS C:¥> Add-PswaAuthorizationRule * * *
4.https://<サーバー名>/pswa にアクセス
ここで指定するサーバーは、
ターゲットとなるサーバー
172
Part 3 バックグラウンドジョブ編
173
• Windows PowerShell 2.0 よりサポート
• 長時間を要するコマンドレットを非同期に実行し、次の処理に移る
(例)get-eventlog “Security”
• ジョブの有効範囲は現在のセッション
• ジョブを生成するには
– -AsJob パラメタ
• 一部のコマンドのみが実装
• ワークフローコマンドには使用可能
– Start-Job コマンドレット
• すべてのコマンド、スクリプトをジョブ化可能
• ジョブの結果がどこに保存されるのかを意識することが重要!
バックグラウンドジョブ
174
-AsJob
-AsJob パラメタを持つコマンドレットは少ない
PS C:¥> Get-Command -ParameterName asjob
CommandType Name ModuleName
----------- ---- ----------
Function Get-SMCounterSample ServerManagerTasks
Function Get-SMPerformanceCollector ServerManagerTasks
Function Get-SMServerBpaResult ServerManagerTasks
Function Get-SMServerClusterName ServerManagerTasks
Function Get-SMServerEvent ServerManagerTasks
Function Get-SMServerFeature ServerManagerTasks
Function Get-SMServerInventory ServerManagerTasks
Function Get-SMServerService ServerManagerTasks
Function Remove-SMServerPerformanceLog ServerManagerTasks
Function Start-SMPerformanceCollector ServerManagerTasks
Function Stop-SMPerformanceCollector ServerManagerTasks
Cmdlet Get-WmiObject Microsoft.PowerShell.Management
Cmdlet Invoke-Command Microsoft.PowerShell.Core
Cmdlet Invoke-WmiMethod Microsoft.PowerShell.Management
Cmdlet Remove-WmiObject Microsoft.PowerShell.Management
Cmdlet Restart-Computer Microsoft.PowerShell.Management
Cmdlet Set-WmiInstance Microsoft.PowerShell.Management
Cmdlet Stop-Computer Microsoft.PowerShell.Management
Cmdlet Test-Connection Microsoft.PowerShell.Management
※AsJobパラメタを持つコマンド一覧
175
ジョブ関連のコマンドレット
 Get-Job
 バックグラウンドジョブを取得
 Receive-Job
 バックグラウンドジョブの出力結果を取得
 Remove-Job
 バックグラウンドジョブを削除
 Start-Job
 バックグラウンドジョブを開始
 Stop-Job
 バックグラウンドジョブを停止
 Wait-Job
 バックグラウンドジョブが終了するまで待つ
176
バックグラウンドジョブの基本操作
(例)
PS C:¥> $job = start-job -scriptblock {do {$a = 0; echo (date) ; start-sleep 5} while ($a -eq 0) }
PS C:¥> $job
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
6 Job6 Completed True localhost get-eventlog "Windows ...
PS C:¥> Receive-Job $job -Keep
PS C:¥> Stop-Job $job
PS C:¥> Remove-job $job
書式
start-job -scriptblock { <スクリプトブロック> }
出力結果が存在する
規定では、出力結果は一度取得するとクリアされてしま
うので、-Keep によって残すように指定
5秒に1回日時を表示するジョブ
ジョブを停止
ジョブを削除
177
スクリプトをバックグラウンドジョブ化するには
$flg = $true
$index = 0
$index_old = 0
Do
{
$Eventlog = Get-Eventlog -LogName TechFielders -Source TechFielders
$index = $eventlog | Select-Object -First 1 -Property Index
$delta_index = $index.Index - $index_old
if ($delta_index -gt 0) { $eventlog | `
Select-Object -First $delta_index | `
Sort-Object -Property Index }
Start-Sleep -Seconds 1
$index_old = $index.Index
} While ($flg)
まずはスクリプトを作成する(イベントログを取得するスクリプト)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
WatchNewEventLog.ps1
結果を Index をキーとして昇順に並べる
178
##作成したスクリプトをバックグラウンドで実行する
PS C:¥> Start-Job -FilePath .¥WatchNewEventLog.ps1 -Name WatchNewEventLog
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
4 WatchNewEven... BackgroundJob Running True localhost $flg = $true...
## 以下のコマンドで現在までの結果を収集する
PS C:¥> Receive-Job -Name WatchNewEventLog
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
1 6 02 17:41 Information TechFielders 5963 テスト
2 6 02 18:09 Information techfielders 99 テスト
3 6 02 18:11 Information TechFielders 9909 テスト
4 6 02 18:12 Information TechFielders 9909 テスト
5 6 02 18:13 Information TechFielders 9909 テスト
6 6 02 18:13 Information TechFielders 9909 Hello
以下のコマンドで新しいイベントを書き込む
C:¥> Write-EventLog -LogName TechFielders -Message "Hello" -Source "TechFielders" -EventId 5963
179
Target
“ジョブの実行場所”と”結果の保存場所”は一緒の法則
Source
Session
• “コマンドの実行場所”と”ジョブの実行場所”は異なる可能性がある
• 操作のターゲットがリモートコンピューターであっても、
ジョブがローカルならば結果もローカルに保存される
CmdLet
Job/Result
TargetSource
Session
CmdLet
Job/Result
コマンドはリモート
ジョブはローカル
コマンドはリモート
ジョブもリモート
180
セッションの永続化とジョブの実行結果
PS> Invoke-Command -Session $S -FilePath backup.ps1 -AsJob
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
2 Job2 RemoteJob Completed True tfdc01 get-service
PS> Receive-Job -Id 2
SRC Target
実
行
結
果
(例1)Invoke-Command -AsJob を使用した場合
セッションに再接続する場合には、結果もリモートに保存しなければ意味がない!!
Invoke-Command をバックグ
ラウンドジョブ化するため
のオプション。
スクリプトはリモートだが、ジョブはローカル。
Invoke-Command の結果はローカルに保存されることに注意!!!
つまりローカルセッションが消えたらジョブの結果も消えるということ!!
181
PS> $S = New-PSSession -ComputerName Target -Name Backup
PS> $Script = “.¥testscript.ps1"
PS> Invoke-Command -Session $S { Start-Job -FilePath $Script }
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job1 BackgroundJob Running True localhost backup...
PS> Disconnect-PSSession -Session $S
SRC1 Target
実
行
結
果
(例2)Invoke-Command {Start-Job} を使用した場合
(つづく)
SRC2
スクリプトをジョブ化することで、結果がリモートに保存されるため、セッションを永続化すれ
ば別のコンピューターから取り出せる。
182
PS> Get-PSSession -ComputerName tfdc01
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- -------------
1 backup tfdc01 Disconnected Microsoft.PowerShell None
PS> $S = Connect-PSSession -Name backup -ComputerName tfdc01
PS> Invoke-Command -Session $S { Get-Job }
Id Name PSJobTypeName State HasMoreData Location
-- ---- ------------- ----- ----------- --------
1 Job1 BackgroundJob Completed True localhost
PS> Invoke-Command -Session $S {Receive-Job -Id 1}
別のコンピューターから接続して結果を取得
183
バックグラウンドジョブのスケジューリング
Add-JobTrigger
Disable-JobTrigger
Disable-ScheduledJob
Enable-JobTrigger
Enable-ScheduledJob
Get-JobTrigger
Get-ScheduledJob
Get-ScheduledJobOption
New-JobTrigger
New-ScheduledJobOption
Register-ScheduledJob
Remove-JobTrigger
Set-JobTrigger
Set-ScheduledJob
Set-ScheduledJobOption
Unregister-ScheduledJob
• PSScheduledJob モジュールで提供
184
ジョブスケジューリングの例
$trigger = New-JobTrigger -Daily -At 3am
Register-ScheduledJob -Name EnergyAnalysisJob -Trigger $trigger -ScriptBlock {
powercfg.exe -energy -xml -output C:¥temp¥energy.xml -duration 60 | Out-Null
$EnergyReport = [xml](get-content C:¥temp¥energy.xml)
$namespace = @{ ns = "http://schemas.microsoft.com/energy/2007" }
$xPath = "//ns:EnergyReport/ns:Troubleshooter/ns:AnalysisLog/ns:LogEntry[ns:Severity = 'Error']"
$EnergyErrors = $EnergyReport | Select-Xml -XPath $xPath -Namespace $namespace
$EnergyErrors.Node | select Name, Description
}
タスクマネージャーで参照可能
185
Part 4 ワークフロー編
186
Agenda ~ワークフロー編
11.Windows PowerShell Workflow とは
12.Windows PowerShell Workflow の基礎
13.ワークフロー特有の記述
14.ワークフロージョブとデータの永続化
187
ワークフロー編
12. Windows PowerShell Workflow とは
188
想定している利用シーン
ターゲットとなる処理
• 長時間を要する処理
– 仮想マシンの展開
– ソフトウェアのインストール
– ビッグデータの集計 など
• 複数の処理の組み合わせ
• 複数のコンピューターに対する処理
– ドメイン参加
– 環境設定
– インベントリ収集 など
要求される制御機構
• タイムアウトやリトライ
• 処理の一時停止、再開
• 処理ステートの永続化
• 複数処理の制御
• 並列
• シーケンシャル
• スクリプト実行権限の委任
• 途中経過の取得
ワークフロー = バックグラウンドジョブ + リモーティング + 実行制御
189
ユーザー
リストを
チェック
ホームディレ
クトリ作成
ユーザー
作成
(例)ユーザーを作成する
UserList
ユーザー
属性設定
グループメン
バーシップ
パスワード
設定
アクセス権
設定
ユーザーごとの処理
完了
190
PowerShell 3.0 - ワークフロー
パラレル
WF
ジョブと結果の永続化
WF
処理1
処理2
checkpoint
結果ストア
結果1
checkpoint
処理3
サーバー
ダウン
サスペンド
WF
処理1
処理2
サスペンド
サーバーが条件
に合致しない場
合にサスペンド
し、あとでレ
ジューム
191
PowerShell ワークフローの特長
• 実行中のコンピューターが再起動してもワークフロージョブは消えない
• 一時停止状態(Suspend)になる
• 長時間タスクの制御と監視
• アクティビティの進行状況はいつでも参照可能
• 自動リカバリ
• 途中経過は指定したポイントで保存されている
• ワークフローセッションへの接続と切断
• ワークフローを開始した PC とは別の PC から再接続が可能
• 同時に複数コンピューターへの接続
• ワークフロータスクを同時に大量のサーバーに配信可能
• 複数のスクリプトを1つのワークフローでコントロール
• スケジューリング
• 特定の状態をトリガーとして起動可能
• XAMLファイルでインポート、エクスポート可能
※ ワークフローが動作するコンピューターには Windows PowerShell 3.0 が必須
192
ワークフロー編
13. Windows PowerShell Workflow の基礎
193
ワークフロ―実行までの流れ
① ワークフローを作成する
② ワークフローを登録する
③ ワークフローを確認する
④ ワークフローを実行する
i. ワークフローセッションの作成
ii. ワークフローを実行
iii. 結果を取得
194
Wokflow の作成
• PowerShell ISE(またはテキストエディタ) で作成する
• workflow キーワードを使用する
workflow <ワークフロー名> ( <引数> )
{
<処理>
}
workflow MyWorkflow ( [String] $ServiceName )
{
Get-Service -PSComputerName $PSComputerName -Name $ServiceName
}
(例)MyWorkflow という名前でリモートコンピューターのサービス一覧を取得するワークフロー
注意 -ComputerName ではない(後述)
共通パラメタ(後述)
195
Workflow の登録
• .ps1 で保存し、実行するだけ
または、PowerShell ISE 上から実行するだけ
• 留意点
 どこに登録するか?
 いつ登録するか?
196
Workflow をどこに登録するか?
自分のPC Managed
Node
WF
自分のPC
Managed
Node
WF 実行
WF
WinRMWinRM
WMIWMI
In-Process Execution
終わるまで家に帰れない!
Execution in Workflow Configuration
実行したらセッッション切断して帰宅 :)
ワークフローは実行するノードに存在しなければならない
197
Workflow の登録先と実行環境について
• In-process 実行
 Activity はローカルに登録される
 PowerShell クライアントホスト上での実行
 ワークフローが終了するまでセッションを切断できない
• Workflow セッション上での実行
 Activity はリモートノードに登録される
 Workflow 用に PS セッションを作成し、WinRM を通して実行する
 一時的な切断が可能で、長時間のジョブを実行する際に便利
198
(参考)In-Process 実行時のアーキテクチャ
Localhost
Powershell.exe
Activity Host Process
Activity
Host
Managed Node
PowerShell
Remoting
(RSRP)
Managed Node
CIMOM/
WMI
PSWF
Executive
PSWF
Cmdlets
199
(参考)Workflow セッションで実行時のアーキテクチャ
Managed Node
PowerShell
Remoting
(RSRP)
Managed Node
CIMOM/
WMI
PowerShell Workflow
Activity Host Process
Activity
Host
PSWF
Executive
Client
PSJobProxy/
PSJob API/
PSRP
WinRM
Client
WinRM
Service
200
Proxy Node
• リモートノードにワークフローを登録
=リモートでスクリプトを実行
自分のPC 登録
WF
Managed
Node
WinRM
WMI
Managed
Node
WinRM
WMI
Managed
Node
WinRM
WMI
実行
WinRM
PS C:¥> $S = New-PSWorkflowSession -ComputerName <Node>
PS C:¥> Invoke-Command –Session $S -FilePath mywf.ps1
ワーククフローが定義されているファイル
PS1ファイルがローカルにある場合
PS C:¥> $S = New-PSWorkflowSession -ComputerName <Node>
PS C:¥> Invoke-Command –Session $S { .¥mywf.ps1 }
PS1ファイルがリモートにある場合
201
ワークフローをいつ登録すべきか?
注意 ワークフローは セッション または PSセッション 内でのみ有効
PS C:¥> Invoke-Command -ComputerName NODE -FilePath .¥mywf.ps1
ダメな例2:登録したとたんに消滅
PS C:¥> $S = New-PSSession -ComputerName NODE
PS C:¥> Invoke-Command -Session $S -FilePath .¥mywf.ps1
ダメじゃないけど気をつけなければならない例:PS セッション消滅とともにWF
も消滅
PS C:¥>.¥mywf.ps1
ダメな例1:コンソールを閉じた瞬間に消滅 orz
ワークフローは実行直前に登録したほうがよさそう...
PS C:¥> Invoke-Command -ComputerName NODE -FilePath .¥mywf.ps1 -asjob
202
(参考)workflow を登録すると...
AST(abstract syntax tree)workflow
{
Get-Service
}
.ps1 ファイル
実行
“workflow” キーワード検出
Script-to-workflow コンパイラ
XAML
workflow
Activity Tree
Workflow Foundation 4
ActivityXamlService Class
203
登録されたワークフローの確認
• Get-Command で確認する
(ワークフローはコマンドレットと同じように扱える)
PS C:¥> Get-Command <ワークフロー名>
PS C:¥> Get-Command MyWorkflow
CommandType Name ModuleName
----------- ---- ----------
Workflow MyWorkflow
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版

More Related Content

What's hot

MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムKouhei Sutou
 
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)今こそ知りたいSpring Batch(Spring Fest 2020講演資料)
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)NTT DATA Technology & Innovation
 
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話JustSystems Corporation
 
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはがんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはJun-ichi Sakamoto
 
Dockerを支える技術
Dockerを支える技術Dockerを支える技術
Dockerを支える技術Etsuji Nakai
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021Hiroshi Tokumaru
 
コンセプトから理解するGitコマンド
コンセプトから理解するGitコマンドコンセプトから理解するGitコマンド
コンセプトから理解するGitコマンドktateish
 
Linux女子部 systemd徹底入門
Linux女子部 systemd徹底入門Linux女子部 systemd徹底入門
Linux女子部 systemd徹底入門Etsuji Nakai
 
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2AbemaTV, Inc.
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話JustSystems Corporation
 
OpenStackで始めるクラウド環境構築入門
OpenStackで始めるクラウド環境構築入門OpenStackで始めるクラウド環境構築入門
OpenStackで始めるクラウド環境構築入門VirtualTech Japan Inc.
 
最近のBurp Suiteについて調べてみた
最近のBurp Suiteについて調べてみた最近のBurp Suiteについて調べてみた
最近のBurp Suiteについて調べてみたzaki4649
 
AWSスポットインスタンスの真髄
AWSスポットインスタンスの真髄AWSスポットインスタンスの真髄
AWSスポットインスタンスの真髄外道 父
 
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Taku Miyakawa
 
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践日本マイクロソフト株式会社
 

What's hot (20)

MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
 
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)今こそ知りたいSpring Batch(Spring Fest 2020講演資料)
今こそ知りたいSpring Batch(Spring Fest 2020講演資料)
 
Goss入門
Goss入門Goss入門
Goss入門
 
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話
DDDとクリーンアーキテクチャでサーバーアプリケーションを作っている話
 
Jenkins 再入門
Jenkins 再入門Jenkins 再入門
Jenkins 再入門
 
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とはがんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
がんばらなくても C# で Single Page Web アプリケーションが書けてしまう「Blazor」とは
 
Dockerを支える技術
Dockerを支える技術Dockerを支える技術
Dockerを支える技術
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
 
コンセプトから理解するGitコマンド
コンセプトから理解するGitコマンドコンセプトから理解するGitコマンド
コンセプトから理解するGitコマンド
 
Linux女子部 systemd徹底入門
Linux女子部 systemd徹底入門Linux女子部 systemd徹底入門
Linux女子部 systemd徹底入門
 
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2
AbemaTVのアーキテクチャの変遷 / AbemaTV DevCon 2018 TrackA Session A2
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
 
OpenStackで始めるクラウド環境構築入門
OpenStackで始めるクラウド環境構築入門OpenStackで始めるクラウド環境構築入門
OpenStackで始めるクラウド環境構築入門
 
HTTP/2 入門
HTTP/2 入門HTTP/2 入門
HTTP/2 入門
 
最近のBurp Suiteについて調べてみた
最近のBurp Suiteについて調べてみた最近のBurp Suiteについて調べてみた
最近のBurp Suiteについて調べてみた
 
Vue入門
Vue入門Vue入門
Vue入門
 
[BurpSuiteJapan]HTTP基礎入門
[BurpSuiteJapan]HTTP基礎入門[BurpSuiteJapan]HTTP基礎入門
[BurpSuiteJapan]HTTP基礎入門
 
AWSスポットインスタンスの真髄
AWSスポットインスタンスの真髄AWSスポットインスタンスの真髄
AWSスポットインスタンスの真髄
 
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方
 
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践
【de:code 2020】 Azure Red hat OpenShift (ARO) によるシステムアーキテクチャ構築の実践
 

Viewers also liked

Hyper-V を Windows PowerShell から管理する
Hyper-V を Windows PowerShell から管理するHyper-V を Windows PowerShell から管理する
Hyper-V を Windows PowerShell から管理するjunichi anno
 
PowerShell の基本操作とリモーティング&v3のご紹介 junichia
PowerShell の基本操作とリモーティング&v3のご紹介 junichiaPowerShell の基本操作とリモーティング&v3のご紹介 junichia
PowerShell の基本操作とリモーティング&v3のご紹介 junichiajunichi anno
 
Power shell の基本操作と処理の自動化 v2_20120514
Power shell の基本操作と処理の自動化 v2_20120514Power shell の基本操作と処理の自動化 v2_20120514
Power shell の基本操作と処理の自動化 v2_20120514junichi anno
 
Active Directory 最新情報 2012.8.31 暫定版
Active Directory 最新情報 2012.8.31 暫定版Active Directory 最新情報 2012.8.31 暫定版
Active Directory 最新情報 2012.8.31 暫定版junichi anno
 
Windows File Service 総復習-Windows Server 2012 R2編 第1版
Windows File Service 総復習-Windows Server 2012 R2編 第1版Windows File Service 総復習-Windows Server 2012 R2編 第1版
Windows File Service 総復習-Windows Server 2012 R2編 第1版junichi anno
 
Windows Server 2012 で管理をもっと自動化する
Windows Server 2012 で管理をもっと自動化するWindows Server 2012 で管理をもっと自動化する
Windows Server 2012 で管理をもっと自動化するjunichi anno
 
ファイルサーバー移行方法の調査
ファイルサーバー移行方法の調査ファイルサーバー移行方法の調査
ファイルサーバー移行方法の調査Naoyuki Sano
 
ふくてん#2 Powershellとossで作るお手軽モニタリング環境
ふくてん#2 Powershellとossで作るお手軽モニタリング環境ふくてん#2 Powershellとossで作るお手軽モニタリング環境
ふくてん#2 Powershellとossで作るお手軽モニタリング環境yukiusagi2052
 
安全なデータ公開のために
安全なデータ公開のために 安全なデータ公開のために
安全なデータ公開のために Wakamatz
 
Windows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIWindows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIjunichi anno
 
会社でPowershell
会社でPowershell会社でPowershell
会社でPowershellkobexr
 
Microsoft の ID 連携技術
Microsoft の ID 連携技術Microsoft の ID 連携技術
Microsoft の ID 連携技術shigeya
 
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPS
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPSUltimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPS
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPSMichael Noel
 
Microsoft と Digital Identity
Microsoft と Digital IdentityMicrosoft と Digital Identity
Microsoft と Digital Identityjunichi anno
 
仮想化した DC を PowerShell で複製する
仮想化した DC を PowerShell で複製する仮想化した DC を PowerShell で複製する
仮想化した DC を PowerShell で複製するjunichi anno
 
Vdi を より使いやすいインフラにするためのセキュリティ設計
Vdi を より使いやすいインフラにするためのセキュリティ設計Vdi を より使いやすいインフラにするためのセキュリティ設計
Vdi を より使いやすいインフラにするためのセキュリティ設計junichi anno
 
SaaS としての IDM の役割
SaaS としての IDM の役割SaaS としての IDM の役割
SaaS としての IDM の役割junichi anno
 
Dynamic Access Control 演習編
Dynamic Access Control 演習編Dynamic Access Control 演習編
Dynamic Access Control 演習編junichi anno
 
Dynamic Access Control 解説編
Dynamic Access Control 解説編Dynamic Access Control 解説編
Dynamic Access Control 解説編junichi anno
 
Shared Nothing Live Migration で重要な「委任」について
Shared Nothing Live Migration で重要な「委任」についてShared Nothing Live Migration で重要な「委任」について
Shared Nothing Live Migration で重要な「委任」についてjunichi anno
 

Viewers also liked (20)

Hyper-V を Windows PowerShell から管理する
Hyper-V を Windows PowerShell から管理するHyper-V を Windows PowerShell から管理する
Hyper-V を Windows PowerShell から管理する
 
PowerShell の基本操作とリモーティング&v3のご紹介 junichia
PowerShell の基本操作とリモーティング&v3のご紹介 junichiaPowerShell の基本操作とリモーティング&v3のご紹介 junichia
PowerShell の基本操作とリモーティング&v3のご紹介 junichia
 
Power shell の基本操作と処理の自動化 v2_20120514
Power shell の基本操作と処理の自動化 v2_20120514Power shell の基本操作と処理の自動化 v2_20120514
Power shell の基本操作と処理の自動化 v2_20120514
 
Active Directory 最新情報 2012.8.31 暫定版
Active Directory 最新情報 2012.8.31 暫定版Active Directory 最新情報 2012.8.31 暫定版
Active Directory 最新情報 2012.8.31 暫定版
 
Windows File Service 総復習-Windows Server 2012 R2編 第1版
Windows File Service 総復習-Windows Server 2012 R2編 第1版Windows File Service 総復習-Windows Server 2012 R2編 第1版
Windows File Service 総復習-Windows Server 2012 R2編 第1版
 
Windows Server 2012 で管理をもっと自動化する
Windows Server 2012 で管理をもっと自動化するWindows Server 2012 で管理をもっと自動化する
Windows Server 2012 で管理をもっと自動化する
 
ファイルサーバー移行方法の調査
ファイルサーバー移行方法の調査ファイルサーバー移行方法の調査
ファイルサーバー移行方法の調査
 
ふくてん#2 Powershellとossで作るお手軽モニタリング環境
ふくてん#2 Powershellとossで作るお手軽モニタリング環境ふくてん#2 Powershellとossで作るお手軽モニタリング環境
ふくてん#2 Powershellとossで作るお手軽モニタリング環境
 
安全なデータ公開のために
安全なデータ公開のために 安全なデータ公開のために
安全なデータ公開のために
 
Windows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIWindows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMI
 
会社でPowershell
会社でPowershell会社でPowershell
会社でPowershell
 
Microsoft の ID 連携技術
Microsoft の ID 連携技術Microsoft の ID 連携技術
Microsoft の ID 連携技術
 
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPS
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPSUltimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPS
Ultimate SharePoint Infrastructure Best Practices - Japanese Version - #JPSPS
 
Microsoft と Digital Identity
Microsoft と Digital IdentityMicrosoft と Digital Identity
Microsoft と Digital Identity
 
仮想化した DC を PowerShell で複製する
仮想化した DC を PowerShell で複製する仮想化した DC を PowerShell で複製する
仮想化した DC を PowerShell で複製する
 
Vdi を より使いやすいインフラにするためのセキュリティ設計
Vdi を より使いやすいインフラにするためのセキュリティ設計Vdi を より使いやすいインフラにするためのセキュリティ設計
Vdi を より使いやすいインフラにするためのセキュリティ設計
 
SaaS としての IDM の役割
SaaS としての IDM の役割SaaS としての IDM の役割
SaaS としての IDM の役割
 
Dynamic Access Control 演習編
Dynamic Access Control 演習編Dynamic Access Control 演習編
Dynamic Access Control 演習編
 
Dynamic Access Control 解説編
Dynamic Access Control 解説編Dynamic Access Control 解説編
Dynamic Access Control 解説編
 
Shared Nothing Live Migration で重要な「委任」について
Shared Nothing Live Migration で重要な「委任」についてShared Nothing Live Migration で重要な「委任」について
Shared Nothing Live Migration で重要な「委任」について
 

Similar to Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版

Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)
Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)
Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)Takamasa Maejima
 
170622 02
170622 02170622 02
170622 02openrtm
 
Cloudstack user group meeting in osaka
Cloudstack user group meeting in osakaCloudstack user group meeting in osaka
Cloudstack user group meeting in osakaNaotaka Jay HOTTA
 
OpenStack base public cloud service by GMO Internet Inc., at 2013/12/12 Okin...
OpenStack base public cloud service by GMO Internet Inc.,  at 2013/12/12 Okin...OpenStack base public cloud service by GMO Internet Inc.,  at 2013/12/12 Okin...
OpenStack base public cloud service by GMO Internet Inc., at 2013/12/12 Okin...Naoto Gohko
 
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」Nobuyuki Tamaoki
 
Build Windows ラップアップ
Build Windows ラップアップBuild Windows ラップアップ
Build Windows ラップアップSunao Tomita
 
Windows PowerShell 2.0 の基礎知識
Windows PowerShell 2.0 の基礎知識Windows PowerShell 2.0 の基礎知識
Windows PowerShell 2.0 の基礎知識shigeya
 
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~Akira Inoue
 
Firefoxの開発プロセス
Firefoxの開発プロセスFirefoxの開発プロセス
Firefoxの開発プロセスMakoto Kato
 
技術選択とアーキテクトの役割
技術選択とアーキテクトの役割技術選択とアーキテクトの役割
技術選択とアーキテクトの役割Toru Yamaguchi
 
OpenStack 向けネットワーク入門
OpenStack 向けネットワーク入門OpenStack 向けネットワーク入門
OpenStack 向けネットワーク入門Dell TechCenter Japan
 
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)VirtualTech Japan Inc.
 
Jenkins study jenkins build-cicdi
Jenkins study jenkins build-cicdiJenkins study jenkins build-cicdi
Jenkins study jenkins build-cicdi昌桓 李
 
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説Daisuke Nishino
 
.NET Core とマルチプラットフォーム
.NET Core とマルチプラットフォーム.NET Core とマルチプラットフォーム
.NET Core とマルチプラットフォームshozon
 
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorks
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorksAWS Black Belt Tech シリーズ 2015 - AWS OpsWorks
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorksAmazon Web Services Japan
 
Cld002 windows server_2016_で作るシンプ
Cld002 windows server_2016_で作るシンプCld002 windows server_2016_で作るシンプ
Cld002 windows server_2016_で作るシンプTech Summit 2016
 
実践で学んだLog Analytics
実践で学んだLog Analytics実践で学んだLog Analytics
実践で学んだLog AnalyticsTetsuya Odashima
 

Similar to Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版 (20)

Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)
Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)
Windows Server 2016 で作るシンプルなハイパーコンバージドインフラ (Microsoft TechSummit 2016)
 
170622 02
170622 02170622 02
170622 02
 
Cloudstack user group meeting in osaka
Cloudstack user group meeting in osakaCloudstack user group meeting in osaka
Cloudstack user group meeting in osaka
 
OpenStack base public cloud service by GMO Internet Inc., at 2013/12/12 Okin...
OpenStack base public cloud service by GMO Internet Inc.,  at 2013/12/12 Okin...OpenStack base public cloud service by GMO Internet Inc.,  at 2013/12/12 Okin...
OpenStack base public cloud service by GMO Internet Inc., at 2013/12/12 Okin...
 
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」
OpenStack最新動向と構築のポイント - EMC様セミナー 「あなたのビジネスを高速化! OpenStackが実現する戦略的なクラウドインフラ」
 
Build Windows ラップアップ
Build Windows ラップアップBuild Windows ラップアップ
Build Windows ラップアップ
 
Amazon EC2 Container Service Deep dive
Amazon EC2 Container Service Deep diveAmazon EC2 Container Service Deep dive
Amazon EC2 Container Service Deep dive
 
Windows PowerShell 2.0 の基礎知識
Windows PowerShell 2.0 の基礎知識Windows PowerShell 2.0 の基礎知識
Windows PowerShell 2.0 の基礎知識
 
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~
Linux & Mac OS でも動く! ~ オープンソース & クロスプラットフォーム .NET の歩き方 ~
 
OpenStack概要
OpenStack概要OpenStack概要
OpenStack概要
 
Firefoxの開発プロセス
Firefoxの開発プロセスFirefoxの開発プロセス
Firefoxの開発プロセス
 
技術選択とアーキテクトの役割
技術選択とアーキテクトの役割技術選択とアーキテクトの役割
技術選択とアーキテクトの役割
 
OpenStack 向けネットワーク入門
OpenStack 向けネットワーク入門OpenStack 向けネットワーク入門
OpenStack 向けネットワーク入門
 
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)
OpenStackで始めるクラウド環境構築入門(Horizon 基礎編)
 
Jenkins study jenkins build-cicdi
Jenkins study jenkins build-cicdiJenkins study jenkins build-cicdi
Jenkins study jenkins build-cicdi
 
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説
『これからの.NETアプリケーション開発』セミナー .NET用アプリケーション フレームワーク Open 棟梁 概説
 
.NET Core とマルチプラットフォーム
.NET Core とマルチプラットフォーム.NET Core とマルチプラットフォーム
.NET Core とマルチプラットフォーム
 
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorks
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorksAWS Black Belt Tech シリーズ 2015 - AWS OpsWorks
AWS Black Belt Tech シリーズ 2015 - AWS OpsWorks
 
Cld002 windows server_2016_で作るシンプ
Cld002 windows server_2016_で作るシンプCld002 windows server_2016_で作るシンプ
Cld002 windows server_2016_で作るシンプ
 
実践で学んだLog Analytics
実践で学んだLog Analytics実践で学んだLog Analytics
実践で学んだLog Analytics
 

More from junichi anno

V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...
V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...
V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...junichi anno
 
Microsoft Azure のセキュリティ
Microsoft Azure のセキュリティMicrosoft Azure のセキュリティ
Microsoft Azure のセキュリティjunichi anno
 
Azure AD によるリソースの保護 how to protect and govern resources under the Azure AD
Azure AD によるリソースの保護 how to protect and govern resources under the Azure ADAzure AD によるリソースの保護 how to protect and govern resources under the Azure AD
Azure AD によるリソースの保護 how to protect and govern resources under the Azure ADjunichi anno
 
Azure AD による Web API の 保護
Azure AD による Web API の 保護 Azure AD による Web API の 保護
Azure AD による Web API の 保護 junichi anno
 
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~junichi anno
 
個人情報を守るための アプリケーション設計(概要)
個人情報を守るためのアプリケーション設計(概要)個人情報を守るためのアプリケーション設計(概要)
個人情報を守るための アプリケーション設計(概要)junichi anno
 
IoT のセキュリティアーキテクチャと実装モデル on Azure
IoT のセキュリティアーキテクチャと実装モデル on AzureIoT のセキュリティアーキテクチャと実装モデル on Azure
IoT のセキュリティアーキテクチャと実装モデル on Azurejunichi anno
 
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計junichi anno
 
Azureの管理権限について
Azureの管理権限について Azureの管理権限について
Azureの管理権限について junichi anno
 
Azure Active Directory 1枚資料 20151125版
Azure Active Directory 1枚資料 20151125版Azure Active Directory 1枚資料 20151125版
Azure Active Directory 1枚資料 20151125版junichi anno
 
リソーステンプレート入門
リソーステンプレート入門リソーステンプレート入門
リソーステンプレート入門junichi anno
 
File Server on Azure IaaS
File Server on Azure IaaSFile Server on Azure IaaS
File Server on Azure IaaSjunichi anno
 
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...junichi anno
 
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版junichi anno
 
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現junichi anno
 
クラウドにおける Windows Azure Active Directory の役割
クラウドにおける Windows Azure Active Directory の役割クラウドにおける Windows Azure Active Directory の役割
クラウドにおける Windows Azure Active Directory の役割junichi anno
 

More from junichi anno (17)

V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...
V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...
V1.1 CD03 Azure Active Directory B2C/B2B コラボレーションによる Customer Identity and Ac...
 
Microsoft Azure のセキュリティ
Microsoft Azure のセキュリティMicrosoft Azure のセキュリティ
Microsoft Azure のセキュリティ
 
Azure AD によるリソースの保護 how to protect and govern resources under the Azure AD
Azure AD によるリソースの保護 how to protect and govern resources under the Azure ADAzure AD によるリソースの保護 how to protect and govern resources under the Azure AD
Azure AD によるリソースの保護 how to protect and govern resources under the Azure AD
 
Azure AD による Web API の 保護
Azure AD による Web API の 保護 Azure AD による Web API の 保護
Azure AD による Web API の 保護
 
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~
Azure ad の導入を検討している方へ ~ active directory の構成パターンと正しい認証方式の選択~
 
Azure Key Vault
Azure Key VaultAzure Key Vault
Azure Key Vault
 
個人情報を守るための アプリケーション設計(概要)
個人情報を守るためのアプリケーション設計(概要)個人情報を守るためのアプリケーション設計(概要)
個人情報を守るための アプリケーション設計(概要)
 
IoT のセキュリティアーキテクチャと実装モデル on Azure
IoT のセキュリティアーキテクチャと実装モデル on AzureIoT のセキュリティアーキテクチャと実装モデル on Azure
IoT のセキュリティアーキテクチャと実装モデル on Azure
 
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計
DevSecOps: セキュリティ問題に迅速に対応するためのパイプライン設計
 
Azureの管理権限について
Azureの管理権限について Azureの管理権限について
Azureの管理権限について
 
Azure Active Directory 1枚資料 20151125版
Azure Active Directory 1枚資料 20151125版Azure Active Directory 1枚資料 20151125版
Azure Active Directory 1枚資料 20151125版
 
リソーステンプレート入門
リソーステンプレート入門リソーステンプレート入門
リソーステンプレート入門
 
File Server on Azure IaaS
File Server on Azure IaaSFile Server on Azure IaaS
File Server on Azure IaaS
 
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...
Active Directory のクラウド武装化計画 V2~"AD on Azure IaaS" or "Windows Azure Active Di...
 
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版
勉強会キット Windows Server 2012 R2 評価版 BYOD 編 v2 20131020 版
 
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現
最新Active DirectoryによるIDMaaSとハイブリッド認証基盤の実現
 
クラウドにおける Windows Azure Active Directory の役割
クラウドにおける Windows Azure Active Directory の役割クラウドにおける Windows Azure Active Directory の役割
クラウドにおける Windows Azure Active Directory の役割
 

Recently uploaded

SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 

Recently uploaded (9)

SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 

Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版

  • 1. 1 Windows PowerShell による Windows Server 管理 V 4.0 2014.3.13 版 日本マイクロソフト株式会社 エバンジェリスト 安納 順一 http://blogs.technet.com/junihia/ 第1部 基礎から学ぼう Part1 基礎の基礎編 Part2 リモーティング編 Part3 バックグラウンドジョブ編 Part4 ワークフロー編 Part5 開発者編 第2部 Hyper-V の管理 Part1 Hyper-V の立ち上げまで Part2 ライブマイグレーション
  • 2. 2 第1部 PowerShell を基礎から学ぼう Part1 基礎の基礎編 Part2 リモーティング編 Part3 バックグラウンドジョブ編 Part4 ワークフロー編 Part5 開発者編
  • 3. 3 第1部 ~ PowerShell を基礎から学ぼう Part1 基礎の基礎編 1.Windows PowerShell の位置づけ 2.基本的なコマンドレットと書式の基礎 3.基本的な文法とスクリプトの作り方 4.Tips Part2 リモーティング編 5.リモーティングの準備と基礎 6.-ComputerNameを使用したリモート操作 7.PS セッションとは 8.コネクションの永続化と再利用可能なPSセッション 9.Windows PowerShell Web Access(PSWA) Part3 バックグラウンドジョブ 10. バックグラウンドジョブ Part4 ワークフロー編 11. Windows PowerShell Workflow とは 12. Windows PowerShell Workflow の基礎 13. ワークフロー特有の記述 14. ワークフロージョブとデータの永続化 Part5 開発者編 15. 開発者にとっての Windows PowerShell とは 16. 開発者のための Windows PowerShell 基礎知識 17. 開発者として必要な情報の取得 18. コマンドレット以外からオブジェクトのインスタン スを作成する 19. Visual Studio(C#)から PowerShell を呼び出す Windows PowerShell には他にもさまざまなテクニックが用意されています。特に、バック グラウンドジョブの概念はシステム管理を行う上で重要です。
  • 6. 6 Windows PowerShell の位置づけ Windows Familiar – インフラエンジニアから見ると • Windows Script(WSH)に変わる管理プラットフォーム • 高機能なスクリプティング機能による自動管理 • WinRM を介したリモートサーバー管理 Windows Familiar – 開発者 から見ると • 高機能なクラスライブラリ • コーディング、テスティングの大幅なコスト削減 Non-Windows Familiar から見ると • OMI(Open Management Infrastructure)を実装したリモートサーバー • 手元のプラットフォームからリモート管理が可能 • 使い慣れた言語からリモート管理が可能
  • 7. 7 代表的なスクリプト言語 バッチファイル(拡張子 .bat) VBScript(拡張子 .vbs) PowerShell(拡張子 .ps1) Jscript(拡張子 .js) MS-DOS時代から使われてきたコマンドシェル上のスクリプト。脈々と現代に引き継がれて おり、利用者が多い。豊富なコマンド群によって支えられており、案外使い出がある。複数 のスクリプトを取りまとめる役割としても便利。 Visual Basic のスクリプト版。「Visual」とあるが、Visual ではない。わかりやすい文法と、 緩い規則によって根強いファンが多い。亜種として VBA もあるが微妙に文法は異なる。 JavaScript のMS 実装版として、VBScript とともに登場。JavaScript を Microsoft の独自 仕様によって拡張することで、汎用性を増している。 いわずと知れた高機能スクリプト言語。.NET Framework が使えると言うメリットから、利 用者は爆発的に増殖中。多くの製品がPowerShell用のコマンドレットを提供しており、 Windows Script Host は Server Coreのメニュー程度でしかお目にかかれなくなりつつある。 Windows Script 今後エンハンスの予定は無い OSに合わせて継続的なエンハンス 今後エンハンスの予定は無い
  • 8. 8 Windows .NET Framework PowerShell スクリプト exe bat VBScript JScript Script Engine CLR(共通言語ランタイム) Class Library スクリプトの実行環境 PowerShell エンジン COM cmd/ command Windows Script Host Cscript.exe Wscript.exe C O M
  • 9. 9 コマンドシェルの進化と機能の包含 cmd.exe command.com 高機能 NT 低機能 DOS/ Win31 2000 XP/2003 Vista/2008 Windows Script Host PowerShell 上では bat/vbs/js も実行可能 Win9x/ Me Win7/ 2008R2 Windows PowerShell 8 100 200 約 2300 コマンドレットの数
  • 10. 10 VBScript vs PowerShell Exchange 2003 (VBScript) Exchange 2007(PowerShell) メール ボックス 統計 Set listExchange_Mailboxs = GetObject("winmgmts:{impersonationLevel=impersonate}!¥¥COMPUTERNAME¥ROOT¥MicrosoftExchangeV2").InstancesOf("Excha nge_Mailbox") For Each objExchange_Mailbox in listExchange_Mailboxs WScript.echo "AssocContentCount =” + objExchange_Mailbox.AssocContentCount WScript.echo " DateDiscoveredAbsentInDS =” + objExchange_Mailbox.DateDiscoveredAbsentInDS WScript.echo " DeletedMessageSizeExtended =" + objExchange_Mailbox.DeletedMessageSizeExtended WScript.echo " LastLoggedOnUserAccount =" + objExchange_Mailbox.LastLoggedOnUserAccount WScript.echo " LastLogoffTime =" + objExchange_Mailbox.LastLogoffTime WScript.echo " LastLogonTime =" + objExchange_Mailbox.LastLogonTime WScript.echo " LegacyDN =" + objExchange_Mailbox.LegacyDN WScript.echo " MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayName WScript.echo " MailboxGUID =" + objExchange_Mailbox.MailboxGUID WScript.echo " ServerName =" + objExchange_Mailbox.ServerName WScript.echo " Size =" + objExchange_Mailbox.Size WScript.echo " StorageGroupName =" + objExchange_Mailbox.StorageGroupName WScript.echo " StorageLimitInfo =" + objExchange_Mailbox.StorageLimitInfo WScript.echo " StoreName =" + objExchange_Mailbox.StoreName WScript.echo " TotalItems =" + objExchange_Mailbox.TotalItems Next get-mailboxstatistics –server $servername データ ベース 管理 Dim StorGroup as New CDOEXM.StorageGroup StorGroup.DataSource.Open "LDAP://" + DCServer + "/ CN=First Storage Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group, CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services, CN=Configuration," + DomainName StorGroup.MoveLogFiles("C:¥newlogPath", 0) move-storagegrouppath -identity "First Storage Group" –log "C:¥newlogPath" 受信者 管理 Dim objMailbox As CDOEXM.IMailboxStore Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName) objMailbox.CreateMailbox "LDAP://" + DCServer + "/CN=Private MDB,CN=First Storage Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group, CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services, CN=Configuration," + DomainName enable-mailbox -identity domain¥FOO –database "First Storage Group¥Private MDB"
  • 11. 11 WBEM - Web Based Enterprise Management http://www.dmtf.org/standards/wbem マイクロソフトやインテル、シスコシステムズ、旧コンパック・コンピュータなどによって提案され、標準化 団体DMTF(Desktop Management Task Force)によって標準化された規格である。その名の通り、「Web ベー スのエンタープライズ管理」のための仕様であり、ネットワーク上に存在するサーバーや OS、ネットワーク 機器などの統合管理に必要なプロトコルやデータ構造を規定する。要するに、従来の SNMP(Simple Network Management Protocol)や syslog に代わる、HTTP と XML をベースとした新世代のネットワーク管理プロトコ ルである。すでにマイクロソフト Windows や HP-UX などのおもなOSをはじめ、サーバー製品、ストレージ製 品、ネットワーク機器、そしてHP OpenView をはじめとするネットワーク管理ツールにおいて、業界標準の ネットワーク管理プロトコルとしてサポートされている。 出典 http://h50146.www5.hp.com/products/software/oe/hpux/developer/column/smh_02/
  • 15. 15 History of Microsoft Management Framework 2000年 Windows 2000 に WMI をインプリメント – 29 WMI プロバイダを含む – 同時に Windows NT, 98, 95 用の WMI もダウンロード開始 (15 WMI プロバイダー) ※どちらかといえば ”プロバイダー” 提供ベンダー向けのテクノロジー ※ Windows ファミリ間の相互運用性に留まる 2005年 WS-Management が DMTF へ提出、承認 2007年 Windows Server 2008 に WS-Management を実装(WinRM) • HTTP/S を介して他プラットフォームとの接続が可能に • Windows PowerShell で WinRM を介したリモートサーバー管理が標準手法 として取り込まれる WS-Management とは Web Services for Management のこと。Windows Server ではない。
  • 16. 16 Windows Management Framework http://www.microsoft.com/downloads/ 前提条件 • Windows PowerShell ISE がインストールされていること • Microsoft .NET Framework 4.0 がインストールされていること OS WMF 3.0 WMF 4.0 Windows 7 SP1 以降 SP1 以降 Windows Server 2008 SP2 以降 × Windows Server 2008 R2 SP1 以降 SP1 以降 Windows 8 標準 8.1にアップグレード Windows 8.1 ー 標準 Windows Server 2012 標準 ○ Windows Server 2012 R2 ー 標準
  • 17. 17 Windows Management Framework Windows Management Framework IT Pro IT Developer Solution Developer Storage Network DevicesCPU Windows PowerShell CIMOM、SMI-S 標準化されたアクセス 標準化されたプロトコル 標準化された オブジェクトモデル WS-Management(WinRM) (Web Service for Management) http 他の プラットフォーム Service Provider 開 発 WS-Man CIMOM、 SMI-S SMI-S(Storage Management Initiative - Specification) 誰が作るの?
  • 18. 18 The Open Group Membership 2012/10/5 時点 Platinum - 5 • Capgemini Netherlands • Hewlett-Packard USA • IBM USA • Kingdee Software (China) Co. Ltd China • Oracle Corporation USA Gold – 44(抜粋) • Microsoft Corporation USA • NTT Data Corporation • ReGIS Inc. Silver – 256 (Japan のみ抜粋) • Asahi Techneion Co., Ltd • AXE, Inc. • eflow Inc. • Information-technology Promotion Agency, Japan • Japan Aerospace Exploration Agency (JAXA) • Mizuho Information and Research Institute, Inc. • Nissan Motor Co., Ltd. • Nomura Research Institute, Ltd. • Rococo Co Ltd • SIOS Technology, Inc. • Sony CSL • Symphony Ltd. Academic – 38 (Japan のみ抜粋) • Aoyama Gakuin University • Kyoto University • Nagoya University • The University of Tokyo Information Technology Center
  • 19. 19 Open Management Infrastructure(nanoWBEM) • オープンソース版 CIM Server • 軽量 250KB、C で開発されている Windows PowerShell、その他 Providers : CIMOM,SMI-S WS-Management(OMI) Providers : CIMOM,SMI-S Storage Network DevicesCPUStorage Network DevicesCPU WS-Management(WinRM) 各種言語 WinRM Client WinRM Server OMI Client OMI Server
  • 20. 20
  • 21. 21 OMI サポート プラットフォーム • HP-UX 11i v2 and v3 (PA-RISC and IA64) • Sun Solaris 8 and 9 (SPARC) and Solaris 10 (SPARC and x86) • Red Hat Enterprise Linux 4 (x86/x64) and 5 (x86/x64) Server • Novell SUSE Linux Enterprise Server 9 (x86) and 10 SP1 (x86/x64) • IBM AIX v5.3 and v6.1 (POWER) • MacOS 10.5 (Intel) • Windows(限定的) 最新版は OMI Source - v.1.0.7a (2013年5月)
  • 23. 23 マイクロソフト製品と Windows PowerShell の関係 • 製品ごとに専用の”コマンドレット”が用意されている • 多くの管理 GUI は裏でコマンドレットを呼んでいる • インフラ担当者に、各製品への”標準化されたアクセス方法”を提供する Active Directory Active Directory PowerShell Module Active Directory 管理センター Hyper-V Hyper-V PowerShell Module System Center Virtual Machine Manager PowerShell コンソール
  • 24. 24 Windows PowerShell ISE • Powershell_ise.exe • Windows PowerShell 専用エディタ • IntelliSense に対応 スクリプトエディタ スクリプト実行画面 コマンドレットを直接実行 コ マ ン ド レ ッ ト 検 索 英語圏の人たちは”アイス” と読むらしい
  • 26. 26 事前準備 • コンソールの環境設定 • 簡易編集を有効に • エクスプローラー(フォルダー)の環境設定 • 「拡張子を表示しない」を無効に • 実行ポリシーの設定 ※オンプレミスの”署名無しスクリプト”を実行できるようにする • リモートからの操作を有効にする(リモーティングの有効化) • 必要に応じて自分専用の初期設定ファイルを作成(規定では存在しない) PS C:¥>Set-ExecutionPolicy RemoteSigned PS C:¥>Enable-PSRemoting –force PS C:¥>notepad $profile
  • 27. 27 実行ポリシーの設定~ Set-ExecutionPolicy • “管理者として実行” する必要がある • 実行ポリシー – Restricted:制限つき (オペレーターモード)(規定値) • 対話形式のみ • スクリプトは実行できない – AllSigned:署名 • スクリプトは、信頼された発行元による署名が必要 – RemoteSigned:リモートの署名(2012R2 の規定値) • “インターネットゾーン” のスクリプトは信頼された発行元による署名が必要 – Unrestricted:無制限 • すべてのスクリプトを実行可能 • リモートのスクリプトについては常に警告 – Bypass:バイパス • 何もブロックされず警告も表示されない http://technet.microsoft.com/ja-jp/library/dd347628.aspx “ポリシーの設定”は、規定では コンピューター全体に影響する。 適用範囲を制限するには、 Scope も同時に定義する。
  • 29. 29 コマンドレットとモジュール • PowerShell の実行単位は「コマンドレット」 • コマンドレットはモジュール(Module)によって提供される • モジュールが読み込まれていないとコマンドレットを使用することは できない(Import-Module <モジュール名>) Module CmdLet CmdLet CmdLet CmdLet Hyper-V Add-VMDvdDrive Add-VMFibreChannelHba Add-VMHardDiskDrive Add-VMMigrationNetwork Add-VMNetworkAdapter Add-VMNetworkAdapterAcl ・ ・ ・ Microsoft.PowerShell. Management Add-Computer Add-Content Checkpoint-Computer Clear-Content Clear-EventLog Clear-Item Clear-ItemProperty Complete-Transaction 構造 規定のモジュール 例
  • 30. 30 モジュールに関するコマンドレット • 読み込まれているモジュール一覧の取得 • 使用可能なモジュール一覧の取得 • モジュールを読み込む • 使用可能なモジュールを全て読み込む PS C:¥> Get-Module PS C:¥> Get-Module -ListAvailable PS C:¥> Import-Module <モジュール名> PS C:¥> Import-Module Hyper-V PS C:¥> Import-Module (Get-Module -ListAvailable).Name
  • 31. 31 コマンドレット情報を取得する • 使用可能なコマンドレット一覧を取得する • “-VM” という文字列を含むコマンドレットの一覧 • 特定のモジュール内のコマンドレット一覧 • コマンドレットの書式 PS C:¥> Get-Command PS C:¥> Get-Command *-vm* -CommandType Cmdlet PS C:¥> Get-Command -Module Hyper-V PS C:¥> Get-Help <コマンドレット> -detailed PS C:¥> Get-Help Move-VM -detailed
  • 33. 33 コマンドレットの戻り値 • コマンドレットの戻り値は“オブジェクト”である • PowerShell はオブジェクトを操作する言語 • 戻り値を「どのように操作できるか」を知っていることが重要 • オブジェクトには「メソッド」と「プロパティ」が用意されている 戻り値を直接、”操作”することが可能 Get-Service サービス一覧 オブジェクト stop()
  • 36. 36 メソッドとプロパティを調べるには • コマンドレットのメソッドとプロパティを表示 ※ COMのメンバーも取得できる New-Object -com scripting.filesystemobject | Get-Member • サービスに対して行える操作を取得する • 仮想マシンに対して行える操作を取得する <コマンドレット> | get-member <コマンドレット> | get-member | sort-object Name | format-list Get-Service | Get-Member Get-VM | Get-Member
  • 37. 37 TIPS オブジェクトであるということは... PS C:¥>$a = “abc” #普通ならば $a は”文字列” になるけれど... #オブジェクトだからメソッドとプロパティが用意されている PS C:¥>$a.ToUpper() PS C:¥>ABC PS C:¥>$a.ToUpper().Split("B")[0] PS C:¥>A
  • 38. 38 コマンドからの出力もオブジェクト化される PS C:¥> (ipconfig)[18].Split(":")[1].Trim() object ipconfig の 出力結果 の18行目 (0から数えて) IPv4 アドレス . . . . . . . . . . : 192.168.1.100 ipconfig の出力結果からIPアドレスを取りだす コロンで分割した (0から数えて)2 つ目の値 前後の空白を トリミング
  • 39. 39 PSドライブ ファイルシステムだけではなく、さまざまなオブジェクトがドライブとしてアク セス可能(CD コマンドで移動可能) モジュールが読み込まれて いないと使えないドライブ もある (例)ActiveDirectory  ファイルシステム  エイリアス(Alias:)  レジストリ(HKLM:、HKCU:)  証明書(Cert:)  環境変数(Env:)  変数(Variable:)  WSMAN設定(Wsman:)  Active Directory(AD:)  IIS(IIS:)  Remote Desktop Service(RDS:) PS C:¥> Get-PSDrive
  • 41. 41 スクリプトの拡張子は .ps1 $Server = $env:COMPUTERNAME $Adapter = "1" Do { $NIC = (Get-NetAdapter)[$Adapter] | Select-Object InterfaceDescription $NICName = $NIC.InterfaceDescription.Replace("#","_") $NICName = $NICName.Replace("(","[") $NICName = $NICName.Replace(")","]") $Perf = Get-Counter -Counter "¥¥$Server¥Network Interface($NICName)¥bytes total/sec" $TimeStamp = $Perf.Timestamp.ToString() $PValue = $Perf.CounterSamples.CookedValue * 8 / 1024 / 1024 $PerfData = $TimeStamp + "," + $Server + "," + $NICName + "," + [int]$PValue $PerfData } While(-1) GetNetCounter.ps1 C:¥tmp> .¥GetNetCounter.ps1
  • 42. 42 1. 起動中のサービス一覧  パイプライン  Where-Object による条件指定 2. 特定のサービスを停止する  () でオブジェクトを表現する 3. ネットワーク情報を取得する  出力結果のフォーマット変換 4. ネットワークの設定を変更する 5. ローカルコンピューター名を変更する  変数の宣言  変数の遅延展開  Array 値  ハッシュテーブル  環境変数 6. リモートからコンピューター名を変更する ※標準コマンドレット or WMI  クレデンシャルの使い方  WMI に必要なアクセス権 7. ドメインに参加させる ※標準コマンドレット or WMI 8. 複数のコンピューターをドメインに参加させる  スクリプトの継続行  ファイルの入出力方法  ファイルのコード変換  CSV のヘッダー行について  繰り返し処理 9. イベントログを収集する  Select-Object により必要な要素のみを取り出す 10. イベントログをバックアップする 11. 独自のイベントログを登録する 12. 仮想マシンを作成して起動する  スクリプトの引数を定義する  名前付き引数 13. Hyper-V ライブマイグレーションを実行する 14. パフォーマンスログを取得する 15. 役割と機能をインストールする 16. 仮想ドメインコントローラを複製する 17. Hyper-V 仮想スイッチを作成する 18. リモートコンピューターから機能を一括で削除する 19. リモートコンピューターを一括でシャットダウンする 20. すべての Hyper-V ホストの仮想マシンを強制的にシャッ トダウンする 21. すべてのHyper-V ホストのライブマイグレーションを有効 化する
  • 43. 43 PS C:¥>get-service | where-object {$_.Status -eq "Running"} 1.起動中のサービス一覧を取得する パイプ サービス一覧 を出力 object サービス一覧 オ ブ ジ ェ ク ト の ま ま 渡 さ れ る object サービス一覧
  • 44. 44 PS > Get-Service | Where-Object Status -EQ "Running" | Select-Object Name, Servicetype | Sort-Object ServiceType コマンドレット1 コマンドレット2 入力パラメタ コマンドレット3 結果 結果 入力パラメタ • サービスの一覧を取得 • Status が Running のみを抽出 • Name プロパティとServiceType プロパティを抽出 • ServiceType でソート オブジェクト パイプラインについて PS > Get-Service | Where-Object {$_.Status -EQ "Running"} | Select-Object -Property Name, Servicetype | Sort-Object -Property ServiceType V3ではこう書ける
  • 45. 45 TIPS 条件を指定して結果を絞り込む Where-Object #サイズが1024バイト以上のファイルを検索する Dir | Where-Object {$_.length -GT 1024} ` |Select-Object Name,length #Active Directory のユーザー名に”a”を含むユーザーを取得する Get-ADUser -Filter * ` |Where-Object {$_.name -Like “*a*”} ` | ForEach-Object name
  • 46. 46 TIPS PS 3.0 では書式を簡略化できます PS C:¥>get-service | where-object {$_.Status -eq "Running"} PS C:¥>get-service | where-object Status -eq "Running" V3 ではこう書ける
  • 47. 47 2.特定のサービスを停止する PS C:¥>(Get-Service -Name WSearch).Stop() メソッド Windows Search サービスの インスタンスを取得 object Windows Search インスタンスに対して メソッドを実行 PS C:¥>Stop-Service WSerarch
  • 49. 49 3.ネットワーク情報を取得する PS C:¥> Get-NetAdapter | FL Name, InterfaceIndex, MacAddress PS C:¥> Get-NetIPAddress -InterfaceIndex 28 -AddressFamily IPv4 ネットワークアダプタの一覧 IP アドレスの取得 Format-List の略
  • 50. 50 TIPS 出力結果のフォーマットを変換 dir | format-table Name,Length dir | format-list Name,Length dir | format-wide Name -column 6 dir | out-gridview
  • 51. 51 4.ネットワークの設定を変更する PS C:¥>New-NetIPAddress -InterfaceIndex 24 -IPAddress 192.168.205.102 -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway 192.168.205.254 PS C:¥> Remove-IPAddress -InterfaceIndex 24 -AddressFamily IPv4 静的なIPV4アドレスを設定する IP アドレスの削除 PS C:¥>Set-DnsClientServerAddress -Interface 24 -ServerAddress 192.168.205.1, 192.168.205.3 DNS の設定 既存の静的アドレスを変更する場合には Set-NetIPAddress を使用する PS C:¥> Set-DnsClientServerAddress -Interface 24 -ResetServerAddress DNSの設定を削除する PS C:¥> Set-NetIPInterface -InterfaceIndex 24 -Dhcp Enabled DHCP を有効にする
  • 52. 52 5.ローカルコンピューター名を変更する PS C:¥> $Env:ComputerName ローカルコンピューター名の取得 PS C:¥> (Get-WmiObject -Class Win32_ComputerSystem).Name PS C:¥> $New_ClientName = “New_ClientName” PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem PS C:¥> $SysInfo.Rename($New_ClientName) PS C:¥> Restart-Computer ローカルコンピューター名の変更 方法1 方法2 C:¥> Rename-Computer -NewName “tfwin8-xx” -Force -Restart WMI を使用する場合 標準のコマンドレットを使用する場合
  • 53. 53 TIPS 変数を使うには $FirstName = "Junichi" $LastName = "Anno" $FullName = $FirstName + " " + $LastName Write-Output $FullName $arrFullName = $FullName.Split(" ") Write-Output $arrFullname[0] PS C:¥> C:¥hogehoge.ps1 Junichi Anno Junichi 出力結果
  • 54. 54 TIPS 変数の宣言について 通常は自動判別 PS > $A = 1 PS > $B = “1” PS > $A + $B 2 PS > $B + $A 11 PS > $A = “abc” PS > $A + $B abc1 System.Int32 System.String 先にある System.Int32 に自動変換 先にあるSystem.String に自動変換 System.String で置き換えが可能 自動変換できない値で あればエラーとなる
  • 55. 55 明示的に宣言することも可能 PS > [System.Int32] $A = 1 PS > [System.String] $B = “abc” PS > [System.Array] $C = “今年は”, 2012, “年です” PS > $A = 987.654 PS > $A 988 PS > $A = “Hello” Cannot convert value "Hello" to type "System.Int32“ PS > [System.String] $A = “Hello” 明に宣言すると自動変換はできない Int32 にキャストされる 0: 今年は 1: 2012 2: 年です [System.String] [System.Int32] [System.String]
  • 56. 56 変数を削除する PS > [System.Int32] $A = 1 PS > Remove-Variable A PS > Get-Variable | Remove-Variable 自分で作成した変数を全て削除 ※削除できないものについてエラーが出る
  • 57. 57 TIPS 変数の展開について PS >$FirstName = "Junichi" PS >$LastName = "Anno" PS >$FullName = “$FirstName $LastName” PS >Write-Output $FullName Junichi Anno PS >$FullName = ‘$FirstName $LastName’ PS >Write-Output $FullName $FirstName $LastName ダブルクオーテーションで 括った場合は変数は展開さ れる シングルクオーテーション で括った場合には変数は展 開されない
  • 58. 58 TIPS 変数の遅延展開 PS > $Name = “Junichi” PS > $Message = “Hello $Name” PS > $Message Hello Junichi PS > $Name = “Junichi” PS > $Message = { “Hello $Name” } PS > $Name = “Taro” PS > $Message Hello $Name PS > & $Message Hello Taro {} で括ると変数は展開されない Echo の代わりに & を使用 通常 遅延展開 $Message を定義した後で $Name に値を入れているこ とに注意 この時点で変数は展開される
  • 59. 59 PS > $Message = { Param( $Name ) “Hello $Name” } PS > & $Message Junichi Hello Junichi 遅延展開を利用して関数として定義
  • 60. 60 TIPS Array 値 PS > $Users = @() PS > $Users = “Junichi”, ”Naoko”, “Kazunori” PS > $Users.Count 3 PS > $Users Junichi Naoko Kazunori PS > $Users += “Maki” PS > $Users += 512 PS > $a = { [system.math]::Pow( 2, $N ) } PS > $Users += $a Array の作り方 空のアレイを作成(あえてしなくてもよい) 値を追加 数値を追加 遅延展開変数を追加 {}で括っているので遅延展開変数
  • 61. 61 Array 値の参照 PS > $Users[3] Maki PS > $Users[-1] PS > $N = 6 PS > & $Users[5] 64 PS > Foreach ($u in $Users) { New-ADUser -Name $u } PS > $Users[2..4] PS > ($Users -eq “Kazunori”).Count PS > $Users -ne “Kazunori” PS > $Users -like “*M*” $users から値を取りだし ながらユーザーを作成 配列の2番から4番を取りだす 遅延展開変数の入った行を参照 配列の一番最後 Kazunori 以外のものを抽出 kazunori と一致するものがあるかどうかを検査 M が含まれる行を抽出
  • 62. 62 PS > $arrINT = 1,2,3,4,5,6,7,8,9 PS > $arrINT -ge 5 PS > $Users += $arrINT PS > $Users | Sort-Object $_ PS > $Users = $Users -ne “Kazunori” PS > [System.Array]::Reverse($Users) 2つの配列を合成 昇順に並べ替えて出力 Kazunori を削除 Users の中の並び順を逆にする 2つの配列を合成
  • 63. 63 空白を文字列で埋める(PadLeft / PadRight) ## $N[] に、001 ~ 100 の文字列を格納する PS > $N = @() PS > 001..100 | % { $N += ("$_").Padleft(3,"0")} PS > User$N 001 002 ・ 100 PS > $VMs = $N | % {echo VM$_} PS > $VMs VM001 VM002 ・ VM100
  • 64. 64 TIPS HashTable PS > $Users = @{} PS > $Users.0001 = “Junichi” PS > $Users.”0001” = “Junichi” PS > $Users.Add( “0001”, “Junichi” ) PS > $Users.Remove(“0001”) HashTable の作り方 注意 Array は () キー 1 に 値 Junichi を登録 キー 0001 に 値 Junichi を登録 キー 0001 の行を削除
  • 65. 65 PS > $USDJPY = Import-CSV -Path C:¥tools¥USDJPY.csv –Encoding Default PS > $HT = @{} PS > While ( $i -lt $USDJPY.Count ) {$HT.Add( $USDJPY.日付[ $i ], $USDJPY.終値 [ $i ] ) ; $i++ } PS > $HT.”2012/2/10” 77.65 CSV ファイルから値を読み込んでHashTable を作成
  • 67. 67 6.コンピューター名を変更する(リモートから) ##スタンドアロンのコンピューターの場合 PS C:¥> $ClientName = “ClientName” PS C:¥> $Cred = Get-Credential PS C:¥> $New_ClientName = “New_ClientName” PS C:¥> Rename-Computer -ComputerName $ClientName -LocalCredential $Cred -NewName $New_ClientName -Force -Restart ##ドメインに参加しているコンピューターの場合 PS C:¥> $ClientName = “ClientName” PS C:¥> $Cred = Get-Credential PS C:¥> $New_ClientName = “New_ClientName” PS C:¥> Rename-Computer -ComputerName $ClientName -DomainCredential $Cred -NewName $New_ClientName -Force -Restart 標準のコマンドレットを使用する
  • 68. 68 PS C:¥> $ClientName = “ClientName” PS C:¥> $Cred = Get-Credential PS C:¥> $New_ClientName = “New_ClientName” PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ClientName -Credential $Cred PS C:¥> $SysInfo.Rename($New_ClientName) PS C:¥> Restart-Computer -ComputerName $ClientName -Credential $cred -Force WMI を使用する Server Client変更 WMI
  • 69. 69 TIPS クレデンシャルの作成 その1 PS C:¥> $Cred = Get-Credential その2 PS C:¥> $user = “administrator“ PS C:¥> $pass = ConvertTo-SecureString "P@ssw0rd“ -AsPlainText -Force PS C:¥> $Cred = New-Object System.Management.Automation.PSCredential $user, $pass ポップアップが表示される
  • 70. 70 TIPS WMI Tester http://technet.microsoft.com/en-us/library/cc782719(v=ws.10) • WMI への接続性をテストするツール • リモートコンピューターへの接続も テストできる
  • 71. 71 TIPS 非ドメインメンバーから WMI接続 が拒否される原因と対処 代表的なエラー番号 • 0x800706ba • 0x80041003 • 0x80070005 代表的な原因 • Firewall の設定 • アクセス権
  • 72. 72 必要なアクセス権 • Distributed COM Users メンバーである こと • (規定では)システム管理者であること ※wmimgmt.msc で変更可能
  • 73. 73 必要な Firewall の設定 • Windows Management Instrumentation のルール
  • 74. 74 7.ドメインに参加させる PS C:¥> $Domain = “tf.com” PS C:¥> $Client = “ClientComputer” PS C:¥> $LocalCred = Get-Credential junichia PS C:¥> $DomainCred = Get-Credential tf¥administrator PS C:¥> $Admin = “tf¥administrator” PS C:¥> $Pass = “P@ssword” PS C:¥> Add-Computer -ComputerName $Clienit -LocalCredential $Cred -Credential $DomainCred -DomainName $Domain -OUPath “OU=営業部” -Restart -Force Server AD Domain 参加指示 Client Client Workgroup Client 標準のコマンドレットを使用する
  • 75. 75 PS C:¥> $Domain = “tf.com” PS C:¥> $Client = “ClientComputer” PS C:¥> $Cred = Get-Credential junichia PS C:¥> $Admin = “tf¥administrator” PS C:¥> $Pass = “P@ssword” PS C:¥> $SysInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ClientComputer -Credential $Cred -Authentication PacketPrivacy PS C:¥> $SysInfo.JoinDomainOrWorkgroup($Domain, $Pass, $Admin, “OU=xx”, 3 ) PS C:¥> Restart-Computer -ComputerName $Client -Credential $Cred -Force 認証に関する通信を暗号化する これを指定しないと以下のエラー “Client connection to WINMGMT needs to be encrypted for this operation. Please adjust your IWbemServices proxy security settings and retry. ” 1: ドメインに参加 + 2: コンピューターアカウントの作成 WMIのクラスを直接使用する
  • 76. 76 8.複数のコンピューターをドメインに参加させる # 各種定数の設定 $Cred = Get-Credential junichia $Domain = "tf.com" $Admin = "tf¥administrator" $Pass = "P@ssword" # いったん、SJISで作成したファイルを読み込み、UNICODEで保存する $InputFile = "C:¥Tools¥Computers.csv" $OutputFile = "C:¥Tools¥Computers_unicode.csv" Get-Content $InputFile -Encoding String | Out-File $OutputFile -Encoding unicode # CSVファイルを読み込む $Computers = Import-Csv -Path $OutputFile -Header ComputerName,IPAddress,Department -Delimiter "," # コンピューター名と部署を取り出し、ドメインに参加させる ForEach ($c in $Computers) { $Client = $c.ComputerName $OU = "OU=" + $c.Department + ",DC=TF,DC=COM $SysInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Client ` -Credential $Cred -Authentication PacketPrivacy $SysInfo.JoinDomainOrWorkgroup($Domain, $Pass, $Admin, $OU , 3 ) Restart-Computer -ComputerName $Client -Credential $Cred -Force } ServerCSV Client Client tfwin8-01,192.168.205.101,経理部 tfwin8-02,192.168.205.102,営業部 ・ ・ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  • 77. 77 TIPS 行継続 アクサン グラーブ記号 (`) を使用する copy-item C:¥tmp¥*.txt ` -destination C:¥ こ い つ
  • 78. 78 TIPS 入出力方法 #標準出力 Write-Output “Hello” Echo “Hello” #標準入力 $InputData = Read-Host #ファイルに出力 Out-File -filepath C:¥tmp¥list.txt -inputobject $Record #ファイルから入力 $file = Get-Content -Path c:¥tmp¥list.txt $file = type c:¥tmp¥list.txt #CSVファイルから入力 $file = Import-CSV -Path c:¥test.csv これを抑えておけば、ひとまずたいていのことはできます
  • 79. 79 TIPS 出力方法の違い PS C:¥> 1 + 2 + 3 6 PS C:¥> Echo “Windows PowerShell” Windows PowerShell PS C:¥> Write-Output 1 + 2 + 3 1 + 2 + 3 PS C:¥> Echo Windows PowerShell Windows PowerShell 空白で区切られる PS C:¥> Windows PowerShell <エラー> ※ Echo は Write-Output のAlias PS C:¥> “1” + “2” + “3” 123
  • 80. 80 TIPS ファイルのコード変換 SJIS作成したファイルは日本語が正しく扱われないことがある ∴ Get-Content で読み込み、Out-File でUnicodeで保存する Get-Content -Path $Input -Encoding String | ` Out-File -Encoding UNICODE 指定可能な文字コード String Unicode Byte BigEndianUnicode UTF8 UTF7 UTF32 Ascii Default Oem
  • 81. 81 TIPS Import-CSV でのヘッダーの取り扱いについて • 規定では、1行目はヘッダーとして扱われる • ヘッダーが無い場合には -Header パラメタで指定可能 • -Header を指定すると1行目はデータとして扱われる • ヘッダー単位(列単位)で取り出しが可能 ComputerName, IPAddress, Department tfwin8-01,192.168.205.101,経理部 tfwin8-02,192.168.205.102,営業部 ・ ・ $Computers = Import-Csv -Path $OutputFile -Header ComputerName,IPAddress $Computers.IPAddress
  • 83. 83 TIPS 繰り返し処理1 #ForEach-Object Get-ADUser -Filter * | ForEach-Object {$_.name} Get-ADUser -Filter * | ForEach-Object name #foreach $Users = Get-ADUser -Filter * foreach ($user in $Users) { $user.name } Active Directory ユーザー一覧から name プロパティをリストする V3
  • 84. 84 TIPS 繰り返し処理2 #1から10までを出力 1..10 #1から10 をリダイレクトして出力 1..10 | % {echo $_ } #User1 から User10 を作成 1..10 | % {New-ADUser “User$_” } ※ % は foreach のエイリアス
  • 85. 85 TIPS 繰り返し処理3 $i = 0 do { Write-Host $i $i++ } while ($i -lt 10) $i = 0 do { Write-Host $i $i++ } until ($i -ge 10)
  • 86. 86 9.イベントログを収集する C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -Newest 10 リモートコンピューターのセキュリティログから、最新10個のログを取りだす 特定の日時範囲のログを取りだす C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -After “2012/6/1 00:00:00” -Before “2012/6/1 00:10:00” 特定のイベントIDを取りだす C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -InstanceID 4632 失敗した監査を取りだす C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -EntryType FailureAudit メッセージに “ログオン” という言葉が含まれているログを取りだす C:¥> Get-EventLog -LogName Security -ComputerName tfdc01 -Message “*ログオン*”
  • 87. 87 C:¥> Get-EventLog -LogName Application | Group-Object -Property EntryType -NoElement イベントログを集計する C:¥> Get-EventLog -LogName Application |Group-Object -Property Source,EntryType -NoElement | Select-Object Name,Count
  • 88. 88 TIPS Select-Object で必要な要素のみを取りだす 結果から必要な要素だけを抜き出して処理する パイプの後ろで使用することをお勧め(なんかおかしい...) PS C:¥> $Data = Dir × PS C:¥> Select-Object -InputObject $Data -Property Name ○ PS C:¥> $Data | Select-Object -Property Name 重複データを除く $data |Select-Object -Unique -Property Name 最後の10個だけ取得 $data | Select-Object -Last 10 最初の5個だけ取得 $data | Select-Object -First 5
  • 89. 89 10. イベントログをバックアップする C:¥> $logFileName = "Security" C:¥> $exportFileName = "C:¥tmp¥" + $logFileName + (get-date -f yyyyMMddhhmmss) + ".evt" C:¥> $exportfilename C:¥> $logFile = Get-WmiObject Win32_NTEventlogFile | Where-Object {$_.logfilename -eq $logFileName} C:¥> $logFile.backupeventlog($exportFileName) セキュリティイベントログをローカルにバックアップする(EVT形式) PowerShell は管理者モードで起動してください
  • 90. 90 11.独自のイベントログを登録する C:¥> New-EventLog -Source "TechFielders" -LogName "TechFielders" ログファイル名 TechFielders、イベントソース TechFielders を新規に登録する C:¥> Write-EventLog -LogName TechFielders -Source “TechFielders” -EntryType Information -EventId 5963 -Message “元気出せこの野郎!1,2,3 ダァ!" TechFielders ログにイベントログを書き込む
  • 91. 91 12. 仮想マシンを作成して起動する param([string] $VMName = "NA", [int] $CPU = 1, [int] $Mem = 10MB) echo -InputObject $VMName, $CPU, $Mem $SwitchName = "Intel(R) 82579LM Gigabit Network Connection - Virtual Switch" New-VM -BootDevice CD ` -MemoryStartupBytes $Mem ` -Name $VMName ` -SwitchName $SwitchName ` -VHDPath ¥¥junichia-vdi¥$VMName¥$VMName.vhdx Set-VM -ProcessorCount $CPU -DynamicMemory -Name $VMName Add-VMNetworkAdapter -VMName $VMName -SwitchName $SwitchName Start-VM -Name $VMName 1 2 3 4 5 6 7 8 9 10 11 PS C:¥> .¥CreateVirtualMachine.ps1 -VMName “VM01" -Mem 1024mb CreateVirtualMachine.ps1
  • 92. 92 TIPS 引数を受け取る Write-Output $args[3] foreach ( $a in $args ) { Write-Output $a } C:¥> .¥hogehoge.ps1 My name is “Junichi Anno” . 5つの引数 My name is Junichi Anno . Junichi Anno
  • 93. 93 TIPS 名前付き引数の使い方(Param 句) param([string] $UserID = “ID", [string] $Password =“PASS") Write-Output $userid Write-Output $Password 引数を所定の名前の変数に格納することで、文法チェック等が行いやすくなる C:¥> .¥hogehoge.ps1 -userid anno anno PASS 実行結果 規定値
  • 94. 94 13. Hyper-V ライブマイグレーション $Source = “HostSV01” $Dist = “HostSV02” $VMs = get-vm -ComputerName $Source -Name VM* foreach ($VMName in $VMs.Name) { Move-VM -ComputerName $Source -Name $VMName -DestinationHost $Dist } Guest メモリ内データ ¥¥Server¥Share¥xxx.vhdx 構成情報 Guest Host01 Host01 $Source の中の VM で始ま るゲストOSを検索している
  • 95. 95 14. パフォーマンスログを取得する Do { $perf =Get-WmiObject -Class win32_perfformatteddata_perfos_processor ` -Property PercentProcessorTime foreach ($p in $perf) { $outrec = "Processor" + $i + ":" + $p.PercentProcessorTime echo $outrec } Start-Sleep -Seconds 1 cls } while (-1) 1 2 3 4 5 6 7 8 9 10 11 プロセッサー(コア単位)の利用率を1秒に1回取得して表示する 1秒スリープ 画面をクリア 目的のパフォーマンスカウン タ(今回はCPU使用率)が含ま れているWMIクラスを指定する
  • 96. 96 TIPS パフォーマンスカウンターの調査方法 パフォーマンスカウンタークラスの一覧を取得するには win32_perfformatteddata_perfos_processor クラスが持ってい るカウンターの一覧を取得する C:¥> Get-CimClass Win32_PerfFormatted* |ft CimClassName C:¥> Get-CimClass Win32_PerfRaw* |ft CimClassName C:¥> $PerfMon = Get-CimClass Win32_PerfFormattedData_perfos_processor C:¥> $PerfMon.CimClassProperties |ft Name
  • 97. 97 $Server = $env:COMPUTERNAME $Adapter = "1" Do { $NIC = (Get-NetAdapter)[$Adapter] | Select-Object InterfaceDescription $NICName = $NIC.InterfaceDescription.Replace("#","_") $NICName = $NICName.Replace("(","[") $NICName = $NICName.Replace(")","]") $Perf = Get-Counter -Counter "¥¥$Server¥Network Interface($NICName)¥bytes total/sec" $TimeStamp = $Perf.Timestamp.ToString() $PValue = $Perf.CounterSamples.CookedValue * 8 / 1024 / 1024 $PerfData = $TimeStamp + "," + $Server + "," + $NICName + "," + [int]$PValue $PerfData } While(-1) ネットワークアダプターのログを取得する 1 2 3 4 5 6 7 8 9 10 11 12 13
  • 99. 99 PS C:¥> Add-WindowsFeature -Name User-Interfaces-Infra -IncludeAllSubFeature -IncludeManagementTools ServerCore にすべての GUI をインストールする(フルインストール) PS C:¥> Add-WindowsFeature –Name Server-gui-mgmt-infra -IncludeManagementTools ServerCore に管理ツールだけをインストールする(MinShell)
  • 100. 100 (参考)Windows Server 2012 GUI オプション Server Core MinShell Server W/GUI Desktop Experience コマンドプロンプト Available Available Available Available Windows PowerShell Available Available Available Available サーバーマネージャー Not Available Available Available Available MMC Not Available Available Available Available コントロールパネル Not Available Not Available Available Available コントロールパネル内 のアプレット Not Available Some Available Available Available Windows Explorer Not Available Not Available Available Available タスクバー Not Available Not Available Available Available 通知エリア Not Available Not Available Available Available Internet Explorer Not Available Not Available Available Available ヘルプ Not Available Not Available Available Available テーマ Not Available Not Available Not Available Available スタートスクリーン Not Available Not Available Not Available Available WinRTアプリ Not Available Not Available Not Available Available メディアプレーヤー Not Available Not Available Not Available Available
  • 101. 101 ServerManager モジュールでサポートされている コマンドレット PS C:¥> Import-Module ServerManager PS C:¥> Get-Command -Module ServerManager Alias Add-WindowsFeature servermanager Alias Remove-WindowsFeature servermanager Function Disable-ServerManagerStandardUserRemoting servermanager Function Enable-ServerManagerStandardUserRemoting servermanager Cmdlet Get-WindowsFeature servermanager Cmdlet Install-WindowsFeature servermanager Cmdlet Uninstall-WindowsFeature servermanager
  • 102. 102 16. DC を複製する Windows Server 2012 以降では、仮想化されたドメインコントローラーを複製して展 開することがでる。 Hyper-V ホスト DC02 DC03Export DC01 (pdc) (条件) • 複製元はPDCエミュレーターであってはならない • 複製元は Clonable Domain Controllers グループのメンバーでなくてはならない • Hyper-V ホストは Windows Server 2012 • DCは Windows Server 2012 VHD Import Hyper-V ホスト Hyper-V ホスト
  • 103. 103 $SourceDC = "DC02" $DistDC = "DC03" $distPDCEmu = DC01" $HyperVHost = “ITCAMP-TMP" Move-ADDirectoryServerOperationMasterRole -Identity $distPDCEmu -OperationMasterRole PDCEmulator Get-ADComputer $SourceDC | %{Add-ADGroupMember -Identity "Cloneable Domain Controllers" -Members $_.samAccountName} Invoke-Command -ComputerName $SourceDC -ScriptBlock { Get-ADDCCloningExcludedApplicationList -GenerateXml -Force } $SB = "New-ADDCCloneConfigFile -Static ` -IPv4Address ""192.168.210.51"" ` -IPv4DNSResolver ""192.168.210.50"" ` -IPv4SubnetMask ""255.255.255.0"" ` -IPv4DefaultGateway ""192.168.210.254"" ` -CloneComputerName " + $DistDC + ` " -SiteName ""Default-First-Site-Name""" Invoke-Command -ComputerName $SourceDC -ScriptBlock { $SB } Stop-VM $SourceDC 新しいドメインコンローラーの 構成ファイルを作成 PDCエミュレーターを複製元となるDC以外に移動 複製元DCをClonable Domain Controllers グループのメンバーにする 複製元DCをシャットダウン
  • 104. 104 つづき Get-VM $SourceDC | %{ Export-VM $_ -Path C:¥VMs} Start-VM -Name $SourceDC $CFG = (Dir “C:¥VMs¥$SourceDC¥Virtual Machines¥*.xml”).FullName md E:¥$DistDC Import-VM -Path "$CFG" -ComputerName $HyperVHost -GenerateNewId -Copy -VhdDestinationPath E:¥$DistDC Get-VM $SourceDC |Where-Object {$_.State -EQ "Off"} | Rename-VM -NewName $DistDC Start-VM $DistDC 複製元DCをエクスポート 複製元DCを起動 エクスポートした仮想マシンをインポート VMの名前が複製元と同じになってしまうので、変更する。ここでは同じHyper-Vホストを使用して いるので、OffになっているほうのDCを変名している。 複製先を起動。起動後自動的にDC間複製が始まる。
  • 105. 105 17. 仮想スイッチを作成する $PCName = "itcamp-pc01" Invoke-Command -ComputerName $PCName -ScriptBlock {New-VMSwitch -Name "External" ` -AllowManagementOS $True -NetAdapterInterfaceDescription "Intel(R) 82579LM Gigabit Network Connection"} New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Public" -SwitchType Private New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-CorpNet" -SwitchType Private New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Storage" -SwitchType Private New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-Internet" -SwitchType Private New-VMSwitch -ComputerName $PCName -Name "WS2012Labs-HA" -SwitchType Private
  • 106. 106 18. リモートコンピューターから機能を一括で削除する Workflow RemoveFOCsWF { $PCs = Import-Csv -Path pclist.txt -Header "PC","IP" foreach -Parallel ($pc in $PCs) { Write-Output -InputObject $pc.pc Remove-WindowsFeature -ComputerName $pc.pc Failover-Clustering -IncludeManagementTools - Restart } } RemoveFOCsWF ワークフローを使用してリモートコンピューターからフェールオーバークラス タリングを削除する itcamp-pc01,192.168.210.1 itcamp-pc02,192.168.210.2 itcamp-pc03,192.168.210.3 itcamp-pc04,192.168.210.4 itcamp-pc05,192.168.210.5 itcamp-pc06,192.168.210.6 ・ ・
  • 107. 107 19. リモートコンピューターを一括でシャットダウンする Workflow RestartAllPCsWF { $PCs = Import-Csv -Path pclist.txt -Header "PC","IP" foreach -Parallel ($pc in $PCs) { Write-Output -InputObject $pc.pc ##Restart-Computer -PSComputerName $pc.PC -Force Stop-Computer -PSComputerName $pc.PC -Force } } RestartAllPCsWF itcamp-pc01,192.168.210.1 itcamp-pc02,192.168.210.2 itcamp-pc03,192.168.210.3 itcamp-pc04,192.168.210.4 itcamp-pc05,192.168.210.5 itcamp-pc06,192.168.210.6 ・ ・
  • 108. 108 20. すべての Hyper-V ホストの仮想マシンを強制的にシャットダウン Workflow StopAllVMs { $PCs = Import-Csv -Path pclist.txt -Header "PC","IP" foreach -Parallel ($pc in $PCs){ ##Get-VM -ComputerName $pc.pc |Start-VM Get-VM -ComputerName $pc.pc |Stop-VM -Force } } itcamp-pc01,192.168.210.1 itcamp-pc02,192.168.210.2 itcamp-pc03,192.168.210.3 itcamp-pc04,192.168.210.4 itcamp-pc05,192.168.210.5 itcamp-pc06,192.168.210.6 ・ ・ ワークフローを使用して一斉にシャットダウン
  • 109. 109 21. すべての Hyper-V ホストのマイグレーション設定を有効化 Workflow DisableMigrationWF { $PCs = Import-Csv -Path c:¥tools¥ps¥HOLSetup¥pclist.txt -Header "PC","IP" foreach -Parallel ($pc in $PCs) { ##Disable-VMMigration -ComputerName $pc.pc ##Set-VMHost -ComputerName $pc.pc -VirtualMachineMigrationAuthenticationType CredSSP ` -MaximumVirtualMachineMigrations 2 -UseAnyNetworkForMigration $true Enable-VMMigration -ComputerName $pc.pc Set-VMHost -ComputerName $pc.pc -VirtualMachineMigrationAuthenticationType Kerberos ` -MaximumVirtualMachineMigrations 2 -UseAnyNetworkForMigration $True } } DisableMigrationWF itcamp-pc01,192.168.210.1 itcamp-pc02,192.168.210.2 itcamp-pc03,192.168.210.3 itcamp-pc04,192.168.210.4 itcamp-pc05,192.168.210.5 itcamp-pc06,192.168.210.6 ・ ・
  • 111. 111 True と False の指定 $True と $False は予約語である C:¥> $MyNameIsJunichi = $True C:¥> If ($MyNameIsJunichi -eq $True) {Echo 1} 1
  • 113. 113 unix のあのコマンドは? ls → get-ChildItem cp → copy-Object grep → select-String sort → sort-Object man → help clear → clear-Host cat → get-Content kill → stop-Process tee → tee-Object tail → get-Content 「アレはあるかな?」と思った ら Get-Alias <unix 上のコマンド> エイリアス tail は登録されてい ないので、自分で登録する必要 がある(後述)。
  • 114. 114 Get-Content で Tail を模してみる ## 新しく追加された行を待ち合わせて表示 gc .¥test.txt -wait -tail 0 ## テキストファイルの5行目から10行目までを表示 (gc .¥test.txt)[4..9] ## テキストファイルの最初の5行を表示 gc .¥test.txt -totalcount 5 ## テキストファイルの最後の5行を表示 gc .¥test.txt | Select-Object -Last 5 ← 時間がかかる可能性があるので –tail をお勧め gc .¥test.txt -tail 5 ## 新しく追加された行に特定の文字列が含まれていたら表示 gc .¥test.txt -wait | Select-String -Pattern ^a
  • 115. 115 tail を Get-Content の Alias として登録する Set-Alias tail Get-Content 一時的に使用する(現在のコンソール上でのみ)場合は以下のように入力 永続化するには、以下のようにプロファイルに書き込む Add-Content $profile "Set-Alias tail get-content" -Force
  • 117. 117 エラー処理の要素 1. エラー発生時のアクションとエラーの取得  $ErrorActionPreference と $Error 変数  -ErrorAction と -ErrorVariable パラメタ 2. より細かい処理の定義  Try…Catch…Finally
  • 118. 118 $ErrorActionPreference • エラー発生時の処理を判断するための環境変数 – Continue • 規定値。エラーを表示するが処理は継続する。 – SilentlyContinue • 処理は継続するが、エラーは表示しない – Stop • エラーを表示し、処理を停止する – Inquire • ユーザーに継続処理を問い合わせる
  • 123. 123 Agenda ~リモーティング編 6. リモーティングの基礎 7. PS セッション • セッションと PS セッション • テンポラリ PS セッション 8. 接続の永続化と再利用可能な PS セッション 9. Windows PowerShell Web Access
  • 125. 125 OS リモーティングを有効にする • 個々の PC で有効にする PS C:¥>Enable-PSRemoting –force WinRM WindowsFirewall Listener 受付窓口要求を透過 WindowsManagement 処理を受付 port 5985
  • 126. 126 Enable-PSRemoting とネットワークプロファイルの関係 ※PowerShell 3.0 の場合 Windows Server 系 ドメイン • ADドメインに参加 • DCと通信可能 プライベート • DCと通信不可能 • ワークグループ • 自宅、職場 パブリック • インターネット • 公共ネットワーク Windows Client 系 WinRM 有効 ネットワークのプロファイル WinRM 有効 WinRM 有効 WinRM 有効 同じサブネットのコン ピューターに対しては WinRM 有効 SkipNetworkProfileChec k パラメタを指定して実行 すれば同じサブネットの コンピューターに対して 有効になる パブリックプロファイルの Firewall の制限をすべて取り払うには以下のコマンドで Set-NetFirewallRule -Name “WINRM-HTTP-In-TCP-PUBLIC” -RemoteAddres Any http://technet.microsoft.com/en-us/library/hh849694.aspx
  • 129. 129 Windows Firewall で WinRM の要求を受信する [コンピューターの構成]-[ポリシー]-[Windows の設定]-[セキュリティの設定] └[セキュリティが強化されたWindowsファイアウォール] └[セキュリティが強化された Windows ファイアウォール(-------)] └[受信の規則]
  • 130. 130
  • 132. 132 リモーティングの設定を確認する PS C:¥> cd WSMan: PS WSMan:¥> cd localhost¥Listner¥Listener_1084132640 PS WSMan:¥localhost¥Listener¥Listener_1084132640> dir WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Listener¥Listener_1084132640 Type Name SourceOfValue Value ---- ---- ------------- ----- System.String Address * System.String Transport HTTP System.String Port 5985 System.String Hostname System.String Enabled true System.String URLPrefix wsman System.String CertificateThumbprint System.String ListeningOn_1038621592 10.168.133.49 System.String ListeningOn_1770022257 127.0.0.1 System.String ListeningOn_1055432771 192.168.205.1 System.String ListeningOn_1414502903 ::1 System.String ListeningOn_894013609 2001:4898:0:fff:0:5e... System.String ListeningOn_1270366863 fe80::5efe:10.168.13... System.String ListeningOn_1565265845 fe80::5efe:192.168.2... System.String ListeningOn_2078661606 fe80::25a7:4656:665e... System.String ListeningOn_1147683958 fe80::fc39:ec3b:d823... PS WSMan:¥localhost¥Listener¥Listener_1084132640> Listener 名は環境に よって異なります
  • 133. 133 ドメイン外のコンピューターを操作するには 操作元の「TrustedHost」リストにターゲットコンピューターを追加する ※「ターゲット」を管理対象としてもいいかを明記するってこと Active Directory ドメイン Or ワークグループ ワークグループ or Active Directory ドメイン OSCredential で認証 WinRM WindowsFirewall Litener WindowsManagement Trusted Hosts 操作元 ターゲット
  • 134. 134 PS C:¥> Get-Item wsman:¥localhost¥Client¥TrustedHosts WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Client Type Name SourceOfValue Value ---- ---- ------------- ----- System.String TrustedHosts PS C:¥> Set-Item wsman:¥localhost¥Client¥TrustedHosts 192.168.205.* -Concatenate WSManConfig: Microsoft.WSMan.Management¥WSMan::localhost¥Client Type Name SourceOfValue Value ---- ---- ------------- ----- System.String TrustedHosts 192.168.205.* 規定では未設定
  • 135. 135 TIPS:NIC のプロファイルが「識別されていない」場合 識別されていない = “パブリックネットワーク” である • ターゲットが Windows クライアント(Windows 7/8 等)であれば、ターゲッ ト PC で以下を実行(Server の場合には行う必要なし) Enable-PSRemoting -Force -SkipNetworkProfileCheck
  • 137. 137 リモートコンピュータの操作する3つの方法 <コマンドレット> -ComputerName パラメタ ※ -ComputerName では PSセッションは張られない • リモートコンピューターに対して「リモート」から操作を行う • 複数のコンピュータを指定可能 Enter-PSSession -ComputerName ・・・・・ • 対話モード(SSH のような使い方) • Exit コマンドで接続を切断し、セッション消滅 Invoke-Command -ComputerName ・・・・・ • -ComputerName パラメタをもたないコマンドレットに対応 • リモートコンピューターの「中」で処理を行う • 複数のコンピュータを指定可能 • コマンドやスクリプトの終了と同時にセッションと接続は消滅
  • 138. 138 -ComputerName を持つコマンドレット PS C:¥> Get-Command -CommandType Cmdlet -ParameterName ComputerName Invoke-Command New-PSSession Connect-PSSession Receive-PSSession Get-PSSession Remove-PSSession Receive-Job Enter-PSSession Add-Computer Clear-EventLog Get-EventLog Get-HotFix Get-Process Get-Service Get-WmiObject Invoke-WmiMethod Limit-EventLog New-EventLog Register-WmiEvent Remove-Computer Remove-EventLog Remove-WmiObject Rename-Computer Restart-Computer Set-Service Set-WmiInstance Show-EventLog Stop-Computer Test-Connection Write-EventLog Get-WindowsFeature Install-WindowsFeature Uninstall-WindowsFeature (ほんの一部)
  • 139. 139 -ComputerName の利用 PS C:¥> Get-EventLog -ComputerName tfdc02 -LogName Security -Newest 10 リモートコンピューターのイベントログを取得する PS C:¥> Restart-Computer -ComputerName tfsv02 リモートコンピューターを再起動する PS C:¥> get-WindowsFeature -ComputerName tfsv02 リモートコンピューターにインストールされている役割/機能の一覧 PS C:¥> Add-WindowsFeature -ComputerName tfsv02 -Name RSAT-Hyper-V-Tools -IncludeAllSubFeature -IncludeManagementTools リモートコンピューターに Hyper-V 管理ツールをインストールする
  • 141. 141 リモートコンピュータの操作する 3 つの方法 <コマンドレット> -ComputerName パラメタ ※ -ComputerName では PSセッションは張られない • リモートコンピューターに対して「リモート」から操作を行う • 複数のコンピュータを指定可能 Enter-PSSession -ComputerName ・・・・・ • 対話モード(SSH のような使い方) • Exit コマンドで接続を切断し、セッション消滅 Invoke-Command -ComputerName ・・・・・ • -ComputerName パラメタをもたないコマンドレットに対応 • リモートコンピューターの「中」で処理を行う • 複数のコンピュータを指定可能 • コマンドやスクリプトの終了と同時にセッションと接続は消滅
  • 142. 142 “セッション” と “PS セッション” Local Computer セッション セッション セッション Remote Computer PSセッション PSセッション Remote Computer PSセッション PSセッション PSセッション •PowerShell.exe が起動すると作られる。 •コンソールを閉じたらクリア。 •個々のセッションは独立 • ユーザー自身が作成し、管理と制御が可能 • 永続化が可能 • 個々のPSセッションは独立 • Windows PowerShell の実行環境 CALL CALL CALL CALL
  • 143. 143 PS セッション Source Targetコネクション • PS セッション内でコマンドやスクリプトが実行される • 変数もセッション内に保存される • コネクションが「消滅」するとセッションも「消滅」する • テンポラリ PS セッション • -ComputerName を使用したときに作成されるセッション • コマンドが終了するとセッションも終了する • リユーザブル(Re-usable) PS セッション • コマンド終了後もコネクションを維持し、セッションを継続 • 実行中の変数等もそのまま維持される セ ッ シ ョ ン
  • 144. 144 Invoke-Command の特徴 • -ComputerName パラメタを持つ • どんなコマンドでもリモートで実行可能 • -ComputerName パラメタを持たないコマンドレット (Start-Service, Stop-Service など) • 従来の DOS コマンド(netstat や gpupdate など) • -Credential のサポート • コマンドレットの中には -Credential を持たないものが多い • -FilePath パラメタにスクリプトを指定可能 • スクリプトはローカルに存在していれば OK ※ただしコマンドレットはリモートに必要 • 複数のコンピューターを指定可能
  • 145. 145 Invoke-Command の利用 コマンドやスクリプトをリモートコンピューターに投げて、結果を受け取る PS C:¥> Invoke-Command -ComputerName tfsv02 -ScriptBlock{ Get-Service } リモートコンピューターのサービス一覧を取得する PS C:¥>Invoke-Command -ComputerName tfsv02 -ScriptBlock{ Stop-Service -Name wuauserv } リモートコンピューターの Windows Update サービスを停止する PS C:¥>Invoke-Command -ComputerName tfsv02 -ScriptBlock{ GPUpdate.exe } リモートコンピューターで GPUpdate を実行する PS C:¥> Invoke-Command -ComputerName tfsv02 -ScriptBlock{ cd env: ; dir } リモートコンピューターの環境変数一覧を取得する Get-Service -ComputerName と同じ
  • 146. 146 Invoke-Command -FilePath パラメタについて -FilePath パラメタに指定するスクリプト(.ps1)は、ローカルのパス Invoke-Command -ComputerName SV01 -FilePath .¥hogehoge.ps1 Invoke-Command -ComputerName SV01 -ScriptBlock {.¥hogehoge.ps1} Target Computer hogehoge.ps1 Get-Service ・ ・ スクリプトの中身がリモートに送られる Target Computer hogehoge.ps1 ターゲット に存在しな いとエラー
  • 147. 147 param([string] $VMName = "VM01", [int] $CPU = 1, [int] $Mem = 10MB) Stop-VM -Name $VMName -Force Remove-VM -Name $VMName -Force Remove-Item -Path ¥¥junichia-vdi¥VMs¥$VMName -Recurse -Force $SwitchName = "Intel(R) 82579LM Gigabit Network Connection - Virtual Switch" New-VM -BootDevice CD ` -MemoryStartupBytes $Mem ` -Name $VMName ` -SwitchName $SwitchName ` -NewVHDPath ¥¥junichia-vdi¥VMs¥$VMName¥$VMName.vhdx ` -NewVHDSizeBytes 40GB Set-VM -ProcessorCount $CPU -DynamicMemory -Name $VMName Add-VMNetworkAdapter -VMName $VMName -SwitchName $SwitchName Start-VM -Name $VMName 1 2 3 4 5 6 7 8 9 10 11 12 13 14 リモートコンピューター上に仮想マシンを作成し起動する PS C:¥> Invoke-Command -ComputerName "junichia-demo05" -FilePath ".¥CreateVirtualMachine.ps1" -ArgumentList “Guest99",“2",“1024MB" CreateVirtualMachine.ps1
  • 148. 148 Invoke-Command の注意点 • PS セッションは Invoke-Command ごとに作成され、実行後に消滅する PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$A = 1} PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$B = 1} PS> Invoke-Command -ComputerName Server1 -ScriptBlock {$C = $A + $B} PS> Invoke-Command -ComputerName Server1 -ScriptBlock {“$A=1; $B=2 ; $C=$A+$B” }
  • 149. 149 複数のリモートコンピューターに対する一括操作 PS > $ComputerList = “tfdc01”, “tfdc02” PS > Get-Service -ComputerName $ComputerList | Sort-Object MachineName, Name | Select-Object MachineName, Name, Status PS > $ComputerList = “tfdc01”, “tfdc02” PS > Invoke-Command -ComputerName $ComputerList {Get-Service |Sort- Object PSComupterName, Name | Select-Object PSComputerName, Name, Status} | FT • 複数のコンピューターに対して処理を行い、結果をマージして出力 • 非同期に処理が開始され、全ての処理が終了するまで待ち合わせる (シーケンシャルでないことに注意!) • 規定では最大同時32台 -ComuterName パラメタに複数のコンピューターを指定する MachineName と PSComputerName に注意!
  • 150. 150 $PSComputerName Get-Service -ComputerName TARGET Invoke-Command -ComputerName TARGET { Get-Service } Source Target コマンド WMI 実 行 空 間 結果 Source Target 実 行 空 間 WMI 結果 Get-Service コマンドレットの 結果にはコンピューター名 (MachineName)が含まれる。 Get-Service コマンドレットの結 果に含まれるMachineNameには ローカルコンピューター「.」が含 まれる。 Target コンピューター名を取得す るには $PSComputerName を使 用する。 PSSession のターゲットとなったコンピューター名が格納される変数
  • 151. 151 CSVファイルから複数コンピューターを入力 Invoke-Command -ComputerName (Import-CSV computerlist.txt).HostName {get- culture} LCID Name DisplayName PSComputerName ---- ---- ----------- -------------- 1041 ja-JP 日u本語e (日u本) tfdc01 1041 ja-JP 日u本語e (日u本) tfdc02 1042 ja-JP 日u本語e (日u本) tfsv02 1041 ja-JP 日u本語e (日u本) tfsv01 HostName,IPAddress tfdc01,192.168.1.1 tfdc02,192.168.1.2 tfsv01,192.168.1.3 tfsv02,192.168.1.4
  • 152. 152 Enter-PSSession • テンポラリ接続により対話型のセッションを開設する • 複数のコマンドを実行可能 • 接続が生きている間はセッションも行き続ける PS> Enter-PSSession -ComputerName Server1 [Server1]: PS > $A = 1 [Server1]: PS > $B = 2 [Server1]: PS > $C = $A + $B PS> Exit-PSSession
  • 154. 154 リユーザブルな PS セッションを使用するには PS > $S = New-PSSession -ComputerName CL01 PS > Invoke-Command -session $S -ScriptBlock {$A=1} PS > Invoke-Command -session $S -ScriptBlock {$B=2} PS > Invoke-Command -session $S -ScriptBlock {$C=$A+$B} PS > Enter-PSSession $S [CL01] PS > Echo $C [CL01] 3 PS > Exit-PSSession PS > Remove-Session $S • セッションの作成 :New-PSSession • セッションの削除 :Remove-PSSession • セッション一覧 :Get-PSSession • セッションへの接続 :Connect-PSSession セッションを作成 セッション内 で実行される
  • 155. 155 複数ターゲットを含んだコネクションも可能 PS > $S = New-PSSession -ComputerName CL01,CL02 PS > $S Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 80 Session80 tfdc01 Opened Microsoft.PowerShell Available 81 Session81 tfdc02 Opened Microsoft.PowerShell Available PS > Invoke-Command -Session $S {Get-Culture} Target1コネクション セ ッ シ ョ ン Target2セ ッ シ ョ ン Source
  • 156. 156 ローカル変数をPSセッションで使用する 書式 $Using:<変数名> PS C:¥> $S = New-PSSession -ComputerName tfdc01 PS C:¥> $MyName = “Junichi Anno” PS C:¥> Invoke-Command -Session $S {Echo $Using:MyName} Junichi Anno
  • 157. 157 PS セッション情報の取得 ~ Get-PSSession Target1コネクション セ ッ シ ョ ン Source1 Source2 PS C:¥tools¥ps> Get-PSSession -ComputerName Target1 Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 65 tfdc01_Session target1 Opened Microsoft.PowerShell Available 80 Session80 taeget1 Opened Microsoft.PowerShell Available 109 Session109 target1 Opened Microsoft.PowerShell Available • リユーザブルなセッション情報は他のコンピューターからも参照できる • 他のユーザーが作成したセッションは、Credential が有効であれば参照可能 -Credential パラメタを使用可能
  • 158. 158 PS セッションへの再接続 Target1 セ ッ シ ョ ン Source1 Source2 • リユーザーブルな PS セッションには他のコンピューターから再接続が可能 • State=Disconnected, Availability=None に対してのみ • Disconnect-PSSession コマンドレットで明に Disconnect した場合 • ネットワークの切断や PC のハングアップ等で Disconnected になった場合 ※ コンソールを明に落とした場合は強制終了したものとみなされる • 同時に2台以上のコンピューターからは接続できない State=Disconnected Availability=None 再接続可能 Disconnect-PSSession Connect-PSSession
  • 159. 159 PS > $S = New-PSSession -ComputerName Target1 PS > $Result = Invoke-Command -Session $S {Get-Service} PS > Disconnect-PSSession -Session $S Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 121 Session121 Target1 Disconnected Microsoft.PowerShell None Target PC1 PC 2 PS > Get-PSSession -ComputerName Target1 Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy 12 Session121 tfdc01 Disconnected Microsoft.PowerShell None PS > $S = Get-PSSession -Name Session121 -ComputerName Target1 PS > Connect-PSSession -Session $S
  • 160. 160 State と Availability Availability State Opened 自分自身が接続している Disconnected 自分自身は接続していない 誰も接続していない 他の誰かが接続してる 自分が接続している None Busy Available こ の 組 み 合 わ せ な ら ば 再 接 続 可 能 Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy 12 Session121 tfdc01 Disconnected Microsoft.PowerShell None
  • 161. 161 もしソース PC がダウンしたら ソースが死んでもセッション情報はターゲットに残されている...ただし... Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 10 Session112 tfdc01 Disconnected Microsoft.PowerShell Busy Availability が Busy なので、再接続できない 2 分 後 Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------ 10 Session112 tfdc01 Disconnected Microsoft.PowerShell None 再接続可能!
  • 162. 162 PS セッションの有効期間 • PS セッションのターゲットの再起動、シャットダウン • Remove-PSSession を実行するまで • セッションがアイドルタイムアウトするまで • Disconnect してからの時間 PS > Remove-PSSession -Session $S PS C:¥> Get-PSSessionConfiguration | ft name,idletimeoutms,maxidletimeoutms Name IdleTimeoutms MaxIdleTimeoutms ---- ------------- ---------------- microsoft.powershell 7200000 2147483647 microsoft.powershell.workflow 7200000 2147483647 microsoft.powershell32 7200000 2147483647 microsoft.windows.servermanagerworkflows 180000 180000 2時間 596時間 規定値
  • 163. 163 アイドルタイムアウト値の変更 PS C:¥> $SessionOption = New-PSSessionOption -IdleTimeOutMSec 60000 PS C:¥> $S = New-PSSession -ComputerName Target1 -SessionOption $SessionOption 設定方法 • 構成ファイルを変更 • Register-PSSessionConfiguration -TransportOption <$TransportOption> • Set-PSSessionConfiguration -TransportOption <$TransportOption> • PS セッション作成時(特定のセッションのみ) • New-PSSession -SessionOption <$SessionOption> • コマンド実行開始時(特定のセッションのみ) • Invoke-Command -SessionOption <$SessionOption> • PS セッション切断時(特定のセッションのみ) • Disconnect-PSSession -IdeleTimeOutSec <秒>
  • 164. 164 出力バッファモード 出力バッファがFULLになった場合の対応モード • Block : バッファがClearされるまでコマンドの実行をサスペンドする • Drop:コマンドの実行は続けるが古い出力結果から捨てられる 現在のモードを調べる PS C¥> Get-PSSessionConfiguration | ft Name, OutputBufferingMode Name OutputBufferingMode ---- ------------------- microsoft.powershell Block microsoft.powershell.workflow Block microsoft.powershell32 Block microsoft.windows.servermanagerworkflows Block 「現在の PS セッションでは Drop モードで実行する」を設定 PS C:¥> $o = New-PSSessionOption -OutputBufferingMode Drop PS C:¥> New-PSSession -SessionOption $o
  • 165. 165 Source2 再接続可能 ループバック PS セッション • LOCALHOST に対してリユーザーブルな PS セッションを作成すれば、 切断したあと別のマシンから再接続が可能 • 管理者モードで実行する必要がある PS > $S = Get-PSSession -ComputerName localhost -Name Backup PS > Receive-PSSession -Session $S PS > Remove-PSSession -Session $S Source1 /Target セ ッ シ ョ ン Connect-PSSession PS> $S = New-PSSession -Name Backup PS> Invoke-Command -Session $S -FilePath backup.ps1 -AsJob PS> Disconnect-PSSession -Session $S
  • 166. 166 モジュールとコマンドのインポート • リモートコンピューター上のコマンドレットを一時的に取り込むことができる • “Invoke-Command -Session” を使用する必要が無くなる • コマンドの実行中はセッションを生かしておく必要がある PS C:> $s = New-PSSession -ComputerName Server1 PS C:> Import-PSSession -Session $s -Module HYPER-V PS C:¥> Get-VM |ft name Name ---- VM01 VM02 VM03 VM04 VM05 Windows Server w/ Hyper-V PS Session Hyper-V Module
  • 168. 168 Windows PowerShell Web Access 再接続 WS-Man に接続するためのゲートウェイ IntranetDMZInternet Home
  • 169. 169 PowerShell Web Access のセットアップ 1.サーバーマネージャーから PowerShell Web Access をインストールする
  • 171. 171 2.PowerShell を管理者モードで起動 3.以下のコマンドを実行 PS C:¥> Set-ExecutionPolicy RemoteSigned PS C:¥> Import-Module PowerShellWebAccess PS C:¥> Install-PswaWebApplication -webSiteName "Default Web Site" PS C:¥> Add-PswaAuthorizationRule * * * 4.https://<サーバー名>/pswa にアクセス ここで指定するサーバーは、 ターゲットとなるサーバー
  • 173. 173 • Windows PowerShell 2.0 よりサポート • 長時間を要するコマンドレットを非同期に実行し、次の処理に移る (例)get-eventlog “Security” • ジョブの有効範囲は現在のセッション • ジョブを生成するには – -AsJob パラメタ • 一部のコマンドのみが実装 • ワークフローコマンドには使用可能 – Start-Job コマンドレット • すべてのコマンド、スクリプトをジョブ化可能 • ジョブの結果がどこに保存されるのかを意識することが重要! バックグラウンドジョブ
  • 174. 174 -AsJob -AsJob パラメタを持つコマンドレットは少ない PS C:¥> Get-Command -ParameterName asjob CommandType Name ModuleName ----------- ---- ---------- Function Get-SMCounterSample ServerManagerTasks Function Get-SMPerformanceCollector ServerManagerTasks Function Get-SMServerBpaResult ServerManagerTasks Function Get-SMServerClusterName ServerManagerTasks Function Get-SMServerEvent ServerManagerTasks Function Get-SMServerFeature ServerManagerTasks Function Get-SMServerInventory ServerManagerTasks Function Get-SMServerService ServerManagerTasks Function Remove-SMServerPerformanceLog ServerManagerTasks Function Start-SMPerformanceCollector ServerManagerTasks Function Stop-SMPerformanceCollector ServerManagerTasks Cmdlet Get-WmiObject Microsoft.PowerShell.Management Cmdlet Invoke-Command Microsoft.PowerShell.Core Cmdlet Invoke-WmiMethod Microsoft.PowerShell.Management Cmdlet Remove-WmiObject Microsoft.PowerShell.Management Cmdlet Restart-Computer Microsoft.PowerShell.Management Cmdlet Set-WmiInstance Microsoft.PowerShell.Management Cmdlet Stop-Computer Microsoft.PowerShell.Management Cmdlet Test-Connection Microsoft.PowerShell.Management ※AsJobパラメタを持つコマンド一覧
  • 175. 175 ジョブ関連のコマンドレット  Get-Job  バックグラウンドジョブを取得  Receive-Job  バックグラウンドジョブの出力結果を取得  Remove-Job  バックグラウンドジョブを削除  Start-Job  バックグラウンドジョブを開始  Stop-Job  バックグラウンドジョブを停止  Wait-Job  バックグラウンドジョブが終了するまで待つ
  • 176. 176 バックグラウンドジョブの基本操作 (例) PS C:¥> $job = start-job -scriptblock {do {$a = 0; echo (date) ; start-sleep 5} while ($a -eq 0) } PS C:¥> $job Id Name State HasMoreData Location Command -- ---- ----- ----------- -------- ------- 6 Job6 Completed True localhost get-eventlog "Windows ... PS C:¥> Receive-Job $job -Keep PS C:¥> Stop-Job $job PS C:¥> Remove-job $job 書式 start-job -scriptblock { <スクリプトブロック> } 出力結果が存在する 規定では、出力結果は一度取得するとクリアされてしま うので、-Keep によって残すように指定 5秒に1回日時を表示するジョブ ジョブを停止 ジョブを削除
  • 177. 177 スクリプトをバックグラウンドジョブ化するには $flg = $true $index = 0 $index_old = 0 Do { $Eventlog = Get-Eventlog -LogName TechFielders -Source TechFielders $index = $eventlog | Select-Object -First 1 -Property Index $delta_index = $index.Index - $index_old if ($delta_index -gt 0) { $eventlog | ` Select-Object -First $delta_index | ` Sort-Object -Property Index } Start-Sleep -Seconds 1 $index_old = $index.Index } While ($flg) まずはスクリプトを作成する(イベントログを取得するスクリプト) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 WatchNewEventLog.ps1 結果を Index をキーとして昇順に並べる
  • 178. 178 ##作成したスクリプトをバックグラウンドで実行する PS C:¥> Start-Job -FilePath .¥WatchNewEventLog.ps1 -Name WatchNewEventLog Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 4 WatchNewEven... BackgroundJob Running True localhost $flg = $true... ## 以下のコマンドで現在までの結果を収集する PS C:¥> Receive-Job -Name WatchNewEventLog Index Time EntryType Source InstanceID Message ----- ---- --------- ------ ---------- ------- 1 6 02 17:41 Information TechFielders 5963 テスト 2 6 02 18:09 Information techfielders 99 テスト 3 6 02 18:11 Information TechFielders 9909 テスト 4 6 02 18:12 Information TechFielders 9909 テスト 5 6 02 18:13 Information TechFielders 9909 テスト 6 6 02 18:13 Information TechFielders 9909 Hello 以下のコマンドで新しいイベントを書き込む C:¥> Write-EventLog -LogName TechFielders -Message "Hello" -Source "TechFielders" -EventId 5963
  • 180. 180 セッションの永続化とジョブの実行結果 PS> Invoke-Command -Session $S -FilePath backup.ps1 -AsJob Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 2 Job2 RemoteJob Completed True tfdc01 get-service PS> Receive-Job -Id 2 SRC Target 実 行 結 果 (例1)Invoke-Command -AsJob を使用した場合 セッションに再接続する場合には、結果もリモートに保存しなければ意味がない!! Invoke-Command をバックグ ラウンドジョブ化するため のオプション。 スクリプトはリモートだが、ジョブはローカル。 Invoke-Command の結果はローカルに保存されることに注意!!! つまりローカルセッションが消えたらジョブの結果も消えるということ!!
  • 181. 181 PS> $S = New-PSSession -ComputerName Target -Name Backup PS> $Script = “.¥testscript.ps1" PS> Invoke-Command -Session $S { Start-Job -FilePath $Script } Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 1 Job1 BackgroundJob Running True localhost backup... PS> Disconnect-PSSession -Session $S SRC1 Target 実 行 結 果 (例2)Invoke-Command {Start-Job} を使用した場合 (つづく) SRC2 スクリプトをジョブ化することで、結果がリモートに保存されるため、セッションを永続化すれ ば別のコンピューターから取り出せる。
  • 182. 182 PS> Get-PSSession -ComputerName tfdc01 Id Name ComputerName State ConfigurationName Availability -- ---- ------------ ----- ----------------- ------------- 1 backup tfdc01 Disconnected Microsoft.PowerShell None PS> $S = Connect-PSSession -Name backup -ComputerName tfdc01 PS> Invoke-Command -Session $S { Get-Job } Id Name PSJobTypeName State HasMoreData Location -- ---- ------------- ----- ----------- -------- 1 Job1 BackgroundJob Completed True localhost PS> Invoke-Command -Session $S {Receive-Job -Id 1} 別のコンピューターから接続して結果を取得
  • 184. 184 ジョブスケジューリングの例 $trigger = New-JobTrigger -Daily -At 3am Register-ScheduledJob -Name EnergyAnalysisJob -Trigger $trigger -ScriptBlock { powercfg.exe -energy -xml -output C:¥temp¥energy.xml -duration 60 | Out-Null $EnergyReport = [xml](get-content C:¥temp¥energy.xml) $namespace = @{ ns = "http://schemas.microsoft.com/energy/2007" } $xPath = "//ns:EnergyReport/ns:Troubleshooter/ns:AnalysisLog/ns:LogEntry[ns:Severity = 'Error']" $EnergyErrors = $EnergyReport | Select-Xml -XPath $xPath -Namespace $namespace $EnergyErrors.Node | select Name, Description } タスクマネージャーで参照可能
  • 186. 186 Agenda ~ワークフロー編 11.Windows PowerShell Workflow とは 12.Windows PowerShell Workflow の基礎 13.ワークフロー特有の記述 14.ワークフロージョブとデータの永続化
  • 188. 188 想定している利用シーン ターゲットとなる処理 • 長時間を要する処理 – 仮想マシンの展開 – ソフトウェアのインストール – ビッグデータの集計 など • 複数の処理の組み合わせ • 複数のコンピューターに対する処理 – ドメイン参加 – 環境設定 – インベントリ収集 など 要求される制御機構 • タイムアウトやリトライ • 処理の一時停止、再開 • 処理ステートの永続化 • 複数処理の制御 • 並列 • シーケンシャル • スクリプト実行権限の委任 • 途中経過の取得 ワークフロー = バックグラウンドジョブ + リモーティング + 実行制御
  • 190. 190 PowerShell 3.0 - ワークフロー パラレル WF ジョブと結果の永続化 WF 処理1 処理2 checkpoint 結果ストア 結果1 checkpoint 処理3 サーバー ダウン サスペンド WF 処理1 処理2 サスペンド サーバーが条件 に合致しない場 合にサスペンド し、あとでレ ジューム
  • 191. 191 PowerShell ワークフローの特長 • 実行中のコンピューターが再起動してもワークフロージョブは消えない • 一時停止状態(Suspend)になる • 長時間タスクの制御と監視 • アクティビティの進行状況はいつでも参照可能 • 自動リカバリ • 途中経過は指定したポイントで保存されている • ワークフローセッションへの接続と切断 • ワークフローを開始した PC とは別の PC から再接続が可能 • 同時に複数コンピューターへの接続 • ワークフロータスクを同時に大量のサーバーに配信可能 • 複数のスクリプトを1つのワークフローでコントロール • スケジューリング • 特定の状態をトリガーとして起動可能 • XAMLファイルでインポート、エクスポート可能 ※ ワークフローが動作するコンピューターには Windows PowerShell 3.0 が必須
  • 193. 193 ワークフロ―実行までの流れ ① ワークフローを作成する ② ワークフローを登録する ③ ワークフローを確認する ④ ワークフローを実行する i. ワークフローセッションの作成 ii. ワークフローを実行 iii. 結果を取得
  • 194. 194 Wokflow の作成 • PowerShell ISE(またはテキストエディタ) で作成する • workflow キーワードを使用する workflow <ワークフロー名> ( <引数> ) { <処理> } workflow MyWorkflow ( [String] $ServiceName ) { Get-Service -PSComputerName $PSComputerName -Name $ServiceName } (例)MyWorkflow という名前でリモートコンピューターのサービス一覧を取得するワークフロー 注意 -ComputerName ではない(後述) 共通パラメタ(後述)
  • 195. 195 Workflow の登録 • .ps1 で保存し、実行するだけ または、PowerShell ISE 上から実行するだけ • 留意点  どこに登録するか?  いつ登録するか?
  • 196. 196 Workflow をどこに登録するか? 自分のPC Managed Node WF 自分のPC Managed Node WF 実行 WF WinRMWinRM WMIWMI In-Process Execution 終わるまで家に帰れない! Execution in Workflow Configuration 実行したらセッッション切断して帰宅 :) ワークフローは実行するノードに存在しなければならない
  • 197. 197 Workflow の登録先と実行環境について • In-process 実行  Activity はローカルに登録される  PowerShell クライアントホスト上での実行  ワークフローが終了するまでセッションを切断できない • Workflow セッション上での実行  Activity はリモートノードに登録される  Workflow 用に PS セッションを作成し、WinRM を通して実行する  一時的な切断が可能で、長時間のジョブを実行する際に便利
  • 198. 198 (参考)In-Process 実行時のアーキテクチャ Localhost Powershell.exe Activity Host Process Activity Host Managed Node PowerShell Remoting (RSRP) Managed Node CIMOM/ WMI PSWF Executive PSWF Cmdlets
  • 199. 199 (参考)Workflow セッションで実行時のアーキテクチャ Managed Node PowerShell Remoting (RSRP) Managed Node CIMOM/ WMI PowerShell Workflow Activity Host Process Activity Host PSWF Executive Client PSJobProxy/ PSJob API/ PSRP WinRM Client WinRM Service
  • 200. 200 Proxy Node • リモートノードにワークフローを登録 =リモートでスクリプトを実行 自分のPC 登録 WF Managed Node WinRM WMI Managed Node WinRM WMI Managed Node WinRM WMI 実行 WinRM PS C:¥> $S = New-PSWorkflowSession -ComputerName <Node> PS C:¥> Invoke-Command –Session $S -FilePath mywf.ps1 ワーククフローが定義されているファイル PS1ファイルがローカルにある場合 PS C:¥> $S = New-PSWorkflowSession -ComputerName <Node> PS C:¥> Invoke-Command –Session $S { .¥mywf.ps1 } PS1ファイルがリモートにある場合
  • 201. 201 ワークフローをいつ登録すべきか? 注意 ワークフローは セッション または PSセッション 内でのみ有効 PS C:¥> Invoke-Command -ComputerName NODE -FilePath .¥mywf.ps1 ダメな例2:登録したとたんに消滅 PS C:¥> $S = New-PSSession -ComputerName NODE PS C:¥> Invoke-Command -Session $S -FilePath .¥mywf.ps1 ダメじゃないけど気をつけなければならない例:PS セッション消滅とともにWF も消滅 PS C:¥>.¥mywf.ps1 ダメな例1:コンソールを閉じた瞬間に消滅 orz ワークフローは実行直前に登録したほうがよさそう... PS C:¥> Invoke-Command -ComputerName NODE -FilePath .¥mywf.ps1 -asjob
  • 202. 202 (参考)workflow を登録すると... AST(abstract syntax tree)workflow { Get-Service } .ps1 ファイル 実行 “workflow” キーワード検出 Script-to-workflow コンパイラ XAML workflow Activity Tree Workflow Foundation 4 ActivityXamlService Class
  • 203. 203 登録されたワークフローの確認 • Get-Command で確認する (ワークフローはコマンドレットと同じように扱える) PS C:¥> Get-Command <ワークフロー名> PS C:¥> Get-Command MyWorkflow CommandType Name ModuleName ----------- ---- ---------- Workflow MyWorkflow