troubleshooting Question

Won't Exit Loop : VBScript

Avatar of mmitchell57
mmitchell57 asked on
VB ScriptPowershell
8 Comments1 Solution888 ViewsLast Modified:
I'm having a serious brain fart. I can't figure out why, in the code below, that when it loops to the last line of the data it won't leave the loop and stop the script. I'm assuming I'm missing something relatively small and overthinking it. Everything else works great.

' This script is designed to query the domain
' see what computer accounts have not checked
' in for more then 90 days and deletes them.
' Created By: mmitchell57
' Date: today
'<!---- Variable Start ----!>
Dim objDSQuery1, strDSQuery1
Dim strLimit
Dim strLen 
Dim strDSRM
'<!---- Variable Start ----!>

'<!---- Initialize start -----!>
Set WshShell = CreateObject("WScript.Shell") 
strLimit = 2

'<!----- Initialize end ----!>

'<!---- Body Start ----!>
WshShell.Exec("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command DSQuery Computer 'OU=Agencies,OU=FORSCOM,OU=Installations,DC=nase,DC=ds,DC=army,DC=mil' -stalepwd 90 -limit " & strLimit & " >> '\\Server\Share\Folder\Folder\File.txt'") 
Set objDSQuery1 = WshShell.Exec("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command DSQuery Computer 'OU=Grouops,OU=Someplace,OU=,DC=domain,DC=controller,DC=com' -stalepwd 90 -limit " & strLimit) 

Do Until objDSQuery1.StdOut.AtEndOfStream 
    strDSQuery1 = objDSQuery1.StdOut.ReadLine()
    strLen = Len(strDSQuery1)
    'wscript.echo strlen
    strLen = strLen - 2
    strDSQuery1 = mid(strDSQuery1, 2, strLen)
    strDSRM = "dsrm '" & strDSQuery1 & "' -noprompt -c -q"
    wscript.echo strDSRM
    'WshShell.Exec("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command " & strDSRM) 

'<!---- Body End ----!>

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 8 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 8 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004