Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > PowerShell

Powershell slow

Reply
 
Thread Tools Display Modes
Old 04-10-2008   #1
Swamy Channaveera
Guest
 
Posts: n/a

Powershell slow

Hi,

I'm using get-qaduser to get some of the attributes from AD. The script
reads a text filee and extracts some of the attributes and writes to the csv
files. The execution takes a long time. I'm querying for only 35 users max it
takes around 45sec to 1 min to get the info and write it to csv file. Where
as a VBScript hardly takes 10 sec!!!!

I have another script which checks wheter the Homemdb attribute exists and
writes some of the attributes to the csv files. The execution takes a long
time about 1 hours for 17,000 users.

I'm running the script on XP mahcine with 512 MB ram. Any suggestion to
improve the execution would be appriciated.

Regards,
Swamy


  Reply With Quote

Old 04-10-2008   #2
Brandon Shell [MVP]
Guest
 
Posts: n/a

Re: Powershell slow

Can you show me the code your using? Are you using a LDAP filter?

"Swamy Channaveera" <SwamyChannaveera@xxxxxx> wrote in
message news:41A5C65E-985D-4620-B58D-BF2C06943146@xxxxxx
Quote:

> Hi,
>
> I'm using get-qaduser to get some of the attributes from AD. The script
> reads a text filee and extracts some of the attributes and writes to the
> csv
> files. The execution takes a long time. I'm querying for only 35 users max
> it
> takes around 45sec to 1 min to get the info and write it to csv file.
> Where
> as a VBScript hardly takes 10 sec!!!!
>
> I have another script which checks wheter the Homemdb attribute exists and
> writes some of the attributes to the csv files. The execution takes a long
> time about 1 hours for 17,000 users.
>
> I'm running the script on XP mahcine with 512 MB ram. Any suggestion to
> improve the execution would be appriciated.
>
> Regards,
> Swamy
>
>
  Reply With Quote
Old 04-10-2008   #3
Swamy Channaveera
Guest
 
Posts: n/a

Re: Powershell slow

The script is as follows

get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
select-object displayname, altrecipient | convertto-html list.htm

Regards,



"Brandon Shell [MVP]" wrote:
Quote:

> Can you show me the code your using? Are you using a LDAP filter?
>
> "Swamy Channaveera" <SwamyChannaveera@xxxxxx> wrote in
> message news:41A5C65E-985D-4620-B58D-BF2C06943146@xxxxxx
Quote:

> > Hi,
> >
> > I'm using get-qaduser to get some of the attributes from AD. The script
> > reads a text filee and extracts some of the attributes and writes to the
> > csv
> > files. The execution takes a long time. I'm querying for only 35 users max
> > it
> > takes around 45sec to 1 min to get the info and write it to csv file.
> > Where
> > as a VBScript hardly takes 10 sec!!!!
> >
> > I have another script which checks wheter the Homemdb attribute exists and
> > writes some of the attributes to the csv files. The execution takes a long
> > time about 1 hours for 17,000 users.
> >
> > I'm running the script on XP mahcine with 512 MB ram. Any suggestion to
> > improve the execution would be appriciated.
> >
> > Regards,
> > Swamy
> >
> >
>
  Reply With Quote
Old 04-10-2008   #4
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Powershell slow

Swamy Channaveera wrote:
Quote:

> The script is as follows
>
> get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
> select-object displayname, altrecipient | convertto-html list.htm
And how about the VBScript version also. Maybe there's something we can
pass along to MS on this for them to look into...

Marco


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
  Reply With Quote
Old 04-10-2008   #5
Swamy Channaveera
Guest
 
Posts: n/a

Re: Powershell slow

Following is the VBScript that produces the exact result as that of Powershell.

'On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1

mbcount=0
SWcount=0
errcount=0

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

FilePath = "Migration.html"
Set objArgs = WScript.Arguments


Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\sam.txt", ForReading)

Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile(filepath,2,true)


i = 0
Do While objTextFile.AtEndOfStream <> True
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
mbcount = mbcount +1
Loop

wfile.writeline("<html>")
wfile.writeline("<head>")
wfile.writeline("<meta http-equiv='Content-Type' content='text/html;
charset=iso-8859-1'>")
wfile.writeline("<title> MIGRATION SWITCH STATUS Report</title>")
wfile.writeline("<style>")
wfile.writeline("<!--")
wfile.writeline("body, td {font-family:tahoma;font-size:11px;border:
border-width:1px; border-style:solid ; color #CCCCCC;}")
wfile.writeline("table{border: thin solid #000000;}")
wfile.writeline("-->")
wfile.writeline("</style>")

wfile.writeline("<meta http-equiv='Refresh' content = '10; '>")

wfile.writeline("<table width='60%' align='center' cellpadding='3'
cellspacing='3' '>")

wfile.writeline("<tr bgcolor='#CCCCCC'>")
wfile.writeline("<td colspan='3' height='45' align='center'>")
wfile.writeline("<font face='tahoma' color='#003399' size='2'><strong>
Mailbox Migration Switch Status Report</strong></font>")
wfile.writeline("</td>")
wfile.writeline("</tr>")
wfile.writeline("</table>")
wfile.writeline("<tr>")
wfile.writeline("<td colspan=5> </td>")
wfile.writeline("</tr>")



wfile.writeline("<table border='1' width='60%' align='center'
cellpadding='3' cellspacing='2' style='border-top: 1px solid #CCCCCC;
border-left: 1px solid #CCCCCC; border-right: 1px solid
#CCCCCC;border-bottom: 1px solid #CCCCCC;'>")


wfile.writeline("<tr align='center'>")
wfile.writeline("<td bgcolor='#CCCCCC' align='left' valign='top'
style='border-bottom: 1px solid #CCCCCC;' width='33%'><div
align='center'><strong>UserID</strong></div></td>")
wfile.writeline("<td bgcolor='#CCCCCC' align='left' valign='top'
style='border-bottom: 1px solid #CCCCCC;' width='33%'><div
align='center'><strong>Display Name</strong></div></td>")
wfile.writeline("<td bgcolor='#CCCCCC' align='left' valign='top'
style='border-bottom: 1px solid #CCCCCC;' width='34%'><div
align='center'><strong>Switched (Yes/No)</strong></div></td>")
wfile.writeline("</tr>")


For Each objItem in objDictionary
objCommand.CommandText = "SELECT samAccountName,altrecipient,displayname
FROM " & _
"'LDAP://dc=UD1,dc=UTILITY' " & _
"WHERE samAccountName = '" & objDictionary.Item(objItem) & "'"
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute

'Wscript.Echo objRecordSet.Fields("distinguishedname").Value


If objRecordSet.RecordCount = 0 Then
Wscript.Echo objDictionary.Item(objItem) & " NOT found"

errcount = errcount+1

Else
objRecordSet.MoveFirst

Do Until objRecordSet.EOF

wfile.writeline("<tr>")
wfile.writeline("<td>" &
objRecordSet.Fields("samaccountname").Value & "</td>")
wfile.writeline("<td>" &
objRecordSet.Fields("displayname").Value & "</td>")

if left(objRecordSet.Fields("altrecipient").Value,8) = "CN=Quest" then
' Wscript.Echo objRecordSet.Fields("displayname").Value & " is not
migrated "
wfile.writeline("<td align='Center'>No</td>")


else
' Wscript.Echo objRecordSet.Fields("displayname").Value & " is migrated "
wfile.writeline("<td align='Center'>Yes</td>")
swcount = swcount+1

end if
' Wscript.Echo objRecordSet.Fields("displayname").Value &
objRecordSet.Fields("altrecipient").Value & " is migrated "
objRecordSet.MoveNext
Loop


End If

Next

wfile.writeline("<tr></tr>")
wfile.writeline("<table border='1' width='60%' align='center'
cellpadding='3' cellspacing='0' style='border-top: 1px #CCCCCC; border-left:
1px solid #CCCCCC; border-right: 1px solid #CCCCCC;border-bottom: 1px solid
#CCCCCC;'>")
wfile.writeline("<tr>")
wfile.writeline("<td width='33%' align='left'>Last Updated: " & now() &
"</td>")
wfile.writeline("<td width='67%' align='left'>Total number of mailboxes : "
& mbcount & " | Switched : " & SWcount & " | Pending : " &
mbcount-errcount-swcount & " | Error : " & errcount & "</td>")

wfile.writeline("</tr>")

wfile.writeline("</table><p>")

' wfile.writeline("<td width='34%' align='left'> Switched : " & SWcount & "
/ Pending : " & mbcount-errcount-swcount & " / Error : " & errcount & "</td>")




objtextfile.close
mbcount=0
SWcount=0





"Marco Shaw [MVP]" wrote:
Quote:

> Swamy Channaveera wrote:
Quote:

> > The script is as follows
> >
> > get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
> > select-object displayname, altrecipient | convertto-html list.htm
>
> And how about the VBScript version also. Maybe there's something we can
> pass along to MS on this for them to look into...
>
> Marco
>
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
>
  Reply With Quote
Old 04-10-2008   #6
Karl Mitschke
Guest
 
Posts: n/a

Re: Powershell slow

Hello Swamy,
Quote:

> The script is as follows
>
> get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
> select-object displayname, altrecipient | convertto-html list.htm
>
> Regards,
>
Swamy;

Try this and see if is any faster. If it is we can work on getting the data
out the way you want:

get-content user.txt | foreach {[ADSI]"LDAP://$_"} | sort altrecipient |
select-object displayname, altrecipient


  Reply With Quote
Old 04-10-2008   #7
Swamy Channaveera
Guest
 
Posts: n/a

Re: Powershell slow

Hi,

I tryed the following command

get-content user.txt | foreach {[ADSI]"WinNT://UD1/$_"}

where UD1 is the netbios name of the domain. The output is blank with the
error message

distinguishedName
--------------------



out-lineoutput : exception retrieving member "Classidd2e4...... ": unknown
error (0x80005000)"

Regards,



"Karl Mitschke" wrote:
Quote:

> Hello Swamy,
>
Quote:

> > The script is as follows
> >
> > get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
> > select-object displayname, altrecipient | convertto-html list.htm
> >
> > Regards,
> >
>
> Swamy;
>
> Try this and see if is any faster. If it is we can work on getting the data
> out the way you want:
>
> get-content user.txt | foreach {[ADSI]"LDAP://$_"} | sort altrecipient |
> select-object displayname, altrecipient
>
>
>
  Reply With Quote
Old 04-10-2008   #8
Oisin (x0n) Grehan [MVP]
Guest
 
Posts: n/a

Re: Powershell slow

On Apr 10, 9:16*am, Swamy Channaveera
<SwamyChannave...@xxxxxx> wrote:
Quote:

> The script is as follows
>
> get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
> select-object displayname, altrecipient | convertto-html list.htm
>
> Regards,
>
>
>
> "Brandon Shell [MVP]" wrote:
Quote:

> > Can you show me the code your using? Are you using a LDAP filter?
>
Quote:

> > "Swamy Channaveera" <SwamyChannave...@xxxxxx> wrote in
> > messagenews:41A5C65E-985D-4620-B58D-BF2C06943146@xxxxxx
Quote:

> > > Hi,
>
Quote:
Quote:

> > > *I'm using get-qaduser to get some of the attributes from AD. The script
> > > reads a text filee and extracts some of the attributes and writes to the
> > > csv
> > > files. The execution takes a long time. I'm querying for only 35 usersmax
> > > it
> > > takes around 45sec to 1 min to get the info and write it to csv file.
> > > Where
> > > as a VBScript hardly takes 10 sec!!!!
>
Quote:
Quote:

> > > I have another script which checks wheter the Homemdb attribute existsand
> > > writes some of the attributes to the csv files. The execution takes a long
> > > time *about 1 hours for 17,000 users.
>
Quote:
Quote:

> > > I'm running the script on XP mahcine with 512 MB ram. Any suggestion to
> > > improve the execution would be appriciated.
>
Quote:
Quote:

> > > Regards,
> > > Swamy- Hide quoted text -
>
> - Show quoted text -

Maybe this is just a transcription typo on your part, but isn't there
something more fundamentally wrong with this line?
Quote:

> get-content user.txt | foreach { get-qaduser $-} | sort altrecipient |
The current pipeline variable should be '$_' ( dollar, underscore ),
not a '$-' (dollar, minus).

- Oisin
  Reply With Quote
Old 04-10-2008   #9