On Error Resume Next Dim oQuery Dim objConnection Dim objCommand Dim objRecordSet Dim strMember Dim strAC Dim arrMember ' logfile = "users-lvs.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") oQuery = "<LDAP://dc=my,dc=site>;" & _ "(objectCategory=user)" & _ ";distinguishedName,name,sAMAccountname,mail,memberOf,userAccountControl,description;subtree" ' Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Open "Provider=ADsDSOObject;" objCommand.ActiveConnection = objConnection objCommand.CommandText = oQuery Set objRecordSet = objCommand.Execute ' - , - if objFSO.FileExists(logfile) then Set objFile = objFSO.OpenTextFile(logfile, 2) objFile.Write "" else Set objFile = objFSO.CreateTextFile(logfile) objFile.Close Set objFile = objFSO.OpenTextFile(logfile, 2) objFile.Write "" end if objFile.Close ' , While Not objRecordSet.EOF strMember = objRecordSet.Fields("memberOf") strStr = "" For i = 0 To UBound(strMember) ' liluka = InStr(2, strMember(i), ",", vbTextCompare) ' strStr = strStr & Right(Left(strMember(i), liluka - 1), liluka - 4) & ", " Next arrOpis = objRecordSet.Fields("description") strOpis = "" For i = 0 To UBound(arrOpis) strOpis = strOpis & arrOpis(i) & ", " Next ' Select Case objRecordSet.Fields("userAccountControl") Case 512 strAC = "" Case 514 strAC = "" Case 66048 strAC = "" Case 66050 strAC = "" End Select ' Set objFile = objFSO.OpenTextFile(logfile, 8) objFile.WriteLine objRecordSet.Fields("sAMAccountname") & ";1" & _ objRecordSet.Fields("name") & ";2" & _ objRecordSet.Fields("mail") & ";3" & _ strStr & ";4" & strAC & ";5" & strOpis & ";6" objFile.Close objRecordSet.MoveNext Wend objConnection.Close
# , write-host open Sharepoint from USERS # sharepoint $env:SPpath = "${env:CommonProgramFiles}\Microsoft Shared\web server extensions\12\" [System.Reflection.Assembly]::LoadFrom("$env:SPPath\ISAPI\Microsoft.SharePoint.dll") write-host open web # web $nsite="http://my_site/sites/MonitorUser" $SpSite = New-Object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList $nsite; $spweb=$spsite.OpenWeb(); write-host open Sharepoint list # $nlist="http://my_site/sites/MonitorUser/Lists/List5/AllItems.aspx" $splist=$spweb.getlist($nlist); # write-host clearing list... $iCnt = $splist.Items.Count; #$icnt; for ($jj=1; $jj -le $iCnt; $jj++){ $splist.Items.Delete(0); } write-host clearing list Done # , write-host Processing log files... foreach ($file in $(get-childitem 'D:\scripts\work\' -include users*.txt -recurse)) { $hostout = $file.FullName + "..." Write-Host $hostout $fl = get-content $file.FullName; # $fl; for ($i=1; $i -lt $fl.Count; $i++) { $st1 =$fl[$i]; # $ind1 = $st1.IndexOf(";1") $ind2 = $st1.IndexOf(";2") $ind3 = $st1.IndexOf(";3") $ind4 = $st1.IndexOf(";4") $ind5 = $st1.IndexOf(";5") $ind6 = $st1.IndexOf(";6") $stLogin = $st1.substring(0,$ind1) $stUserName = $st1.substring($ind1+2,$ind2-$ind1-2) $stMail = $st1.substring($ind2+2,$ind3-$ind2-2) $ind7 = $ind4-$ind3 if ($ind7 -eq 2) { $stGroup = " " } else { $stGroup = $st1.substring($ind3+2,$ind4-$ind3-4) } $ind7 = $ind6-$ind5 if ($ind7 -eq 2) { $stOpis = "" } else { $stOpis = $st1.substring($ind5+2,$ind6-$ind5-4) } $stBlock = $st1.substring($ind4+2,$ind5-$ind4-2) $stSeg = $st1.substring($ind6+2,3) # $NewItem = $SpList.Items.Add(); $NewItem[""] = $stLogin; $NewItem[" "] = $stUserName; $NewItem["e-mail"] = $stMail; $NewItem[""] = $stGroup; $NewItem[""] = $stBlock; $NewItem[""] = $stSeg; $NewItem[""] = $stOpis; $NewItem.Update(); } } write-host Processing log files DONE $spweb.Dispose(); $spsite.Dispose(); write-host Program END
cscript users-lvs.vbs %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "& 'D:\scripts\work\users.ps1'" %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "& 'D:\scripts \work\pk.ps1'"
Source: https://habr.com/ru/post/158183/
All Articles