SMS2003&SCCM2007: списки локальных администраторов
Перенос моей статьи, для истории, из ЖЖ (livejournal.com)
Собсно мелкий скриптик, возможно кому-то тоже будет полезен, для получения списка локальных администраторов ввиде .MIF файла располагающегося сразу в нужном для System Management Server 2003 месте. Дабы они появились в инвентаризации.
Работает на windows 2000/2003/XP/Vista различных локализаций (локалонезависимая). Не тестировал на 2008м сервере.
--------------------localadm.vbs------------------------
On Error Resume Next
Dim CurKey
Dim Value
Dim Arr
Set myfso = CreateObject("Scripting.FileSystemObject")
CurKey = 0
strComputer = GetComputerName()
TimeStamp = CurrentTimestamp()</p>
Set MIFFile = myfso.OpenTextFile(SMSAgentPath() & "\LocalAdm.mif", 2, True)
MIFFile.Write "Start Component" & VbCrLf
MIFFile.Write "NAME = " + Chr(34) + "WORKSTATION" + Chr(34) & VbCrLf
Set colGroups = GetObject("WinNT://" & strComputer & "/" & GetLocalAdminGroupName(strComputer))
For Each objUser In colGroups.Members
CurKey = CurKey + 1
MIFFile.Write " Start Group" & VbCrLf
MIFFile.Write " NAME = " + Chr(34) + "Windows Local Administrators" + Chr(34) & VbCrLf
MIFFile.Write " ID = " + CStr(CurKey) + VbCrLf
MIFFile.Write " CLASS = " + Chr(34) + "WindowsLocalAdministrators" + Chr(34) & VbCrLf
MIFFile.Write " KEY = 1" & VbCrLf
MIFFile.Write " Start Attribute" & VbCrLf
MIFFile.Write " NAME = " + Chr(34) + "User(Group)" + Chr(34) & VbCrLf
MIFFile.Write " ID = 1" & VbCrLf
MIFFile.Write " TYPE = STRING(128)" & VbCrLf
Arr = Split(objUser.AdsPath, "/", -1, 1)
if InStr(1, objUser.AdsPath, "/" & strComputer & "/", 1) > 0 Then
Value = Arr(4)
Else
Select Case UBound(Arr)
Case 2 Value = Arr(2)
Case 3 Value = Arr(2) & "/" & Arr(3)
End Select
End If
MIFFile.Write " VALUE = " + Chr(34) + Value + Chr(34) & VbCrLf
MIFFile.Write " End Attribute" & VbCrLf
MIFFile.Write " Start Attribute" & VbCrLf
MIFFile.Write " NAME = " + Chr(34) + "Date" + Chr(34) & VbCrLf
MIFFile.Write " ID = 2" & VbCrLf
MIFFile.Write " TYPE = STRING(128)" & VbCrLf
MIFFile.Write " VALUE = " + Chr(34) + TimeStamp + Chr(34) & VbCrLf
MIFFile.Write " End Attribute" & VbCrLf
MIFFile.Write " End Group" & VbCrLf
Next
MIFFile.Write "End Component" & VbCrLf
MIFFile.Close
Function GetComputerName()
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colItems
GetComputerName=objItem.Name
Next
End Function
Function SMSAgentPath()
Set oWshShell = CreateObject("WScript.Shell")
On Error resume next
SMSAgentPath = oWshShell.RegRead("HKLM\SOFTWARE\Microsoft\SMS\Client\Configuration\Client Properties\NOIDMIF Directory")
If Err.Number <> 0 Then
SMSAgentPath = ""
End if
Set oWshShell = Nothing
End Function
Function CurrentTimestamp()
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
dtmLocalTime = objItem.LocalDateTime
dtmMonth = Mid(dtmLocalTime, 5, 2)
dtmDay = Mid(dtmLocalTime, 7, 2)
dtmYear = Left(dtmLocalTime, 4)
dtmHour = Mid(dtmLocalTime, 9, 2)
dtmMinutes = Mid(dtmLocalTime, 11, 2)
dtmSeconds = Mid(dtmLocalTime, 13, 2)
Next
CurrentTimeStamp = dtmMonth & "." & dtmDay & "." & dtmYear & " " & dtmHour & ":" & dtmMinutes & ":" & dtmSeconds
End Function
Function GetLocalAdminGroupName(strComputer)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAccounts = objWMIService.ExecQuery ("Select * From Win32_Group Where Domain = '" & strComputer & "' AND SID = 'S-1-5-32-544'")
For Each objAccount in colAccounts
GetLocalAdminGroupName=objAccount.Name
Next
End Function
--------------------localadm.vbs------------------------
There are no published comments.
New comment