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

それで出世が遅れ(ry

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 の情報を取る方法とかあるみたいですが微妙な感じです…。

8 Faces Issue #7 と Helvetica

もう昨年末の話になるのですが、11月頃?に発行された 8 Faces Issue #7 で最初にインタビュー記事が掲載されている Michael Bierut 氏の Helvetica に関する発言の中で、最後に氏が選んだ8つのタイプフェイスのうちの1つ、Helvetica の部分に書かれているコメントが以下の通りとなるのですが、少しおもしろいなと思うところがありまして。

Because I'm in the documentary about it, people tend to associate me with Helvetica. YET I'VE ALWAYS TRIED TO RESIST IT, WHICH IS DIFFICULT. Like others, I've tried to improve it, but that's difficult too. For our wayfinding for the New York City Department of Transportation, we changed all the square dots to round, which I enjoyed. (p.16)

Michael Bierut 氏と Helvetica と言えば、まさに Helvetica というタイトルのドキュメンタリー映画に出演し非常に印象的な以下の発言をしていましたが、このドキュメンタリー映画には氏以外にも様々なタイプデザイナーの方が出演されており、それぞれが各々の観点で Helvetica について話していたことがこのドキュメンタリー映画の大きな特徴と言えると思います(今更な話ではありますが)。

一方で "people tend to associate me with Helvetica." というようなことを他のタイプデザイナーが言っているを聞いた/見たことは寡聞にしてありません(どなたかそういう発言をされているソースとかお持ちでしょうか)。

"Can you imagine how bracing and thrilling that was? That must have felt like you had crawled through a desert with your mouth caked with filthy dust, and then someone offers you a clear, refreshing distilled icy glass of water … it must have just been fantastic."


Helvetica - PERIOD. - YouTube

Issue #7 が発行された 2013 年当時 Helvetica に関して話題になっていたのは iOS 7 が Helvetica Neue Ultra Light を採用したとかそういうことぐらいで、今更と言っては語弊がありますが Helvetica について現在進行形で Helvetica があふれる世の中に抵抗してみたとか Helvetica をよりよくしようとしたというようなことを語るタイプデザイナーをあまり見かけない気がして、逆に新鮮な感じでした。そういう所がおもしろかったよ、という話です。

もちろん iOS 7 で Helvetica Neue Ultra Light を採用するのは適切ではなかったというような話はありましたが、それはタイプフェイスそのものの話ではないので…。

あと、どうでもいいことなのですが Helvetica の特徴について、おそらく Wikipedia からの引用だと思われるのですが”簡素な”という形容詞を使われる方をたまに見かけます。しかしながら Helvetica を表すのに簡素というのはあまり適切ではないように思います。感覚の問題と言ってしまえばそうかもしれませんが、いったいどの辺りが簡素なのか、じゃあ例えば Frutiger はどうなのか。。。