問題をすべてのSidを現在のループに追加できません。他のすべては私が期待したとおりに働いています。私は自分のコードに表示されている各ユーザーのSIDを追加するために自分のコードを追加する手助けが必要です。 SIDが表示されます。C#のActive DirectoryからすべてのユーザーのSIDを追加する
である私の現在のコード:
namespace ActiveDirectoryDisplayNamesApp
{
class Program
{
static void Main(string[] args)
{
using (var context = new PrincipalContext(ContextType.Domain, "nor-amcoldcorp.local"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
var sidByte = ObjectToByteArray(de.Properties["objectSId"].Value);
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value);
Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
Console.WriteLine("Object Sid: " + System.Text.Encoding.UTF8.GetString(sidByte)); //Here is the changement
Console.WriteLine();
}
}
}
Console.ReadLine();
}
static public byte[] ObjectToByteArray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}
私のchangementを見てみましょう。 post obove – AndresBryan29
リンクされたポストでメソッドを試しても分かりませんが、試してみましたが、約5分でDirectoryEntryプロパティからSIDが出力されました。 – Laslos
私は結果を使用しているコードを追加します – AndresBryan29