VB Script to Modify Folder NTFS Security and Share Permission

Below is the VBscript to Modify Folder NTFS Security and Share permission. It is using Cacls.exe and Rmtshare.exe to modify the permission. Cacls.exe can be used to modify Folder NTFS security Permission and  rmtshare.exe modifies Share Permission.  Below script removes all the existing permission NTFS Permission and Provides domain\accountname Full access and remove Inheritance check box and provide domain\accountname read share permission and remove all the other share permission. You can modify the script to suite your requirement

Set WshNetwork = WScript.CreateObject(“WScript.Network”)
strFolderName = Installerpath(WshNetwork.ComputerName)
Set objShell = CreateObject(“Wscript.Shell”)
intRunError = objShell.Run(“%COMSPEC% /c Echo Y| cacls ” & strFolderName & ” /c /g domain\accountname:F”, 2, True)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /remove”)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /grant “”domain\accountname””:read”)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /remove everyone”)

Function Installerpath(compname)
strPath = “\\” &  compname & “\Sharename”
strPath = Replace(strPath, “\\”, “”)
arrPath = Split(strPath, “\”)
strComputer = arrPath(0)
strShare = arrPath(1)
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery(“Select * From Win32_Share Where Name = ‘” & strShare & “‘”)

For Each objItem in colItems
strFolderName = objItem.Path
Next
Installerpath = strFolderName

End Function

Executing the script :

Save the file as .vbs and you can execute locally or user psexec.exe to execute script remotely. Below is the psexec command to run remotely.

Psexec.exe \\servername cscript C:\Securitymodify.vbs

You can find the copy of the code in the below link

http://powershell.com/cs/members/smtpport25.wordpress/files/ModifySecuritySharePermission.txt.aspx

Windows Password Change Notification Script

If your orginization has users who is working outside office network and they normally access email through pop3 then chances that they do not have any notification on password change. This script helps to intimate the give list of users to change the password.

Please find the copy of the script in the below link

http://powershell.com/cs/members/smtpport25.wordpress/files/PasswordChangeNotification.txt.aspx

 

VBscript to Pull out the Members of the local Adminstrators Group

Below VBscript helps to pull out Members of the Local Administrators Group from the given list of computer names. You need you have admin permission on the remote computer to pull out the membership details

 

Option Explicit

Dim objNetwork, objLocalGroup
Dim objTrans, strComputer, strNetBIOSDomain
Dim Result,k,v, Lusr,Dusr, Grp
Dim filesys
Dim filetxt,Servername

‘ Determine NetBIOS name of domain and local computer.
Set objNetwork = CreateObject(“Wscript.Network”)
strNetBIOSDomain = objNetwork.UserDomain
‘strComputer = objNetwork.ComputerName

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.OpenTextFile(“D:\scripts\LocalAdministrator\Servers.txt”,1)

do Until filetxt.AtEndOfStream
Servername = filetxt.Readline
Servername = trim(Servername)

strComputer = Servername
Set objNetwork = Nothing

‘ Bind to local Administrators group.
Set objLocalGroup = GetObject(“WinNT://” & strComputer  & “/Administrators,group”)

‘ Enumerate members of the local group.
result = strComputer
Lusr = “Local User :”
grp = “Domain Group :”
Dusr = “Domain USer : “

Call EnumLocalGroup(objLocalGroup,strComputer)

Loop

Sub EnumLocalGroup(ByVal objGroup,strComputer)
    ‘ Subroutine to enumerate members of local group.
    ‘ The variable strComputer has global scope.

    Dim objMember

    ‘ Enumerate direct members of group.
    For Each objMember In objGroup.Members

 If (LCase(objMember.Class) = “group”) Then
 K = objMember.AdsPath
 V = split(K,”/”)
 grp = grp & V(2) & “/” & v(3) & ” : ”
 Else
        K = objMember.AdsPath
 V = split(K,”/”)
 if Ubound(v) = 3 Then
 Dusr = Dusr  & V(2) & “/” & v(3) & ” : ”
 ElseIF Ubound(v) = 4 Then
 Lusr = Lusr & V(3) & “/” & v(4)  & ” : ”
 ‘wscript.echo objMember.AdsPath
 End If
 End If
    Next
 wscript.echo Ucase(strComputer) & “,” & Ucase(Lusr) &”,” & Ucase(Dusr) &”,” & Ucase(grp)
End Sub

 

Copy of the script can be found in the below mentioned Link

http://powershell.com/cs/members/smtpport25.wordpress/files/AdminMembers.txt.aspx

VBscript to Check Schema has been updated on Domain Controllers

To Introduce new Windows 2008 Additional domain controller we have to forest and domain. As part of the forest preparation we run the commaind adprep /Forestprep. Its recommended to run this command on the Schema Master Server

http://technet.microsoft.com/en-us/library/cc753437(WS.10).aspx

Below VBscript  will check on all the DCs for Schema update on the servername which are given in the file serverlist.  Script result will confirm if schema is updated successful or failed on the servers.

 

Dim objShell
set objShell = wscript.createObject(“wscript.shell”)

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt1 = filesys.OpenTextFile(“C:\serverlist.txt”,1)

do Until filetxt1.AtEndOfStream
 Servername = filetxt1.Readline
 servername = trim(Servername)
 iReturn = objShell.Run(“CMD /C psexec.exe \\” & servername & ” schupgr > log.txt”, , True)
 Set filesys = CreateObject(“Scripting.FileSystemObject”)
 set filetxt = filesys.OpenTextFile(“C:\log.txt”,1)
 K = 0
 str = “Current Schema Version is 44”
 do Until filetxt.AtEndOfStream
  LineVerify = filetxt.Readline
  LineVerify = trim(LineVerify)
  If InStr(UCase(LineVerify), Ucase(“Current Schema Version is 44”)) Then
   K = 1
  End If
 Loop

 if iReturn = 1 AND K = 1 Then

  wscript.echo servername & “: Success”
 Else
  wscript.echo servername &”: Failure”
 End If

loop

 

Find the copy of the script in the below link

http://powershell.com/cs/members/smtpport25.wordpress/files/psexec.txt.aspx

VBscript to copy file to the remote computers

Below is the VB script to copy a file from local computer to list of remote computers

On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile(“C:\server.txt”, ForReading)

Do Until objTextFile.AtEndOfStream
 strComputer = objTextFile.Readline
        objFSO.CopyFile “C:\regsetting.bat” , “\\” & strcomputer & “\C$\”
        wscript.echo strcomputer & ” Copied”
Loop

VBscript to check if SCOM agent is installed on a given list of servers

Below scripts takes input list of servers as input and generates the out with list of scom agent installed servers  and also get the details like start mode, current status etc

on error resume next
Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.OpenTextFile(“C:\scripts\Server.txt”,1)

do Until filetxt.AtEndOfStream
 name = filetxt.Readline
 strComputer = trim(name)

 Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
 Set colServices = objWMIService.ExecQuery (“Select * From Win32_Service”)

 For Each objService in colServices
 
  if objService.Name = “HealthService” Then
   wscript.echo  strcomputer & ” – ” & objService.Name & ” – ” & objService.State & ” – ” &objService.Startmode
  End If
       
 Next
loop

VBScript to find LDAP Path of the user

on Error resume Next

username = Inputbox(“Whats the username”)

 set objRoot = getobject(“LDAP://RootDSE“)
 domainname = objRoot.get(“defaultNamingContext”)
 wscript.echo  finduser(username,domainname)

 
Function FindUser(Byval UserName, Byval Domain)
 on error resume next

 set cn = createobject(“ADODB.Connection”)
 set cmd = createobject(“ADODB.Command”)
 set rs = createobject(“ADODB.Recordset”)

 cn.open “Provider=ADsDSOObject;”
 
 cmd.activeconnection=cn
 cmd.commandtext=”SELECT ADsPath FROM ‘LDAP://” & Domain & _
    “‘ WHERE sAMAccountName = ‘” & UserName & “‘”
 
 set rs = cmd.execute

 if err<>0 then
  FindUser=”Error connecting to Active Directory Database:” & err.description
 else
  if not rs.BOF and not rs.EOF then
        rs.MoveFirst
        FindUser = rs(0)
  else
   FindUser = “Not Found”
  end if
 end if
 cn.close
end function

VBscript to add multiple email addresses to a User Object

Below is the script to add multiple email address to a object. If you wanted to add 100’s of email address as alias address for some reason to a individual then below is the code to do the same.

Const ADS_PROPERTY_APPEND = 3
Set objUser = GetObject (“LDAP://path of the user“)

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.openTextfile(“c:\Names.txt”,1)
do until filetxt.AtEndofStream
 name = filetxt.readline
 name = trim(name)
 objUser.PutEx ADS_PROPERTY_APPEND, “proxyAddresses”, Array(“smtp:” & name)
 objUser.SetInfo

Loop

VB Script to Find the Uptime of the server on the given machines list in text file

on error resume next
Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt1 = filesys.OpenTextFile(“C:\scripts\Serveruptime\Serverlist.txt”,1)

do Until filetxt1.AtEndOfStream
strComputer = filetxt1.Readline
strComputer = trim(strComputer)
set objWMIDateTime = CreateObject(“WbemScripting.SWbemDateTime”)
set objWMI = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
set colOS = objWMI.InstancesOf(“Win32_OperatingSystem”)

for each objOS in colOS
if err.number = 0 Then
objWMIDateTime.Value = objOS.LastBootUpTime
Wscript.Echo strComputer & ” | ” & objWMIDateTime.GetVarDate
Else
Wscript.Echo strComputer & ” | ”
End If
next
Err.clear
Loop