basticn

WMIC Abfrage im Netzwerk erstellen via .VBS

Hallo Zusammen,

könnt Ihr mir bei einer Abfrage im Netzwerk helfen?

Ich möchte eine .VBS erstellen und eine Msg box erstellen die nach dem Hostname fragt und im Netzwerk sucht.

Bekomme es nicht mit der Msg Box hin face-sad

wmic /node:"hostname"  qfe list full  

den Hostname bekomme ich via:

Set wshShell = CreateObject( "WScript.Shell" )  
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )  
WScript.Echo "Computer Name: " & strComputerName  

angezeigt aber ich möchte den im Netzwerk suchen lassen, ich bin etwas Ratlos


Einen User im Netzwerk kann ich zurück setzten mit folgendem Script:


GLID = InputBox("User ID??", "GL-ID")  

If GLID = ""  Then  
		
		WScript.Quit
End If

Set searchKonto = FindAccount(GLID)



On Error Resume Next

Userexist = searchKonto.SamAccountName

If Err.number > 0 Then
	
	MsgBox "NOPE" & Userexist & " gibt es nicht, bitte nochmal GLID prüfen",16,"HEY AUFGEPASST =)"  
			
			WScript.Quit
End If
On Error Goto 0

'Function:			 FindAccount  
'Description:		Exits user at the AD  


Function FindAccount(ByVal strGLID)
	
	Container = "OU=Anwender,OU=DE"  
	
   Set RootDSE = GetObject("LDAP://RootDSE")  
	path = "LDAP://" & Container & "," & RootDSE.get("DefaultNamingContext")  

   sql = "SELECT ADsPath FROM '" & path &  "' WHERE objectClass='User' and name ='" & strGLID & "'"  

   Set objconn = CreateObject("ADODB.Connection")  
   Set objcomm = CreateObject("ADODB.Command")  
   objconn.Provider = "ADsDSOObject"  
   objconn.open "Active Directory Provider"  

   Set objcomm.ActiveConnection = objconn

   objcomm.CommandText = sql
   objcomm.Properties("Page Size")=50  
   objcomm.Properties("Searchscope") = 2  

   Set rs = objcomm.Execute

   If rs.eof Then
         Set FindAccount = Nothing
   Else
      Set FindAccount = GetObject(rs("ADsPath"))  
   End If
End Function


Public Function SearchDistinguishedName(ByVal GLID)
    ' Function:     SearchDistinguishedName  
    ' Description:  Searches the DistinguishedName for a given SamAccountName  
    ' Parameters:   ByVal GLID - The Global Link ID to search  
    ' Returns:      The DistinguishedName Name  
    Dim oRootDSE, oConnection, oCommand, oRecordSet 
    Set oRootDSE = GetObject("LDAP://rootDSE")  
    Set oConnection = CreateObject("ADODB.Connection")  
    oConnection.Open "Provider=ADsDSOObject;"  
    Set oCommand = CreateObject("ADODB.Command")  
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _  
	">;(&(objectCategory=User)(samAccountName="& GLID &"));distinguishedName;subtree"	  
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")  
    On Error Goto 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function

Result = SearchDistinguishedName(GLID)

Set objKonto = GetObject ("LDAP://" & Result & "")  
On Error Resume Next
objKonto.SetPassword "Urlaub24"  

If Err.number > 0 Then
	
	MsgBox " Die Global Link ID  " & Userexist & " konnte nicht zurückgesetzt werden",16,"ACHTUNG keine Berechtigung!"  
			
			WScript.Quit			
	End If
 On Error Goto 0

With objKonto
	
			.Put "userAccountControl", 512  
			.Put "pwdLastSet",0			  
			.SetInfo
	
End With

MsgBox " Das Paßwort der Global Link ID  " & Userexist & " wurde auf ""Urlaub24"" zurückgesetzt",,"ACHTUNG"  



Viele Dank im Vorraus für jeden Tipp.

lieben Gruß
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 448179

Url: https://administrator.de/forum/wmic-abfrage-im-netzwerk-erstellen-via-vbs-448179.html

Ausgedruckt am: 23.04.2025 um 22:04 Uhr

emeriks
emeriks 07.05.2019 um 08:32:26 Uhr
Goto Top
Hi,
kann es sein, dass Du mit "im Netzwerk suchen" eigentlich meinst "im Active Directory suchen"?

Falls ja, dann geht das genauso wie beim Benutzer. objectClass='computer' und die OU anpassen und gut. Oder statt in einer OU zu suchen besser in der ganzen Domäne. Die Computernamen müssen je Domäne eh eindeutig sein.

E.
BastiCn
BastiCn 07.05.2019 um 10:15:20 Uhr
Goto Top
Hi emeriks,

ja genau, meine in der AD.

Danke Dir, das versuche ich nachher mal! =)
BastiCn
BastiCn 07.05.2019 um 11:39:15 Uhr
Goto Top
Hallo emeriks,

habe jetzt folgende OU verwendet, wo die workstations eindeutig sind:

Container = "OU=DE-DE,OU=Workstations,OU=PRD"  

und den objectClass geändert:

sql = "SELECT ADsPath FROM '" & path &  "' WHERE objectClass='computer' and name ='" & strGLID & "'"  

Aber ich weiß nicht wie ich die Updates anzeigen lassen kann, wenn ich in der Msg Box den Hostname eintrage face-sad

HOST = InputBox("Hostname??", "PC Name")  

If HOST = ""  Then  
		
		WScript.Quit
End If

Set searchKonto = FindAccount(GLID)



On Error Resume Next

hostexist = searchKonto.SamAccountName

If Err.number > 0 Then
	
	MsgBox "NOPE" & hostexist & " gibt es nicht, bitte nochmal Host prüfen",16,"HEY AUFGEPASST =)"  
			
			WScript.Quit
End If
On Error Goto 0

'Function:			 FindAccount  
'Description:		Exits user at the AD  


Function FindAccount(ByVal strGLID)
	
	Container = "OU=DE-DE,OU=Workstations,OU=PRD"  
	
   Set RootDSE = GetObject("LDAP://RootDSE")  
	path = "LDAP://" & Container & "," & RootDSE.get("DefaultNamingContext")  

   sql = "SELECT ADsPath FROM '" & path &  "' WHERE objectClass='computer' and name ='" & strGLID & "'"  

   Set objconn = CreateObject("ADODB.Connection")  
   Set objcomm = CreateObject("ADODB.Command")  
   objconn.Provider = "ADsDSOObject"  
   objconn.open "Active Directory Provider"  

   Set objcomm.ActiveConnection = objconn

   objcomm.CommandText = sql
   objcomm.Properties("Page Size")=50  
   objcomm.Properties("Searchscope") = 2  

   Set rs = objcomm.Execute

   If rs.eof Then
         Set FindAccount = Nothing
   Else
      Set FindAccount = GetObject(rs("ADsPath"))  
   End If
End Function


Public Function SearchDistinguishedName(ByVal GLID)
    ' Function:     SearchDistinguishedName  
    ' Description:  Searches the DistinguishedName for a given SamAccountName  
    ' Parameters:   ByVal GLID - The Global Link ID to search  
    ' Returns:      The DistinguishedName Name  
    Dim oRootDSE, oConnection, oCommand, oRecordSet 
    Set oRootDSE = GetObject("LDAP://rootDSE")  
    Set oConnection = CreateObject("ADODB.Connection")  
    oConnection.Open "Provider=ADsDSOObject;"  
    Set oCommand = CreateObject("ADODB.Command")  
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _  
	">;(&(objectCategory=User)(samAccountName="& GLID &"));distinguishedName;subtree"	  
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")  
    On Error Goto 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function

wmic /node:"hostname"  qfe list full  

Thanks for your help in advance.

viele Grüße
BastiCn
BastiCn 07.05.2019 um 11:42:06 Uhr
Goto Top
Ich denke ich muss die Public Function wohl anpassen hänge aber irgendwie fest face-sad