資格情報の代替セットを提供する必要があるため、powershell を使用して呼び出すことにより、いくつかの ADSI/LDAP クエリを実行しDirectoryServices.DirectorySearcher
ます。FindAll()
メソッドを実行すると、DirectoryServices.SearchResultCollection
を実装する が得られますICollection
。そこから、その出力を ft または export-csv にパイプしたい場合は、次のように、関心のある属性を新しい PSObject にコピーする新しい psobject を作成する必要があります。
$dEntry = New-Object DirectoryServices.DirectoryEntry("LDAP://acme.com/cn=sites,cn=configuration,dc=acme,dc=com","user","pass");
$searcher=New-Object DirectoryServices.DirectorySearcher($dEntry);
$searcher.Filter="(objectClass=siteLink)";
$searcher.PropertiesToLoad.Add("siteList");
$searcher.PropertiesToLoad.Add("cost");
$searcher.PropertiesToLoad.Add("replInterval");
$searcher.PropertiesToLoad.Add("cn");
$searcher.FindAll() |%{
$count=$_.Properties.sitelist.Count;
$p=@{"cn"=[string]$_.Properties.cn; "sites"=$count;
"cost"=[string]$_.Properties.cost;
"replInterval"=[string]$_.Properties.replInterval;
};
if ($count>=2) {
$p["mesh"]=$count;
}else{
$p["mesh"]=$count*$count;
}
New-Object psobject -Property $p
}
これは非常に面倒に見えますが、おそらく非常に一般的なタスクであるため、もっと簡単な方法があるはずです。はい、私は AD ヘルパー ライブラリを知っていますが、代替の資格情報を使用する必要があり、ほとんどがこの方法で壊れているため、それらは役に立ちません。