I am trying to write a script/web based console to manage WDS (Windows Deployment Server) Approved, Pending and Rejected devices more user friendly. And I'd like to share first part of it, actually it is just preparation phase, but I thought it may give ideas.
The script exports all devices to text files by using wdsutil then parse the text files to create more usable semi column seperated files. PS: It is my draft version.
Example
When we run wdsutil /get-AutoAddDevices /DeviceType:RejectedDevices command and export the result to a text file it produces the format below.
The script parses and re-writes the text file and make it more usable like below.
Script : ListWDSAll Devices.vbs
Author : Osman Shener
'ListWDSAllDevices.vbs Written by : Osman Shener
'Feel free to use! (Kill the hero, but don't eat his right :) (Don't try to undertand it is a funny translation of a Turkish proverb))
Const ForReading = 1
Const ForWriting = 2
Const TristateUseDefault=-2
Dim objFSO, arrStr, wshell, objRegEx
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshell = CreateObject("WScript.Shell")
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "\:"
wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:PendingDevices > C:\PendingDevices.txt", 0, TRUE
wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:RejectedDevices > C:\RejectedDevices.txt", 0, TRUE
wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:ApprovedDevices > C:\ApprovedDevices.txt", 0, TRUE
set wshell = nothing
'Create Pending Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\PendingDevices.txt", ForReading, True, TristateUseDefault)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strPenText = strPenText + strLine + ";"
If Left(strLine, 11) = "Join domain" Then
strPenText = strPenText & vbCrLf
End If
' Wscript.Echo strPenText
Next
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile ("C:\PendingDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strPenText)
objFile.Close
'Create Approved Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\ApprovedDevices.txt", ForReading, True, TristateUseDefault)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strAppText = strAppText + strLine + ";"
If Left(strLine, 13) = "Approval time" Then
strAppText = strAppText & vbCrLf
End If
' Wscript.Echo strAppText
Next
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile ("C:\ApprovedDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strAppText)
objFile.Close
'Create Rejected Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\RejectedDevices.txt", ForReading, True, TristateUseDefault)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strRejText = strRejText + strLine + ";"
If Left(strLine, 14) = "Rejection time" Then
strRejText = strRejText & vbCrLf
End If
Next
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile ("C:\RejectedDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strRejText)
objFile.Close