Thursday 3 March 2011

WDS de tüm aygıtları listelemek.

WDS (Windows Deployment Server)de Approved, Pending ve Rejected device lari yonetim icin bir script hazirlamaya basladim, ilk asamada bu devicelari listelemek icin yazmis oldugum script i konuyla ilgilenen arkadaslara esin kaynagi olmasi icin paylasmak istedim. Script basitce wdsutil komutunu kullanarak devicelari text dosyasina aldiktan sonra, dosyalari parse edip daha kullanilabilir bir hale getirmek icin noktali virgul ile ayrilmis sekilde duzenliyor.
Screen_05 21-Jan-09 16.19

Ornegin,
wdsutil /get-AutoAddDevices /DeviceType:RejectedDevices sonucunu export ettigimizde asagidaki sekilde kullanimi daha zor olan bir formattaki ciktiyi

Screen_06 21-Jan-09 16.20

Bu sekle donusturerek kolaylik sagliyor.
Screen_07 21-Jan-09 16.20
 '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

No comments:

Post a Comment