vbscript - Variable values in For Each loop being retained -
i'm new vbscript , running trouble. script making api call , pulling account information, placing data csv
file. i'm pulling data array, looping through each account and, if properties qualify, assigning them variable written csv
. problem having if 1 account qualifies property, sets variable , if next account doesn't qualify, variable still retaining value, giving false results in csv
.
set sftpserver = wscript.createobject("sftpcominterface.ciserver") accounts = sftpserver.adminaccounts each admin in accounts adminname = admin.login dim count : count = admin.getpermissionscount() = 0 cint(count )- 1 set permission = admin.getpermission(i) ' adminpermissionspolicy: ' servermanagement = 0, ' sitemanagement = 1, ' stmanagement = 2, ' usercreation = 3, ' changepassword = 4, ' commanagement = 5, ' reportmanagement = 6, select case permission.permission case 0: serveradmin = "server admin" case 1: site = permission.sitename case 2: stman = "2" case 3: usercreate = "3" case 4: chpassword = "4" case 5: comman = "5" case 6: report = "6" end select next writestuff.writeline""+adminname+"|"+site+"|"+stman+"|"+usercreate+"|"+chpassword+"|"+comman+"|"+report+"") next
unfortunately variables in vbscript either @ global, or function scope.
so you'll need reset each of variables on each iteration of for
loop.
one way write dim dummy
@ top of script, , before select case
, write serveradmin = dummy
, site = dummy
etc.
it's practice dim
explicitly variables, , use option explicit
@ top of module enforce that.
Comments
Post a Comment