Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - ADO & Powershell

Reply
 
Old 08-15-2006   #1 (permalink)
Dean Wells [MVP]


 
 

ADO & Powershell

It was mentioned to me that Powershell may have issues with ADO but I
can't seem to find a reference to back that up. As such, I'm working on
the assumption that it will eventually work. I've been trying to
execute a simple LDAP query against a backend AD, the goal of which is
to simply iterate through the result set and do 'X' task with each of
the objects. Here's what's being returned -

PS C:\> C:\test.ps1
Exception calling "Execute" with "0" argument(s): "Table does not
exist."
At C:\test.ps1:11 char:28
+ $qRes = $objCommand.Execute( <<<< )

Here's C:\test.ps1 -

$objCommand = New-object -comobject "ADODB.Command"
$objConnection = New-object -comobject "ADODB.Connection"
$objConnection.Provider =
"ADsDSOObject;UserID=administrator;Password=password;"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

$query =
"<LDAP://cubelet/dc=mset,dc=lab>;(objectcategory=user);1.1;subtree"
$objCommand.CommandText = $query
$qRes = $objCommand.Execute()

If would appear the Execute method requires a few args. in Powershell,
any pointers?

Thanks in advance!

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l



My System SpecsSystem Spec
Old 08-15-2006   #2 (permalink)
Chris Warwick


 
 

Re: ADO & Powershell

On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
<dwells@mask.msetechnology.com> wrote:

> I've been trying to
>execute a simple LDAP query against a backend AD, the goal of which is
>to simply iterate through the result set and do 'X' task with each of
>the objects.


Try this:

$Searcher=New-Object DirectoryServices.DirectorySearcher
$Searcher.Filter="(objectcategory=user)" # LDAP of your choice
$Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}

Change the last line to pick out the attributes you're interested in

hth
Chris
My System SpecsSystem Spec
Old 08-15-2006   #3 (permalink)
Dean Wells [MVP]


 
 

Re: ADO & Powershell

Thanks Chris ... appreciate it, I'll give that a go.

And though helpful in this instance, it still leaves the bigger question
re: ADO, any further input?

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

"Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
> On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
> <dwells@mask.msetechnology.com> wrote:
>
>> I've been trying to
>>execute a simple LDAP query against a backend AD, the goal of which is
>>to simply iterate through the result set and do 'X' task with each of
>>the objects.

>
> Try this:
>
> $Searcher=New-Object DirectoryServices.DirectorySearcher
> $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
> $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>
> Change the last line to pick out the attributes you're interested in
>
> hth
> Chris



My System SpecsSystem Spec
Old 08-15-2006   #4 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

Re: ADO & Powershell

This works for me :

PoSH>$objCommand = New-object -comobject "ADODB.Command"
PoSH>$objConnection = New-object -comobject "ADODB.Connection"
PoSH>$objConnection.Provider = "ADsDSOObject"
PoSH>$objConnection.Open("Active Directory Provider")
PoSH>$objCommand.ActiveConnection = $objConnection
PoSH>
PoSH>$query =
"<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
PoSH>$objCommand.CommandText = $query
PoSH>$qRes = $objCommand.Execute()
PoSH>$qres


Properties : {IAccessor, IColumnsInfo, IColumnsInfo2, IConvertType...}
AbsolutePosition : 1
ActiveConnection : ADODB.ConnectionClass
BOF : False
Bookmark : 0
CacheSize : 1
CursorType : adOpenStatic
EOF : False
Fields : {cn, adspath}
LockType : adLockReadOnly
MaxRecords : 0
RecordCount : 21
Source :
<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
AbsolutePage : 1
EditMode : adEditNone
Filter : 0
PageCount : 3
PageSize : 10
Sort :
Status : 0
State : 1
CursorLocation : adUseServer
MarshalOptions : adMarshalAll
DataSource : ADODB.RecordsetClass
ActiveCommand : ADODB.CommandClass
StayInSync : True
DataMember :
Index :



PoSH>$qres.fields


Status : 0
ActualSize : 26
Attributes : 32
DataFormat :
DefinedSize : 256
Name : cn
NumericScale : 255
OriginalValue :
Precision : 255
Properties : {}
Type : adVarWChar
UnderlyingValue :
Value : Administrator

Status : 0
ActualSize : 114
Attributes : 32
DataFormat :
DefinedSize : 256
Name : adspath
NumericScale : 255
OriginalValue :
Precision : 255
Properties : {}
Type : adVarWChar
UnderlyingValue :
Value : LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local

Greetings /\/\o\/\/
for more examples using .NET see :

http://mow001.blogspot.com/2006/08/p...ry-part-8.html

"Dean Wells [MVP]" wrote:

> Thanks Chris ... appreciate it, I'll give that a go.
>
> And though helpful in this instance, it still leaves the bigger question
> re: ADO, any further input?
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
> > <dwells@mask.msetechnology.com> wrote:
> >
> >> I've been trying to
> >>execute a simple LDAP query against a backend AD, the goal of which is
> >>to simply iterate through the result set and do 'X' task with each of
> >>the objects.

> >
> > Try this:
> >
> > $Searcher=New-Object DirectoryServices.DirectorySearcher
> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
> >
> > Change the last line to pick out the attributes you're interested in
> >
> > hth
> > Chris

>
>
>

My System SpecsSystem Spec
Old 08-16-2006   #5 (permalink)
Dean Wells [MVP]


 
 

Re: ADO & Powershell

Heh, still doesn't work for me as is ... it seems supplying the creds.
causes the failure -

[FAILS]
$objConnection.Provider =
"ADsDSOObject;UserID=administrator;Password=password;"

[SUCCEEDS]
$objConnection.Provider = "ADsDSOObject"

.... sadly, it doesn't entriely resolve the issue since I do on occasion
need to provide the credentials.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
> This works for me :
>
> PoSH>$objCommand = New-object -comobject "ADODB.Command"
> PoSH>$objConnection = New-object -comobject "ADODB.Connection"
> PoSH>$objConnection.Provider = "ADsDSOObject"
> PoSH>$objConnection.Open("Active Directory Provider")
> PoSH>$objCommand.ActiveConnection = $objConnection
> PoSH>
> PoSH>$query =
> "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
> PoSH>$objCommand.CommandText = $query
> PoSH>$qRes = $objCommand.Execute()
> PoSH>$qres
>
>
> Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
> IConvertType...}
> AbsolutePosition : 1
> ActiveConnection : ADODB.ConnectionClass
> BOF : False
> Bookmark : 0
> CacheSize : 1
> CursorType : adOpenStatic
> EOF : False
> Fields : {cn, adspath}
> LockType : adLockReadOnly
> MaxRecords : 0
> RecordCount : 21
> Source :
> <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
> AbsolutePage : 1
> EditMode : adEditNone
> Filter : 0
> PageCount : 3
> PageSize : 10
> Sort :
> Status : 0
> State : 1
> CursorLocation : adUseServer
> MarshalOptions : adMarshalAll
> DataSource : ADODB.RecordsetClass
> ActiveCommand : ADODB.CommandClass
> StayInSync : True
> DataMember :
> Index :
>
>
>
> PoSH>$qres.fields
>
>
> Status : 0
> ActualSize : 26
> Attributes : 32
> DataFormat :
> DefinedSize : 256
> Name : cn
> NumericScale : 255
> OriginalValue :
> Precision : 255
> Properties : {}
> Type : adVarWChar
> UnderlyingValue :
> Value : Administrator
>
> Status : 0
> ActualSize : 114
> Attributes : 32
> DataFormat :
> DefinedSize : 256
> Name : adspath
> NumericScale : 255
> OriginalValue :
> Precision : 255
> Properties : {}
> Type : adVarWChar
> UnderlyingValue :
> Value :
> LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
>
> Greetings /\/\o\/\/
> for more examples using .NET see :
>
> http://mow001.blogspot.com/2006/08/p...ry-part-8.html
>
> "Dean Wells [MVP]" wrote:
>
>> Thanks Chris ... appreciate it, I'll give that a go.
>>
>> And though helpful in this instance, it still leaves the bigger
>> question
>> re: ADO, any further input?
>>
>> --
>> Dean Wells [MVP / Directory Services]
>> MSEtechnology
>> [[ Please respond to the Newsgroup only regarding posts ]]
>> R e m o v e t h e m a s k t o s e n d e m a i l
>>
>> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
>> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
>> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
>> > <dwells@mask.msetechnology.com> wrote:
>> >
>> >> I've been trying to
>> >>execute a simple LDAP query against a backend AD, the goal of which
>> >>is
>> >>to simply iterate through the result set and do 'X' task with each
>> >>of
>> >>the objects.
>> >
>> > Try this:
>> >
>> > $Searcher=New-Object DirectoryServices.DirectorySearcher
>> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
>> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>> >
>> > Change the last line to pick out the attributes you're interested
>> > in
>> >
>> > hth
>> > Chris

>>
>>
>>



My System SpecsSystem Spec
Old 08-16-2006   #6 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: ADO & Powershell

By any chance, does the password include any of the following characters:
`(backtick)
or one of
{$(
This is grabbing at straws. : |


"Dean Wells [MVP]" <dwells@mask.msetechnology.com> wrote in message
news:uL6LCtTwGHA.4868@TK2MSFTNGP02.phx.gbl...
> Heh, still doesn't work for me as is ... it seems supplying the creds.
> causes the failure -
>
> [FAILS]
> $objConnection.Provider =
> "ADsDSOObject;UserID=administrator;Password=password;"
>
> [SUCCEEDS]
> $objConnection.Provider = "ADsDSOObject"
>
> ... sadly, it doesn't entriely resolve the issue since I do on occasion
> need to provide the credentials.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
>> This works for me :
>>
>> PoSH>$objCommand = New-object -comobject "ADODB.Command"
>> PoSH>$objConnection = New-object -comobject "ADODB.Connection"
>> PoSH>$objConnection.Provider = "ADsDSOObject"
>> PoSH>$objConnection.Open("Active Directory Provider")
>> PoSH>$objCommand.ActiveConnection = $objConnection
>> PoSH>
>> PoSH>$query =
>> "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
>> PoSH>$objCommand.CommandText = $query
>> PoSH>$qRes = $objCommand.Execute()
>> PoSH>$qres
>>
>>
>> Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
>> IConvertType...}
>> AbsolutePosition : 1
>> ActiveConnection : ADODB.ConnectionClass
>> BOF : False
>> Bookmark : 0
>> CacheSize : 1
>> CursorType : adOpenStatic
>> EOF : False
>> Fields : {cn, adspath}
>> LockType : adLockReadOnly
>> MaxRecords : 0
>> RecordCount : 21
>> Source :
>> <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
>> AbsolutePage : 1
>> EditMode : adEditNone
>> Filter : 0
>> PageCount : 3
>> PageSize : 10
>> Sort :
>> Status : 0
>> State : 1
>> CursorLocation : adUseServer
>> MarshalOptions : adMarshalAll
>> DataSource : ADODB.RecordsetClass
>> ActiveCommand : ADODB.CommandClass
>> StayInSync : True
>> DataMember :
>> Index :
>>
>>
>>
>> PoSH>$qres.fields
>>
>>
>> Status : 0
>> ActualSize : 26
>> Attributes : 32
>> DataFormat :
>> DefinedSize : 256
>> Name : cn
>> NumericScale : 255
>> OriginalValue :
>> Precision : 255
>> Properties : {}
>> Type : adVarWChar
>> UnderlyingValue :
>> Value : Administrator
>>
>> Status : 0
>> ActualSize : 114
>> Attributes : 32
>> DataFormat :
>> DefinedSize : 256
>> Name : adspath
>> NumericScale : 255
>> OriginalValue :
>> Precision : 255
>> Properties : {}
>> Type : adVarWChar
>> UnderlyingValue :
>> Value :
>> LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
>>
>> Greetings /\/\o\/\/
>> for more examples using .NET see :
>>
>> http://mow001.blogspot.com/2006/08/p...ry-part-8.html
>>
>> "Dean Wells [MVP]" wrote:
>>
>>> Thanks Chris ... appreciate it, I'll give that a go.
>>>
>>> And though helpful in this instance, it still leaves the bigger question
>>> re: ADO, any further input?
>>>
>>> --
>>> Dean Wells [MVP / Directory Services]
>>> MSEtechnology
>>> [[ Please respond to the Newsgroup only regarding posts ]]
>>> R e m o v e t h e m a s k t o s e n d e m a i l
>>>
>>> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
>>> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
>>> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
>>> > <dwells@mask.msetechnology.com> wrote:
>>> >
>>> >> I've been trying to
>>> >>execute a simple LDAP query against a backend AD, the goal of which is
>>> >>to simply iterate through the result set and do 'X' task with each of
>>> >>the objects.
>>> >
>>> > Try this:
>>> >
>>> > $Searcher=New-Object DirectoryServices.DirectorySearcher
>>> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
>>> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>>> >
>>> > Change the last line to pick out the attributes you're interested in
>>> >
>>> > hth
>>> > Chris
>>>
>>>
>>>

>
>



My System SpecsSystem Spec
Old 08-16-2006   #7 (permalink)
Brandon Shell


 
 

Re: ADO & Powershell

How do you access a specific Field Value.

Example in VBS:
rs.Fields("Name").Value

In POSH:
$rs.Fields("Name").Value

POSH failes with Method Error


"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
> This works for me :
>
> PoSH>$objCommand = New-object -comobject "ADODB.Command"
> PoSH>$objConnection = New-object -comobject "ADODB.Connection"
> PoSH>$objConnection.Provider = "ADsDSOObject"
> PoSH>$objConnection.Open("Active Directory Provider")
> PoSH>$objCommand.ActiveConnection = $objConnection
> PoSH>
> PoSH>$query =
> "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
> PoSH>$objCommand.CommandText = $query
> PoSH>$qRes = $objCommand.Execute()
> PoSH>$qres
>
>
> Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
> IConvertType...}
> AbsolutePosition : 1
> ActiveConnection : ADODB.ConnectionClass
> BOF : False
> Bookmark : 0
> CacheSize : 1
> CursorType : adOpenStatic
> EOF : False
> Fields : {cn, adspath}
> LockType : adLockReadOnly
> MaxRecords : 0
> RecordCount : 21
> Source :
> <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
> AbsolutePage : 1
> EditMode : adEditNone
> Filter : 0
> PageCount : 3
> PageSize : 10
> Sort :
> Status : 0
> State : 1
> CursorLocation : adUseServer
> MarshalOptions : adMarshalAll
> DataSource : ADODB.RecordsetClass
> ActiveCommand : ADODB.CommandClass
> StayInSync : True
> DataMember :
> Index :
>
>
>
> PoSH>$qres.fields
>
>
> Status : 0
> ActualSize : 26
> Attributes : 32
> DataFormat :
> DefinedSize : 256
> Name : cn
> NumericScale : 255
> OriginalValue :
> Precision : 255
> Properties : {}
> Type : adVarWChar
> UnderlyingValue :
> Value : Administrator
>
> Status : 0
> ActualSize : 114
> Attributes : 32
> DataFormat :
> DefinedSize : 256
> Name : adspath
> NumericScale : 255
> OriginalValue :
> Precision : 255
> Properties : {}
> Type : adVarWChar
> UnderlyingValue :
> Value :
> LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
>
> Greetings /\/\o\/\/
> for more examples using .NET see :
>
> http://mow001.blogspot.com/2006/08/p...ry-part-8.html
>
> "Dean Wells [MVP]" wrote:
>
>> Thanks Chris ... appreciate it, I'll give that a go.
>>
>> And though helpful in this instance, it still leaves the bigger question
>> re: ADO, any further input?
>>
>> --
>> Dean Wells [MVP / Directory Services]
>> MSEtechnology
>> [[ Please respond to the Newsgroup only regarding posts ]]
>> R e m o v e t h e m a s k t o s e n d e m a i l
>>
>> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
>> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
>> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
>> > <dwells@mask.msetechnology.com> wrote:
>> >
>> >> I've been trying to
>> >>execute a simple LDAP query against a backend AD, the goal of which is
>> >>to simply iterate through the result set and do 'X' task with each of
>> >>the objects.
>> >
>> > Try this:
>> >
>> > $Searcher=New-Object DirectoryServices.DirectorySearcher
>> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
>> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>> >
>> > Change the last line to pick out the attributes you're interested in
>> >
>> > hth
>> > Chris

>>
>>
>>



My System SpecsSystem Spec
Old 08-16-2006   #8 (permalink)
Dean Wells [MVP]


 
 

Re: ADO & Powershell

Sadly no, the password is the literal I posted earlier - "password".

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:%23hpHOOUwGHA.324@TK2MSFTNGP06.phx.gbl...
> By any chance, does the password include any of the following
> characters:
> `(backtick)
> or one of
> {$(
> This is grabbing at straws. : |
>
>
> "Dean Wells [MVP]" <dwells@mask.msetechnology.com> wrote in message
> news:uL6LCtTwGHA.4868@TK2MSFTNGP02.phx.gbl...
>> Heh, still doesn't work for me as is ... it seems supplying the
>> creds. causes the failure -
>>
>> [FAILS]
>> $objConnection.Provider =
>> "ADsDSOObject;UserID=administrator;Password=password;"
>>
>> [SUCCEEDS]
>> $objConnection.Provider = "ADsDSOObject"
>>
>> ... sadly, it doesn't entriely resolve the issue since I do on
>> occasion need to provide the credentials.
>>
>> --
>> Dean Wells [MVP / Directory Services]
>> MSEtechnology
>> [[ Please respond to the Newsgroup only regarding posts ]]
>> R e m o v e t h e m a s k t o s e n d e m a i l
>>
>> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
>> news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
>>> This works for me :
>>>
>>> PoSH>$objCommand = New-object -comobject "ADODB.Command"
>>> PoSH>$objConnection = New-object -comobject "ADODB.Connection"
>>> PoSH>$objConnection.Provider = "ADsDSOObject"
>>> PoSH>$objConnection.Open("Active Directory Provider")
>>> PoSH>$objCommand.ActiveConnection = $objConnection
>>> PoSH>
>>> PoSH>$query =
>>> "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
>>> PoSH>$objCommand.CommandText = $query
>>> PoSH>$qRes = $objCommand.Execute()
>>> PoSH>$qres
>>>
>>>
>>> Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
>>> IConvertType...}
>>> AbsolutePosition : 1
>>> ActiveConnection : ADODB.ConnectionClass
>>> BOF : False
>>> Bookmark : 0
>>> CacheSize : 1
>>> CursorType : adOpenStatic
>>> EOF : False
>>> Fields : {cn, adspath}
>>> LockType : adLockReadOnly
>>> MaxRecords : 0
>>> RecordCount : 21
>>> Source :
>>> <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
>>> AbsolutePage : 1
>>> EditMode : adEditNone
>>> Filter : 0
>>> PageCount : 3
>>> PageSize : 10
>>> Sort :
>>> Status : 0
>>> State : 1
>>> CursorLocation : adUseServer
>>> MarshalOptions : adMarshalAll
>>> DataSource : ADODB.RecordsetClass
>>> ActiveCommand : ADODB.CommandClass
>>> StayInSync : True
>>> DataMember :
>>> Index :
>>>
>>>
>>>
>>> PoSH>$qres.fields
>>>
>>>
>>> Status : 0
>>> ActualSize : 26
>>> Attributes : 32
>>> DataFormat :
>>> DefinedSize : 256
>>> Name : cn
>>> NumericScale : 255
>>> OriginalValue :
>>> Precision : 255
>>> Properties : {}
>>> Type : adVarWChar
>>> UnderlyingValue :
>>> Value : Administrator
>>>
>>> Status : 0
>>> ActualSize : 114
>>> Attributes : 32
>>> DataFormat :
>>> DefinedSize : 256
>>> Name : adspath
>>> NumericScale : 255
>>> OriginalValue :
>>> Precision : 255
>>> Properties : {}
>>> Type : adVarWChar
>>> UnderlyingValue :
>>> Value :
>>> LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
>>>
>>> Greetings /\/\o\/\/
>>> for more examples using .NET see :
>>>
>>> http://mow001.blogspot.com/2006/08/p...ry-part-8.html
>>>
>>> "Dean Wells [MVP]" wrote:
>>>
>>>> Thanks Chris ... appreciate it, I'll give that a go.
>>>>
>>>> And though helpful in this instance, it still leaves the bigger
>>>> question
>>>> re: ADO, any further input?
>>>>
>>>> --
>>>> Dean Wells [MVP / Directory Services]
>>>> MSEtechnology
>>>> [[ Please respond to the Newsgroup only regarding posts ]]
>>>> R e m o v e t h e m a s k t o s e n d e m a i l
>>>>
>>>> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
>>>> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
>>>> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
>>>> > <dwells@mask.msetechnology.com> wrote:
>>>> >
>>>> >> I've been trying to
>>>> >>execute a simple LDAP query against a backend AD, the goal of
>>>> >>which is
>>>> >>to simply iterate through the result set and do 'X' task with
>>>> >>each of
>>>> >>the objects.
>>>> >
>>>> > Try this:
>>>> >
>>>> > $Searcher=New-Object DirectoryServices.DirectorySearcher
>>>> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
>>>> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>>>> >
>>>> > Change the last line to pick out the attributes you're interested
>>>> > in
>>>> >
>>>> > hth
>>>> > Chris
>>>>
>>>>
>>>>

>>
>>

>
>



My System SpecsSystem Spec
Old 08-16-2006   #9 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: ADO & Powershell

I'm able to make this work reliably from a session on the server, using
alternate credentials, by doing this. Note that instead of tacking the
credentials onto the Provider, I modify the ConnectionString property after
setting the Provider.

$objConnection.Provider = "ADsDSOObject"
$objConnection.ConnectionString = $objConnection.ConnectionString + ";" +
"UserID=admin2;Password=!Pa55word"
$objConnection.Open("Active Directory Provider")



"Dean Wells [MVP]" <dwells@mask.msetechnology.com> wrote in message
news:OM$TR8UwGHA.1284@TK2MSFTNGP05.phx.gbl...
> Sadly no, the password is the literal I posted earlier - "password".
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
> "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
> news:%23hpHOOUwGHA.324@TK2MSFTNGP06.phx.gbl...
>> By any chance, does the password include any of the following characters:
>> `(backtick)
>> or one of
>> {$(
>> This is grabbing at straws. : |
>>
>>
>> "Dean Wells [MVP]" <dwells@mask.msetechnology.com> wrote in message
>> news:uL6LCtTwGHA.4868@TK2MSFTNGP02.phx.gbl...
>>> Heh, still doesn't work for me as is ... it seems supplying the creds.
>>> causes the failure -
>>>
>>> [FAILS]
>>> $objConnection.Provider =
>>> "ADsDSOObject;UserID=administrator;Password=password;"
>>>
>>> [SUCCEEDS]
>>> $objConnection.Provider = "ADsDSOObject"
>>>
>>> ... sadly, it doesn't entriely resolve the issue since I do on occasion
>>> need to provide the credentials.
>>>
>>> --
>>> Dean Wells [MVP / Directory Services]
>>> MSEtechnology
>>> [[ Please respond to the Newsgroup only regarding posts ]]
>>> R e m o v e t h e m a s k t o s e n d e m a i l
>>>
>>> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
>>> news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
>>>> This works for me :
>>>>
>>>> PoSH>$objCommand = New-object -comobject "ADODB.Command"
>>>> PoSH>$objConnection = New-object -comobject "ADODB.Connection"
>>>> PoSH>$objConnection.Provider = "ADsDSOObject"
>>>> PoSH>$objConnection.Open("Active Directory Provider")
>>>> PoSH>$objCommand.ActiveConnection = $objConnection
>>>> PoSH>
>>>> PoSH>$query =
>>>> "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
>>>> PoSH>$objCommand.CommandText = $query
>>>> PoSH>$qRes = $objCommand.Execute()
>>>> PoSH>$qres
>>>>
>>>>
>>>> Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
>>>> IConvertType...}
>>>> AbsolutePosition : 1
>>>> ActiveConnection : ADODB.ConnectionClass
>>>> BOF : False
>>>> Bookmark : 0
>>>> CacheSize : 1
>>>> CursorType : adOpenStatic
>>>> EOF : False
>>>> Fields : {cn, adspath}
>>>> LockType : adLockReadOnly
>>>> MaxRecords : 0
>>>> RecordCount : 21
>>>> Source :
>>>> <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
>>>> AbsolutePage : 1
>>>> EditMode : adEditNone
>>>> Filter : 0
>>>> PageCount : 3
>>>> PageSize : 10
>>>> Sort :
>>>> Status : 0
>>>> State : 1
>>>> CursorLocation : adUseServer
>>>> MarshalOptions : adMarshalAll
>>>> DataSource : ADODB.RecordsetClass
>>>> ActiveCommand : ADODB.CommandClass
>>>> StayInSync : True
>>>> DataMember :
>>>> Index :
>>>>
>>>>
>>>>
>>>> PoSH>$qres.fields
>>>>
>>>>
>>>> Status : 0
>>>> ActualSize : 26
>>>> Attributes : 32
>>>> DataFormat :
>>>> DefinedSize : 256
>>>> Name : cn
>>>> NumericScale : 255
>>>> OriginalValue :
>>>> Precision : 255
>>>> Properties : {}
>>>> Type : adVarWChar
>>>> UnderlyingValue :
>>>> Value : Administrator
>>>>
>>>> Status : 0
>>>> ActualSize : 114
>>>> Attributes : 32
>>>> DataFormat :
>>>> DefinedSize : 256
>>>> Name : adspath
>>>> NumericScale : 255
>>>> OriginalValue :
>>>> Precision : 255
>>>> Properties : {}
>>>> Type : adVarWChar
>>>> UnderlyingValue :
>>>> Value :
>>>> LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
>>>>
>>>> Greetings /\/\o\/\/
>>>> for more examples using .NET see :
>>>>
>>>> http://mow001.blogspot.com/2006/08/p...ry-part-8.html
>>>>
>>>> "Dean Wells [MVP]" wrote:
>>>>
>>>>> Thanks Chris ... appreciate it, I'll give that a go.
>>>>>
>>>>> And though helpful in this instance, it still leaves the bigger
>>>>> question
>>>>> re: ADO, any further input?
>>>>>
>>>>> --
>>>>> Dean Wells [MVP / Directory Services]
>>>>> MSEtechnology
>>>>> [[ Please respond to the Newsgroup only regarding posts ]]
>>>>> R e m o v e t h e m a s k t o s e n d e m a i l
>>>>>
>>>>> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
>>>>> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
>>>>> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
>>>>> > <dwells@mask.msetechnology.com> wrote:
>>>>> >
>>>>> >> I've been trying to
>>>>> >>execute a simple LDAP query against a backend AD, the goal of which
>>>>> >>is
>>>>> >>to simply iterate through the result set and do 'X' task with each
>>>>> >>of
>>>>> >>the objects.
>>>>> >
>>>>> > Try this:
>>>>> >
>>>>> > $Searcher=New-Object DirectoryServices.DirectorySearcher
>>>>> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
>>>>> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
>>>>> >
>>>>> > Change the last line to pick out the attributes you're interested in
>>>>> >
>>>>> > hth
>>>>> > Chris
>>>>>
>>>>>
>>>>>
>>>
>>>

>>
>>

>
>



My System SpecsSystem Spec
Old 08-17-2006   #10 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

Re: ADO & Powershell

$qres.fields.item('cn').name
cn
$qres.fields.item('cn').value
Administrator

gr /\/\o\/\/

"Brandon Shell" wrote:

> How do you access a specific Field Value.
>
> Example in VBS:
> rs.Fields("Name").Value
>
> In POSH:
> $rs.Fields("Name").Value
>
> POSH failes with Method Error
>
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:1573FDBD-E45B-4F87-B22B-8897F1A184F2@microsoft.com...
> > This works for me :
> >
> > PoSH>$objCommand = New-object -comobject "ADODB.Command"
> > PoSH>$objConnection = New-object -comobject "ADODB.Connection"
> > PoSH>$objConnection.Provider = "ADsDSOObject"
> > PoSH>$objConnection.Open("Active Directory Provider")
> > PoSH>$objCommand.ActiveConnection = $objConnection
> > PoSH>
> > PoSH>$query =
> > "<LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree"
> > PoSH>$objCommand.CommandText = $query
> > PoSH>$qRes = $objCommand.Execute()
> > PoSH>$qres
> >
> >
> > Properties : {IAccessor, IColumnsInfo, IColumnsInfo2,
> > IConvertType...}
> > AbsolutePosition : 1
> > ActiveConnection : ADODB.ConnectionClass
> > BOF : False
> > Bookmark : 0
> > CacheSize : 1
> > CursorType : adOpenStatic
> > EOF : False
> > Fields : {cn, adspath}
> > LockType : adLockReadOnly
> > MaxRecords : 0
> > RecordCount : 21
> > Source :
> > <LDAP://mowdc001/dc=mow,dc=local>;(objectcategory=user);cn,adspath;subtree
> > AbsolutePage : 1
> > EditMode : adEditNone
> > Filter : 0
> > PageCount : 3
> > PageSize : 10
> > Sort :
> > Status : 0
> > State : 1
> > CursorLocation : adUseServer
> > MarshalOptions : adMarshalAll
> > DataSource : ADODB.RecordsetClass
> > ActiveCommand : ADODB.CommandClass
> > StayInSync : True
> > DataMember :
> > Index :
> >
> >
> >
> > PoSH>$qres.fields
> >
> >
> > Status : 0
> > ActualSize : 26
> > Attributes : 32
> > DataFormat :
> > DefinedSize : 256
> > Name : cn
> > NumericScale : 255
> > OriginalValue :
> > Precision : 255
> > Properties : {}
> > Type : adVarWChar
> > UnderlyingValue :
> > Value : Administrator
> >
> > Status : 0
> > ActualSize : 114
> > Attributes : 32
> > DataFormat :
> > DefinedSize : 256
> > Name : adspath
> > NumericScale : 255
> > OriginalValue :
> > Precision : 255
> > Properties : {}
> > Type : adVarWChar
> > UnderlyingValue :
> > Value :
> > LDAP://mowdc001/CN=Administrator,CN=Users,DC=mow,DC=local
> >
> > Greetings /\/\o\/\/
> > for more examples using .NET see :
> >
> > http://mow001.blogspot.com/2006/08/p...ry-part-8.html
> >
> > "Dean Wells [MVP]" wrote:
> >
> >> Thanks Chris ... appreciate it, I'll give that a go.
> >>
> >> And though helpful in this instance, it still leaves the bigger question
> >> re: ADO, any further input?
> >>
> >> --
> >> Dean Wells [MVP / Directory Services]
> >> MSEtechnology
> >> [[ Please respond to the Newsgroup only regarding posts ]]
> >> R e m o v e t h e m a s k t o s e n d e m a i l
> >>
> >> "Chris Warwick" <news@remove.this.bit.nuney.com> wrote in message
> >> news:m074e2lu2l2lvtu3ggkml94m9m0s5p1dv4@4ax.com...
> >> > On Tue, 15 Aug 2006 14:59:06 -0400, "Dean Wells [MVP]"
> >> > <dwells@mask.msetechnology.com> wrote:
> >> >
> >> >> I've been trying to
> >> >>execute a simple LDAP query against a backend AD, the goal of which is
> >> >>to simply iterate through the result set and do 'X' task with each of
> >> >>the objects.
> >> >
> >> > Try this:
> >> >
> >> > $Searcher=New-Object DirectoryServices.DirectorySearcher
> >> > $Searcher.Filter="(objectcategory=user)" # LDAP of your choice
> >> > $Searcher.FindAll()|%{$_.GetDirectoryEntry().DistinguishedName}
> >> >
> >> > Change the last line to pick out the attributes you're interested in
> >> >
> >> > hth
> >> > Chris
> >>
> >>
> >>

>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Installing PowerShell dependent features on W2K8 with PowerShell CTP PowerShell
when run powershell script as windows service ,powershell fail PowerShell
Powershell Plus - Free for non commercial Use and Powershell Analyzer1.0 released PowerShell
Automatic PowerShell Error Parsing in PowerShell Analyzer and PowerShellPlus PowerShell
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46