更新されたコード: スクリプトは実行されますが、何も出力されず、Excel.exe プロセスが引き続き実行されます。.vbs スクリプトが起動されたディレクトリに出力し、Excel ファイルに Book1.xls 以外の名前を付けるには、これが必要です。
Option Explicit
Dim strFile, strGroupDN, objGroup, objExcel, intRow, objMember, objSheet
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain, strGroup
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
strNetBIOSDomain = Left(strNetBIOSDomain, _
Len(strNetBIOSDomain) - 1)
strGroup = InputBox("Enter AD group name")
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strGroup
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Group " & strGroup & " not found"
Wscript.Quit
End If
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
Set objGroup = GetObject("LDAP://" & strGroupDN)
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Columns(1).ColumnWidth = 100
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "AD Group Members"
intRow = 1
For Each objMember In objGroup.Members
objSheet.Cells(intRow, 1).Value = objMember.sAMAccountName
intRow = intRow + 1
Next
Set fso = CreateObject("Scripting.FileSystemObject")
cwd = fso.GetAbsolutePathName("*.*")
filename = fso.BuildPath(cwd, "output.xls")
objExcel.ActiveWorkbook.SaveAs filename