-
October 3rd, 2014, 03:55 PM
#1
Collection Item Question
Hello,
I have been trying to figure out how I can get a specific item from this collection, output to a Console.Writeline.
Sample output from console as of now:
Enter computer name: sql
cn : SQL
dnshostname : SQL.lab.local
description : SQL Server for LAB
What I'm trying to do is get dnshostname and description into a string, so that I can use it to perform other tasks on the local computer.
I have it outputing the correct information, I just cannot seems to figure out what todo next.
I tried these things.
Console.WriteLine([dnshostname].myCollection.ToString();
Console.WriteLine(dnshostname.myCollection.ToString();
Console.WriteLine(property, 1, myCollection.ToString();
Console.WriteLine(property[1].ToString());
I'm new to doing this and maybe you can see from the code below, how to help me.
If you have any need for more information, please let me know.
Code:
string[] requiredProperties = new string[] { "cn", "dnshostname", "description" };
foreach (String property in requiredProperties)
search.PropertiesToLoad.Add(property);
SearchResult result = search.FindOne();
if (result != null)
{
foreach (String property in requiredProperties)
foreach (Object myCollection in result.Properties[property])
Console.WriteLine(String.Format("{0,-20} : {1}",
property, myCollection.ToString()));
// Perform local computer name check and replace
// this is where I need help?????????????????????? below
Console.WriteLine();
}
else Console.WriteLine("Computer not found!");
}
catch (Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
Thanks for the help,
-Mike
-
October 4th, 2014, 02:15 PM
#2
Re: Collection Item Question
The code you posted doesn't include the code for the variable 'search'.
-
October 4th, 2014, 02:40 PM
#3
Re: Collection Item Question
i would ask that you clarify the question more specifically?
often
just asking one individual specific question well spoken, is far better than,
trying to squeeze in a whole set of problem's into a post
1)
I have been trying to figure out how I can get a specific item from this collection, then output it to a Console.Writeline
2)
What I'm trying to do is get dnshostname and description into a string
3)
I have it outputing the correct information,
4)
I just cannot seem to figure out, what todo next.
it appears you can place what you want in a console writeline ?
but just simply want it in a string ?
string s = String.Format("{0,-20} : {1}", property, myCollection.ToString());
however these lines
string[] requiredProperties = ect...
foreach (String property in requiredProperties)
this line
foreach (Object myCollection in result.Properties[property]) // you might want Object to be var instead ?
as arjay said
we also cannot see the class or struct for SearchResult or what the FindOne() method is doing
so we cannot know what the object myCollection holds, which is a object technically by the shown foreach
Last edited by willmotil; October 4th, 2014 at 03:06 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|