There are two ways to go about this. It seems like you are attempting to filter or exclude some of the results of your WMI query by looping over them and passing through a bunch of conditionals. This is what it should look like.
On Error Resume Next
WScript.Echo Day(Now) & "/" & Month(Now) & "/" & Year(Now)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("D:\users.txt", True)
For Each objItem in colItems
If objItem.Name = "Administrator" Then Continue
If objItem.Name = "Guest" Then Continue
If objItem.Name = "Admin" Then Continue
If objItem.PasswordChangeable = "False" Then Continue
'WScript.Echo "Name: " & objItem.Name
objFile.WriteLine(objItem.Name)
objFile.WriteLine(objItem.PasswordChangeable)
Next
objFile.Close
Set objFSO = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
However, you're doing a lot of extra work here. If you really want to grab an entire WMI class, you should really skip the ExecQuery and just grab the entire class from the start. That would look something like this.
On Error Resume Next
WScript.Echo Day(Now) & "/" & Month(Now) & "/" & Year(Now)
strComputer = "."
Set colUsers = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_UserAccount")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("D:\users.txt", True)
For Each objUser in colUsers
If objUser.Name = "Administrator" Then Continue
If objUser.Name = "Guest" Then Continue
If objUser.Name = "Admin" Then Continue
If objUser.PasswordChangeable = "False" Then Continue
'WScript.Echo "Name: " & objUser.Name
objFile.WriteLine(objUser.Name)
objFile.WriteLine(objItem.PasswordChangeable)
Next
objFile.Close
Set objFSO = Nothing
Set colUsers = Nothing
Set objWMIService = Nothing
As you can see, you're saving some keystrokes and maybe a few CPU cycles, but you're still making WMI give you the entire class full of data you don't want. This is where the query really comes into play. You should use the query to limit the result set to only the information that you are looking for.
On Error Resume Next
WScript.Echo Day(Now) & "/" & Month(Now) & "/" & Year(Now)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_UserAccount " &_
"Where LocalAccount = True " &_
"And PasswordChangeable = True " &_
"And Name <> 'Administrator' " &_
"And Name <> 'Guest' " &_
"And Name <> 'Admin'")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("D:\users.txt", True)
For Each objItem in colItems
'WScript.Echo "Name: " & objItem.Name
objFile.WriteLine(objItem.Name)
objFile.WriteLine(objItem.PasswordChangeable)
Next
objFile.Close
Set objFSO = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
This is a much better approach and you're letting WMI handle the heavy lifting instead of the script interpreter. Also, you should be taking advantage of the File object's WriteLine
method. It handles line endings for you.