|
| Powershell slow |
 |
Thu, 10 Apr 2008 01:53:00 -070 |
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
|
| Post Reply
|
| Re: Powershell slow |
 |
Thu, 10 Apr 2008 06:16:02 -070 |
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:
> Can you show me the code your using? Are you using a LDAP filter?
>
> "Swamy Channaveera"
<SwamyChannaveera@discussions.microsoft.com> wrote in
> message news:41A5C65E-985D-4620-B58D-BF2C06943146@microsoft.com...
> > 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
> >
> >
|
| Post Reply
|
| Re: Powershell slow |
 |
Thu, 10 Apr 2008 07:02:04 -070 |
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>&quo
t;)
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:
> Swamy Channaveera wrote:
> > 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
|
| Post Reply
|
| Re: Powershell slow |
 |
Thu, 10 Apr 2008 08:18:01 -070 |
The ADSI uses the user's complete LDAP path, but the input file has only
alias of the user !!!!!. with get-qaduser i can specify only the alias.
Regards,
"Karl Mitschke" wrote:
> Hello Swamy,
>
> > 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
>
>
|
| Post Reply
|
| Re: Powershell slow |
 |
Thu, 10 Apr 2008 08:36:02 -040 |
Can you show me the code your using? Are you using a LDAP filter?
"Swamy Channaveera" <SwamyChannaveera@discussions.microsoft.com>
wrote in
message news:41A5C65E-985D-4620-B58D-BF2C06943146@microsoft.com...
> 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
>
>
|
| Post Reply
|
|
|
|
|
|
|
|
|
|