備考欄に感想を書くタイプのエンジニア

それで出世が遅れ(ry

OpenStack Cloud Computing Cookbook Third Edition, Second Edition からの変更点(削除された章編)

先日品川で開催された OpenStack Summit Tokyo 2015 でラッキーなことに2ヶ月ほど前に出版されたばかりの OpenStack Cloud Computing Cookbook Third Edition (以降 TE、2015/8 出版、Juno および Kilo ベース) をゲットすることができたので、Second Edition (以降 SE、2013/6 出版、OpenStack Grizzly ベース) との違いをまずは見ていこうと思います。長いので SE で削除された章編と TE で追加された項目編に分けて書こうと思います。

※見落としや間違いがありましたら教えて頂けると助かります。

余談ですが、OpenStack のリリーススケジュールは6ヵ月毎となっており、TE が出版された2ヵ月後には Kilo の次のバージョンである Liberty がリリースされていますし、その次のバージョンである Mitaka (Meiji という名称はどうのこうのという話がありましたね) 予定通りであればまた半年以内にリリースされると思われますので、Forth Edition のころにはコアサービスだけが対象だったとしても Neutron を始めとして内容が結構変わっているかもしれません。出版されれば、の話ですが。せっかく著者が OpenStack Summit にいらしていてサインまでもらったので perspective とか聞いてみればよかったです…。

Third Edition の目次

  • Chapter 1: Keystone - OpenStack Identity Service
  • Chapter 2: Glance - OpenStack Image Service
  • Chapter 3: Neutron - OpenStack Networking
  • Chapter 4: Nova - OpenStack Compute
  • Chapter 5: Swift - OpenStack Object Storage
  • Chapter 6: Using OpenStack Object Storage
  • Chapter 7: Administering OpenStack Object Storage
  • Chapter 8: Cinder - OpenStack Block Storage
  • Chapter 9: More OpenStack
  • Chapter 10: Using the OpenStack Dashboard
  • Chapter 11: Production OpenStack

Second Edition の目次

  • Chapter 1: Keystone OpenStack Identity Service
  • Chapter 2: Starting OpenStack Image Service
  • Chapter 3: Starting OpenStack Compute
  • Chapter 4: Installing OpenStack Object Storage
  • Chapter 5: Using OpenStack Object Storage
  • Chapter 6: Administering OpenStack Object Storage
  • Chapter 7: Starting OpenStack Block Storage
  • Chapter 8: OpenStack Networking
  • Chapter 9: Using OpenStack Dashboard
  • Chapter 10: Automating OpenStack Installations
  • Chapter 11: Highly Available OpenStack
  • Chapter 12: Troubleshooting
  • Chapter 13: Monitoring

太字が今回の対象。

Second Edition との違い(TE で削除された章編)

Chapter 10: Automating OpenStack Installations (SE)

SE 10 章では OpenStack の環境を構成する方法として Chef を利用していますが、Chef を使って環境を構成するという決定の背景には以下のような議論があったようです。

Notes for this edition of the OpenStack Cookbook

There are lots and lots of choices when it comes to the bare-metal and automated provisioning of an OpenStack environment. In this edition of the book, after some discussion with Kevin and those in the community, we decided to change gears from Ubuntu's MaaS to something that would allow for a greater degree of flexibility. After considering the great work going on in the TripleO project and Bare Metal OpenStack, we decided that while great progress is being made in those projects, at this time we were going to print with PuppetLabs Razor and Chef.

これは First Edition の時に Ubuntu MaaS を利用してベアメタル プロビジョニングをする項目があったようで、そこからの "Change gears" ということのようです。その結果 SE では VagrantVirtualBox を OpenStack 環境のベースにしており、さらに TE では Ansible の Playbook を利用して Ubuntu の上の LXC Container に OpenStack 環境を構成する方法を採っています。なお、TE では OpenStack のインストールを自動化する内容が 11 章の Production OpenStack の中の一項目となり、SE のような章立てではなくなっています。

Chapter 11: Highly Available OpenStack (SE)

SE 11 章では、単一障害点を取り除いた可用性の高い OpenStack 環境を構成することをコンセプトに、バックエンドのデータベース側には MySQL Galera cluster + HA Proxy、Keystone と Glance の冗長化の目的で Pacemaker + Corosync を利用した構成を行う形となっています。TE では SE の 10 章と同じく TE の 11 章の Production OpenStack の中の項目となり、MySQL Galera cluster から MariaDB Galera cluster に変更となっていますが、構成内容そのものには大きな変更はなさそうです。

Chapter 12: Troubleshooting (SE)

SE の Chapter 12 ではトラブルシューティングの方法として OpenStack が生成するログの保存先の情報(e.g. nova-compute: /var/log/nova/nova-compute.log)の提示やサービスの確認等々の記載がありましたが、これらの内容は TE では章立てとしてそもそもなくなっており、SE で記載があった内容についても大半がなくなっているようです(ぱっと見では nova-manage, nova list, swift-recon についてはそれぞれ関連する章内に別々に記載がありました)。

ちなみに、トラブルシューティングの仕方については、OpenStack Summit Tokyo の Debugging the Virtualization layer (libvirt and QEMU) in OpenStack で興味深い話がありましたので、よかったらリンク先のスライドもどうぞ(このスライドを使った OpenStack Summit の動画は 11/9 時点でまだ公開されていないようです…)。

Chapter 13: Monitoring (SE)

何か先例を引き合いに出すまでもなく、モニタリングと環境の見える化(Visibility)はこういったシステムの運用にとって非常に重要な要素だと思いますが、SE 13 章では監視する対象に合わせて以下のような見出しになっていた一方で、TE では同様の内容として 9 章の More OpenStack 内で Ceilometer を利用した Nova ノードのリソース監視を行うものの、それ以外は記載がなくなっているようです。

  • Monitoring OpenStack services with Nagios
  • Monitoring Compute service with Munin
  • Monitoring instances using Munin and collectd
  • Monitoring the storage service using StatsD/Graphite
  • Monitoring MySQL with Hyperic

余談ですが、Operations and Management of a Hyper-Converged Multi-Tenant Platform のセッションでの Nick Gerasimatos 氏の発言によると FICO では OpenStack の監視に Zabbix を使っているとのことです。

We've been using Zabbix for very long time and what we realize is Zabbix, it's not bad tool. It requires a lot of custom immigration to meet our needs (and) our requirements...


ご参考: モニタリングに関しては Monitoring Swift with Elastic SearchMonitoring system for OpenStack, using a OSS products というセッションがありましたが、私は別のセッションに出ていたので内容はまだ未確認です。興味があればあわせてどうぞ。

FYDIBOHF23SPDLTの意味

Exchange Server 2007 以降でメッセージング環境を扱ったことがある方なら FYDIBOHF23SPDLT という文字列を見たことがあると思いますが、この文字列のアルファベットおよび数字を以下の順番においてそれぞれ1文字ずつ前(左)に戻すと… EXCHANGE12ROCKS。それだけの話でした(いままで知りませんでした)。

ABCDEFGHIJKLMNOPQRSTUVWXYZ
(0)123456789(0) ※数字のゼロは前なのか後ろなのか判断できません。

意味はともかくですが、これをどう読んでいいのかわからなくてちょっと電話のときとか NATO フォネティック コードを使った会話みたいになってつらかったので、今度からはドヤ顔で EXCHANGE12ROCKS と言おうと思います。

※ちなみに FYDIBOHF25SPDLT があるのは確認していてこれもバージョンの違いですね。

PowerShell でフォレストの信頼を作成する

※これは PowerShell Advent Calendar 2014: ATND 9 日目の記事です。


昨今進化が目覚ましく、頻繁に話題を目にするようになった PowerShell ですが、Micorosft の製品を利用/運用しているといまだ PowerShell で簡単に実行できないことがいろいろあることに気づく方も多いのではないかと思います(簡単にとい言うのはいわゆる"動詞-名詞" 形式の命名規則に基づいたコマンドレットの実行のことです)。

今回はその中のうち、フォレストの信頼を PowerShell で実行する方法を紹介しようと思います。ご存知かもしれませんが Active Directory の信頼を作成する方法としては GUINetdom コマンドレットがあります。個人の観測範囲内では Netdom すらあまり使われているのを見たことはなく GUI とスクリーン ショットのコンボを決めているのが大半かなと思います。。。

それで、まずマウスでポチポチするのはやめましょうか、と考えたときにじゃあ Netdom を使いましょうか、と思うのですが

Netdom cannot be used to create a forest trust between two AD DS forests. To create a cross forest trust between two AD DS forests, you can either use a scripting solution or the Active Directory Domains and Trusts snap-in. (TechNet | Netdom trust)

要するにフォレスト間の信頼を作成するのに Netdom は使えません。そんな馬鹿な、誰か反論を。ということで残念ながら現時点では PowerShell にもそれを実現するコマンドレットは存在しません。

  • Get-ADForest で、実行した AD フォレストの現時点の情報を取得する→わかる。
  • Get-ADTrust で、実行したドメインにおける現時点の信頼されたドメイン オブジェクトの情報を取得する→わかる。
  • Get-ADForest があるということは New-ADTrustCreate-ADTrust で、特定のドメインもしくはフォレストの間に信頼を作成できそうなのにそういうコマンドレットがない→?!

とは言え、ないものは仕方がありません。幸い PowerShell では .NET Framework を利用できます。利用できますというか PowerShell はいわば .Net Framework アプリケーションですので、今回は不本意(?)ですがその機能を明示的に使っていきたいと思います。

まずどこからか [System.DirectoryServices.ActiveDirectory] 名前空間Forest クラス見つけ出します。msdnForest メソッドを確認してみると CreateLocalSideOfTrustRelationship というメンバーがあります。"Creates the local side of a trust relationship with the specified forest." と書いてあるのでちょうどよさそうです。

一応 PowerShell 上でも確認してみると

PS > $sample = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

PS > $sample | Get-Member


   TypeName: System.DirectoryServices.ActiveDirectory.Forest

Name                               MemberType Definition                                            
----                               ---------- ----------                                            
CreateLocalSideOfTrustRelationship Method     void CreateLocalSideOfTrustRelationship(string targ...
CreateTrustRelationship            Method     void CreateTrustRelationship(System.DirectoryServic...
DeleteLocalSideOfTrustRelationship Method     void DeleteLocalSideOfTrustRelationship(string targ...
DeleteTrustRelationship            Method     void DeleteTrustRelationship(System.DirectoryServic...
Dispose                            Method     void Dispose(), void IDisposable.Dispose()            
Equals                             Method     bool Equals(System.Object obj)                        
FindAllDiscoverableGlobalCatalogs  Method     System.DirectoryServices.ActiveDirectory.GlobalCata...
FindAllGlobalCatalogs              Method     System.DirectoryServices.ActiveDirectory.GlobalCata...
FindGlobalCatalog                  Method     System.DirectoryServices.ActiveDirectory.GlobalCata...
GetAllTrustRelationships           Method     System.DirectoryServices.ActiveDirectory.TrustRelat...
GetHashCode                        Method     int GetHashCode()                                     
GetSelectiveAuthenticationStatus   Method     bool GetSelectiveAuthenticationStatus(string target...
GetSidFilteringStatus              Method     bool GetSidFilteringStatus(string targetForestName)   
GetTrustRelationship               Method     System.DirectoryServices.ActiveDirectory.ForestTrus...
GetType                            Method     type GetType()                                        
RaiseForestFunctionality           Method     void RaiseForestFunctionality(System.DirectoryServi...
RepairTrustRelationship            Method     void RepairTrustRelationship(System.DirectoryServic...
SetSelectiveAuthenticationStatus   Method     void SetSelectiveAuthenticationStatus(string target...
SetSidFilteringStatus              Method     void SetSidFilteringStatus(string targetForestName,...
ToString                           Method     string ToString()                                     
UpdateLocalSideOfTrustRelationship Method     void UpdateLocalSideOfTrustRelationship(string targ...
UpdateTrustRelationship            Method     void UpdateTrustRelationship(System.DirectoryServic...
VerifyOutboundTrustRelationship    Method     void VerifyOutboundTrustRelationship(string targetF...
VerifyTrustRelationship            Method     void VerifyTrustRelationship(System.DirectoryServic...
ApplicationPartitions              Property   System.DirectoryServices.ActiveDirectory.Applicatio...
Domains                            Property   System.DirectoryServices.ActiveDirectory.DomainColl...
ForestMode                         Property   System.DirectoryServices.ActiveDirectory.ForestMode...
GlobalCatalogs                     Property   System.DirectoryServices.ActiveDirectory.GlobalCata...
Name                               Property   string Name {get;}                                    
NamingRoleOwner                    Property   System.DirectoryServices.ActiveDirectory.DomainCont...
RootDomain                         Property   System.DirectoryServices.ActiveDirectory.Domain Roo...
Schema                             Property   System.DirectoryServices.ActiveDirectory.ActiveDire...
SchemaRoleOwner                    Property   System.DirectoryServices.ActiveDirectory.DomainCont...
Sites                              Property   System.DirectoryServices.ActiveDirectory.ReadOnlySi...

大丈夫そうです。ちょっと途切れてしまっていますが、SyntaxCreateLocalSideOfTrustRelationship(string targetForestName,TrustDirection direction,string trustPassword) となっていますので、例えば一方向:出力の信頼を作成する場合、

$TargetForestName = "Domain.Name"
$TrustPassword = "H0gehQ83"
$TrustDirection = "Outbound"
$Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Forest.CreateLocalSideOfTrustRelationship($TargetForestName,$TrustDirection,$TrustPassword)

という、なんともすっきりしないコマンドレットを実行することで信頼の作成が可能です。本当に構成ができているのか確認もしておきたいですよね。では、GUI における [検証] ボタンを押すのと同じように検証をしてみます。

PS > $forest.VerifyOutboundTrustRelationship($TargetForestName)

PS >

何も出力されません。これで大丈夫なのですが、念のため誤ったドメイン名を変数に入力するとこのようなエラーになります。

PS > $fakeTargetForestName = "contoso.com"

PS > $forest.VerifyOutboundTrustRelationship($fakeTargetForestName)
Exception calling "VerifyOutboundTrustRelationship" with "1" argument(s): "A forest trust relationship does not exist 
between "Domain.Name" and "contoso.com"."
At line:1 char:1
+ $forest.VerifyOutboundTrustRelationship($fakeTargetForestName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ActiveDirectoryObjectNotFoundException
 

PS > 

このように出力されると信頼の作成に失敗していることがよくわかります()一応、信頼の作成ができている状態だと Get-ADTrust のような形で現在構成されている信頼関係から状態を確認することもできますので、確認してみてもいいのではないでしょうか。こんな感じですね。

PS > Get-ADTrust -Filter * | Format-Table -Property Direction,Name,ObjectClass,TrustAttributes -AutoSize

Direction Name                    ObjectClass   TrustAttributes
--------- ----                    -----------   ---------------
 Outbound Domain.Name             trustedDomain               8
 Outbound hogehoge.tokyo          trustedDomain               4

ちなみに今回の記事を書くベースになった Automate Forest trust creation に記載がある通り、双方のフォレストの管理者権限をもつアカウントの情報を持っている場合は PowerShell においてもまたちょっと違った方法で信頼を作成する形となります(内容自体は GUI で実施するときと同じです)。

AsSecureStringの値はパスワード欄にそのまま入れると死ぬ

PowerShell 内でパスワードの情報を扱う際に -AsSecureString というパラメーターを使ったり ConvertTo-SecureString コマンドを使ったりするシーンがあるかと思います。SecureString にしない場合はこう。

PS > $Password = Read-Host -Prompt "Enter your Password..."
Enter your Password...: Password

PS > $password
Password

-AsSecureString パラメーターを付けた場合はこう。

PS > $Password = Read-Host -AsSecureString -Prompt "Enter your Password..."
#パスワード入力のためのポップアップは表示されるが、入力した内容は伏字になる
PS > $Password
System.Security.SecureString

ということで、そのままだとパスワードの値そのものは利用できないという認識だったのですが、 Windows PowerShell 4.0 for .NET Developers を見てると次のような形で Outlook.com に接続してサインインまでしてしまおうとしていて「?」となったわけです。

$EmailAddress = Read-Host -Prompt "Enter your Microsoft Account.."
$Password = Read-Host -AsSecureString -Prompt "Enter your Password..."
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible = $true
$ie.navigate("https://outlook.com")
while ($ie.Busy){Start-Sleep -Milliseconds 500}
$doc = $ie.document
$tbUsername = $doc.getElementByID("i0116")
$tbUsername.value = $EmailAddress
$tbPassword = $doc.getElementByID("i0118")
$tbPassword.value = $Password
$tbnSubmit = $doc.getElementByID("idSIButton9")
$tbnSubmit.Click()

結構回りくどい感じですが、それよりも $Password で SecureString になっているパスワードをそのまま突っ込んでいますし、実際にこのコードを実行するとサインインに失敗します。ではどうするか。1つは SecureString を平文に戻す方法です。

$EmailAddress = Read-Host -Prompt "Enter your Microsoft Account.."
$Password = Read-Host -AsSecureString -Prompt "Enter your Password..."
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible = $true
$ie.navigate("https://outlook.com")
while ($ie.Busy){Start-Sleep -Milliseconds 500}
$ie.document.getElementByID("i0116").value = $EmailAddress
$ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
$PasswordPlain = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr)
$ie.document.getElementByID("i0118").value = $PasswordPlain
$ie.document.getElementByID("idSIButton9").Click()

今回は COM を使って元のパスワードに戻していますが、それでもまだ面倒くさい感じがします。もう一つの方法は Get-Credential にアカウント情報を持たせてあげる形です。というより@guitarrapc_tech 氏が下のように言っていたのを見て、そう言えば書籍に書いてあることが間違えているのに気づいたことを思い出して書いているだけです()

$cred = Get-Credential -Message "Input username for login"
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible = $true
$ie.navigate("https://outlook.com")
while ($ie.Busy){Start-Sleep -Milliseconds 500}
$ie.document.getElementByID("i0116").value = $cred.UserName
$ie.document.getElementByID("i0118").value = $cred.GetNetworkCredential().Password
$ie.document.getElementByID("idSIButton9").Click()

こちらのほうが比較的シンプルな感じでしょうか。。。他にいい方法があれば教えてくだしあ。 ※それでもやはりパスワードの情報を利用する際には GetNetworkCredential メソッドを使わないと正しくパスワード情報を得られなくて死にます。

coexistence-configuration の PSsnap-in を追加すると何ができるようになるのか

PowerShell から手動で Office 365 とディレクトリ同期を行うときに Add-PSsnapin coexistence-configuration を実行してから Start-OnlineCoexistenceSync を実行するというのは検索すればすぐに出てくるので新しい話ではないのですが、ちょっと待て、と。よく考えてみると Start-OnlineCoexistenceSync だけを実行するために PSsnap-in を落としてくるのはちょっと非効率すぎないかと思って、中身を見てみました。

Get-Command -Module Coexistence-Configuration | ft CommandType,Name -AutoSize 


CommandType Name                                
----------- ----                             
Cmdlet      Disable-DirSyncLog                    
Cmdlet      Disable-MSOnlinePasswordSync      
Cmdlet      Disable-MSOnlineRichCoexistence    
Cmdlet      Disable-PasswordSyncLog       
Cmdlet      Enable-DirSyncLog          
Cmdlet      Enable-MSOnlinePasswordSync  
Cmdlet      Enable-MSOnlineRichCoexistence   
Cmdlet      Enable-PasswordSyncLog    
Cmdlet      Get-CoexistenceConfiguration     
Cmdlet      Get-DirSyncLogStatus    
Cmdlet      Get-PasswordSyncLogStatus   
Cmdlet      Set-CoexistenceConfiguration   
Cmdlet      Set-CompanyDirSyncFeatures  
Cmdlet      Set-FullPasswordSync                  
Cmdlet      Start-OnlineCoexistenceSync           
Cmdlet      Update-MSOLDirSyncNetworkProxySetting

他にもたくさんありますねw 上で列挙されたコマンドの名前を見るとだいたい何をするためのコマンドかわかりますが、coexistence-configuration スナップインを追加することで Windows Azure Active Directory ディレクトリ同期ツールの構成ウィザードで設定する内容を PowerShell で実行するための(本当はツールが裏で PS を実行しているだけだと思いますが)コマンド各種が実行可能になるようです。詳細は後述で Get-Help -Detailed した内容を貼付けておくので興味があれば見てみてください(ところでこれらのコマンドがなぜ公式で一切情報提供されてないんでしょうか…)。


Enable-MSOnlineRichCoexistence って何かと思ったのですがおそらく構成ウィザードにおける [混合環境を有効にする] で、Azure -> On-Premise の方向での同期の権限付与とかそういう動作のためのコマンドみたいです。

こんな KB 出てました→ Attributes for Exchange Online aren't written back to the on-premises Active Directory directory service in an Exchange hybrid deployment

あと、Update-MSOLDirSyncNetworkProxySettingError message when you run the Directory Sync tool Configuration Wizard: "Your credentials could not be authenticated" という KB が出ていることから察するに、構成ウィザードでは WinHTTP のプロキシの設定を拾ってくれる一方 PowerShell の場合は明示的にこのコマンドでプロキシの設定を拾わないとだめな感じでしょうか。

名前
    Disable-DirSyncLog
   
概要
    This commandlet is used to disable logging for the Azure Active Directory Sync tool.
   
構文
    Disable-DirSyncLog [<CommonParameters>]
   
説明
    This commandlet is used to disable logging for the Azure Active Directory Sync tool.
   
パラメーター
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
   
    C:\PS>Disable-DirSyncLog
   
注釈
    例を参照するには、次のように入力してください: "get-help Disable-DirSyncLog -examples".
    詳細を参照するには、次のように入力してください: "get-help Disable-DirSyncLog -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Disable-DirSyncLog -full".
 
 
 
名前
    Disable-MSOnlinePasswordSync
   
構文
    Disable-MSOnlinePasswordSync -Credential <pscredential> [-WhatIf] [-Confirm]  [<CommonParameters>]
   
パラメーター
    -Confirm
   
    -Credential <pscredential>
   
    -WhatIf
   
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
エイリアス
    なし
   
注釈
    なし
 

 
名前
    Disable-MSOnlineRichCoexistence
   
構文
    Disable-MSOnlineRichCoexistence -Credential <pscredential> [-WhatIf] [-Confirm]  [<CommonParameters>]
   
パラメーター
    -Confirm
   
    -Credential <pscredential>
   
    -WhatIf
   
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
エイリアス
    なし
   
注釈
    なし
 
 
 
名前
    Disable-PasswordSyncLog
   
概要
    This commandlet is used to disable logging for the Password Sync feature of the Azure Active Directory Sync tool.
       
構文
    Disable-PasswordSyncLog [<CommonParameters>]
       
説明
    This commandlet is used to disable logging for the Password Sync feature of the Azure Active Directory Sync tool.
 
パラメーター
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
   
    C:\PS>Disable-PasswordSyncLog
   
注釈
    例を参照するには、次のように入力してください: "get-help Disable-PasswordSyncLog -examples".
    詳細を参照するには、次のように入力してください: "get-help Disable-PasswordSyncLog -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Disable-PasswordSyncLog -full".
 
 
 
名前
    Enable-DirSyncLog
   
概要
    This commandlet is used to configure the logging level for the Azure Active Directory Sync tool.
    
構文
    Enable-DirSyncLog [-FilePath <String>] [-TraceLevel <String>] [<CommonParameters>]
      
説明
    This commandlet is used to configure the logging level for the Azure Active Directory Sync tool.
 
パラメーター
    -FilePath <String>
        Specifies the location in the files system where the log file should be written to.  If not speci
        fied, defaults to the location where the Directory Sync tool is installed.
       
    -TraceLevel <String>
        Specifies the level to configure the Directory Sync tool to log at.  Valid options are: “Error”,
        “Warning”, “Info”, “Verbose”. If not specified, defaults to “Verbose”.
        
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
   
    C:\PS>Enable-DirSyncLog -TraceLevel Info -FilePath C:\DirSync.log
    
注釈
    例を参照するには、次のように入力してください: "get-help Enable-DirSyncLog -examples".
    詳細を参照するには、次のように入力してください: "get-help Enable-DirSyncLog -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Enable-DirSyncLog -full".
 
 
 
 
名前
    Enable-MSOnlinePasswordSync
   
構文
    Enable-MSOnlinePasswordSync -Credential <pscredential> [-WhatIf] [-Confirm]  [<CommonParameters>]
    
パラメーター
    -Confirm
   
    -Credential <pscredential>
   
    -WhatIf
   
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
 エイリアス
    なし

注釈
    なし
 
 
 
 
名前
    Enable-MSOnlineRichCoexistence
   
構文
    Enable-MSOnlineRichCoexistence -Credential <pscredential> [-WhatIf] [-Confirm]  [<CommonParameters>]
   
パラメーター
    -Confirm
   
    -Credential <pscredential>
   
    -WhatIf
   
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
エイリアス
    なし
   
注釈
    なし
 
 
 
 
名前
    Enable-PasswordSyncLog
   
概要
    This commandlet is used to configure the logging level for the Password Sync feature of the Azure Active Directory Sync tool.
   
構文
    Enable-PasswordSyncLog [-FilePath <String>] [-TraceLevel <String>] [<CommonParameters>]
   
説明
    This commandlet is used to configure the logging level for the Password Sync feature of the Azure Active Directory Sync tool.
 
パラメーター
    -FilePath <String>
        Specifies the location in the files system where the log file should be written to.  If not speci
        fied, defaults to the location where the Directory Sync tool is installed.
       
    -TraceLevel <String>
        Specifies the level to configure the Directory Sync tool to log at.  Valid options are: “Error”, “Warning”, “Info”, “Verbose”.  If not specified, defaults to 'Verbose'.
       
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
   
    C:\PS>Enable-PasswordSyncLog -TraceLevel Info -FilePath C:\PasswordSync.log
   
注釈
    例を参照するには、次のように入力してください: "get-help Enable-PasswordSyncLog -examples".
    詳細を参照するには、次のように入力してください: "get-help Enable-PasswordSyncLog -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Enable-PasswordSyncLog -full".
 
 
 
 
名前
    Get-CoexistenceConfiguration
   
概要
    Gets a configuration information from the Microsoft Online Coexistence Web Server   
    
構文
    Get-CoexistenceConfiguration -TargetCredentials <PSCredential> [<CommonParameters>]
    
説明
    Gets a configuration information from the Microsoft Online Coexistence Web Server
 
パラメーター
    -TargetCredentials <PSCredential>
        Administrative credentials for a company in Microsoft Online.
       
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Get Configuration --------------
   
    C:\PS>$cnfg = Get-CoexistenceConfiguration
   
    Gets a configuration object from the Microsoft Online Web Service    
    
注釈
    例を参照するには、次のように入力してください: "get-help Get-CoexistenceConfiguration -examples".
    詳細を参照するには、次のように入力してください: "get-help Get-CoexistenceConfiguration -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Get-CoexistenceConfiguration -full".
 
 
 
 
名前
    Get-DirSyncLogStatus
   
概要
    This commandlet is used to retrieve the current logging level for the Azure Active Directory Sync tool.
    
構文
    Get-DirSyncLogStatus [<CommonParameters>]
    
説明
    This commandlet is used to retrieve the current logging level for the Azure Active Directory Sync tool.  
 
パラメーター
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
    
    C:\PS>Get-DirSyncLogStatus
      
注釈
    例を参照するには、次のように入力してください: "get-help Get-DirSyncLogStatus -examples".
    詳細を参照するには、次のように入力してください: "get-help Get-DirSyncLogStatus -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Get-DirSyncLogStatus -full".
 
 
 
 
名前
    Get-PasswordSyncLogStatus
   
概要
    This commandlet is used to retrieve the current logging level for the Password Sync feature of the Azure Active Directory Sync tool.
    
構文
    Get-PasswordSyncLogStatus [<CommonParameters>]
   
説明
    This commandlet is used to retrieve the current logging level for the Password Sync feature of the Azure Active Directory Sync tool.
 
パラメーター
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Example  --------------
   
    C:\PS>Get-PasswordSyncLogStatus
   
注釈
    例を参照するには、次のように入力してください: "get-help Get-PasswordSyncLogStatus -examples".
    詳細を参照するには、次のように入力してください: "get-help Get-PasswordSyncLogStatus -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Get-PasswordSyncLogStatus -full".
 
 
 
 
名前
    Set-CoexistenceConfiguration
   
概要
    Configures Microsoft Online Directory Synchronization Tool.
 
構文
    Set-CoexistenceConfiguration -SourceCredentials <PSCredential> -TargetCredentials <PSCredential> [-Config] <CoexistenceConfiguration> [-Path <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
     
説明
    Configures Microsoft Online Directory Synchronization Tool.
 
パラメーター
    -SourceCredentials <PSCredential>
        Enterprise Admin credentials for the forest that will be sent up to Microsoft Online.  These credentials are used to create an account in Active Directory that has the minimum required permissions to read from Active Directory.
       
    -TargetCredentials <PSCredential>
        Administrative credentials for a company in Microsoft Online.
       
    -Config <CoexistenceConfiguration>
        Configuration object returned from Get-CoexistenceConfiguration
       
    -Path <String>
        The directory which contains XML that defines the default management agents and the metaverse schema.
       
    -WhatIf
       
        
    -Confirm
       
        
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Configuration --------------
   
    C:\PS>$cnfg = Get-CoexistenceConfiguration
    Set-CoexistenceConfiguration $cnfg
   
    Configures Microsoft Online Directory Synchronization.
   
 注釈
    例を参照するには、次のように入力してください: "get-help Set-CoexistenceConfiguration -examples".
    詳細を参照するには、次のように入力してください: "get-help Set-CoexistenceConfiguration -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Set-CoexistenceConfiguration -full".
 
 
 
 
名前
    Set-CompanyDirSyncFeatures
   
構文
    Set-CompanyDirSyncFeatures -TargetCredentials <pscredential> -FeaturesFlag <int>  [<CommonParameters>
    ]
    
パラメーター
    -FeaturesFlag <int>
   
    -TargetCredentials <pscredential>
   
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
 
エイリアス
    なし
  
注釈
    なし
 
 
 
 
名前
    Set-FullPasswordSync
   
概要
    Resets the password sync state information forcing a full sync the next time the service is restarted.  
    
構文
    Set-FullPasswordSync [<CommonParameters>]
    
説明
    Resets the password sync state information forcing a full sync the next time the service is restarted.   
 
パラメーター
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Set FullPasswordSync --------------
   
    C:\PS>Set-FullPasswordSync
   
    Resets the password sync state information forcing a full sync the next time the service is restarted.   
    
注釈
    例を参照するには、次のように入力してください: "get-help Set-FullPasswordSync -examples".
    詳細を参照するには、次のように入力してください: "get-help Set-FullPasswordSync -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Set-FullPasswordSync -full".
 
 
 
 
名前
    Start-OnlineCoexistenceSync
   
概要
    Starts synchronization with Microsoft Online
   
構文
    Start-OnlineCoexistenceSync [-FullSync] [-WhatIf] [-Confirm] [<CommonParameters>]
    
説明
    Starts synchronization with Microsoft Online
   
パラメーター
    -FullSync
        Performs a full sync with Microsoft Online.
       
    -WhatIf
       
        
    -Confirm
       
        
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  Start Sync --------------
   
    C:\PS>Start-OnlineCoexistenceSync
   
    Starts a directory sync with Microsoft Online.
   
    
    
    -----------  Start Full Sync ------------
   
    C:\PS>Start-OnlineCoexistenceSync -FullSync
   
    Performs a full sync with Microsoft Online.
   
注釈
    例を参照するには、次のように入力してください: "get-help Start-OnlineCoexistenceSync -examples".
    詳細を参照するには、次のように入力してください: "get-help Start-OnlineCoexistenceSync -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Start-OnlineCoexistenceSync -full".
 
 
 
 
名前
    Update-MSOLDirSyncNetworkProxySetting
   
概要
    Updates the directory sync service to use the current user's http proxy settings.
   
構文
    Update-MSOLDirSyncNetworkProxySetting [[-NoProxyUpdate]] [-WhatIf] [-Confirm] [<CommonParameters>]
    
説明
    Copies the current user's http proxy settings off to a .config file.  The directory sync will apply these settings each time it communicates with the directory sync web service
   
パラメーター
    -NoProxyUpdate
        Causes directory sync to ignore the http proxy settings that were saved in a .config file.
       
    -WhatIf
       
        
    -Confirm
       
        
    <CommonParameters>
        このコマンドレットは、次の共通パラメーターをサポートします: Verbose、
        Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、
        OutBuffer、および OutVariable。詳細については、about_CommonParameters
        (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。
   
    --------------  EXAMPLE 1 --------------
   
    C:\PS>Update-MSOLDirSyncNetworkProxySetting
   
    Updates the http proxy settings that directory sync will use
   
    
    
    
    --------------  EXAMPLE 2 --------------
   
    C:\PS>Update-MSOLDirSyncNetworkProxySetting -NoProxyUpdate
   
    Disables the automatic application of current user setting to the directory sync service.
   
    
注釈
    例を参照するには、次のように入力してください: "get-help Update-MSOLDirSyncNetworkProxySetting -examples".
    詳細を参照するには、次のように入力してください: "get-help Update-MSOLDirSyncNetworkProxySetting -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Update-MSOLDirSyncNetworkProxySetting -full".
    オンライン ヘルプを参照するには、次のように入力してください: "get-help Update-MSOLDirSyncNetworkProxySetting -online"

PowerShell によるパスワードの生成に char 型を使ってみる

ちょっと Active Directory でユーザーを自動的に作成する際に予めランダムかつある程度の複雑性があるパスワードを設定しておきたいなということで、これを生成する方法が必要になりました。それで、私はゆとり PowerShell-er なのでまず検索してみますと powershell.com にこんなスクリプトがありました。

    function Get-RandomPassword {
        param(
            $length = 10,
            $characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789!"§\$%&/()=?*+#_'
            )
    
        $random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
         # output random pwd
         $private:ofs=""
         [String]$characters[$random]
    } 

文字列の生成方法としては、予め候補となる文字記号数字を $characters に格納し、$length で文字数を指定して Get-Randam でそれらの情報を利用して文字列をランダムに生成している感じで特別変わったことはしてない感じです。不足があれば記号とか増やしてあげるといいです。

次はこちら。これは Windows Server 2012 Automation with PowerShell Cookbook の Chapter 2, Creating AD Users に書かれていたスクリプトです。上述のスクリプトに対してこちらのスクリプトの書き方がちょっとおもしろいというか、理屈を考えれば何ら不思議のない書き方なのですが、あんまり見たことがない書き方かなということでこちらが本題(?)です。

function Get-RandomPass{
    $newPass = ''
    1..10 | ForEach-Object {
    $newPass += [char](Get-Random -Minimum 48 -Maximum 122)
    }
    return $newPass
}

$newPass の部分を見ると [char](Get-random -Minimun 48 -Maximum 122) という部分があります。ここで何をしているかというと Get-Random-Minimum および -Maximum パラメータで指定した範囲内でランダムに取得された int 型の値を10進法の ASCII コードとして扱うべく [char] で char 型に変換した結果として文字を取得しています。

上のスクリプトで指定している最小値および最大値から判断する限り、以下の文字の中からランダムに文字列を生成することが意図されていると考えられますが、この理屈から言うと ASCII 33 (min) - 126 (max) までが範囲として最大となり、最も多くの記号を利用することになります1。ASCII 32 まで含むとスペースを含むことになりますね。

$characters = 
'0123456789:;<=>?@ABCDEFHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz'

どちらの方法がどうだとかいうことではありませんが、fizzbuzz にもいろいろな書き方があるような感じで「へぇ」ぐらいに受け取ってもらえれば。

Get-HofixのInstalledOnの時間が取得できない(未解決)

タイトルの通りなのですが…。

PS >Get-HotFix | Format-Table -AutoSize

Source    Description HotFixID  InstalledBy         InstalledOn         
------    ----------- --------  -----------         -----------         
TESTLAB01 Update      KB2871777 NT AUTHORITY\SYSTEM 3/1/2014 12:00:00 AM
TESTLAB01 Update      KB2877213 NT AUTHORITY\SYSTEM 3/1/2014 12:00:00 AM
TESTLAB01 Update      KB2891804 NT AUTHORITY\SYSTEM 3/1/2014 12:00:00 AM
TESTLAB01 Update      KB2904266 NT AUTHORITY\SYSTEM 3/1/2014 12:00:00 AM

Get-Hotfix でインストールした Hotfix の情報を取得すると InstalledOn のパラメータの時刻の値が勝手に 12:00:00 AM になってしまいます。それで調べてみたところ同じような現象が発生している方がいらっしゃったようでフォーラムに書き込みがされているのをいくつか見ていたところ、Microsoft Connect で報告されている以下のバグのような気がしますが、まだ fix されていないという認識でいいのでしょうかね…。

Get-Hotfix show date only if date parsing has same rules as in en-US Culture.

work around として一応 $env:windir\WindowsUpdate.log の文字列を Select-String して Hotfix の情報を取る方法とかあるみたいですが微妙な感じです…。