Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Friday, June 3, 2011

VB script to view system serial number

Copy the below code and save it as filename.vbs extension. then execute it




ComputerName = InputBox("Enter the name of the computer you wish to query")
 
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
 
'WScript.Echo winmgmt1
 
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
 
for each SN in SNSet
        MsgBox "The serial number for the specified computer is: " & SN.SerialNumber
Next

Thursday, April 14, 2011

VB script to create OU in active directory


                A Simple vb script to create a OU ( Organizational unit ) in the Active directory. Please find the below script, edit the script as your needs. I will explain in both picture and video. Please tell your comments.

Set objDomain = GetObject("LDAP://DC=test, DC=com")
Set objOU = objDomain.Create("organizationalUnit", "OU=North_Bay")
objOU.SetInfo


Thursday, March 3, 2011

VB Script to unlock user accounts - Active directory


The below VB script code can unlock the user accounts in active directory .Copy the below code and paste to notepad and save it as .vbs extension.


UserName = InputBox("Enter the user's login name that you want to unlock:")


DomainName = InputBox("Enter the domain name in which the user account exists:")


Set UserObj = GetObject("WinNT://"& DomainName &"/"& UserName &"")
If UserObj.IsAccountLocked = -1 then UserObj.IsAccountLocked = 0
UserObj.SetInfo


If err.number = 0 Then
    Wscript.Echo "The Account Unlock Failed.  Check that the account is, in fact, locked-out."
Else
    Wscript.Echo "The Account Unlock was Successful"
End if





Script to view disk free space


The below simple VB Script to show the free disk space in the local computer, copy the below code and paste to notepad and save it as .vbs extension.

Const HDD = 3
 strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HDD & "")
 For Each objDisk in colDisks
    Wscript.Echo "Drive: "& vbTab &  objDisk.DeviceID & vbTab & objDisk.FreeSpace      
   Next

Monday, February 28, 2011

Script to copy a folder

Scripting language is very handy tool for system admins, if u learned the scripting. we can finish the work as fast.

Today , here i would like to write a script about how to copy a folder. Copy the below code to notepad and save it as .vbs extension. And edit the source and destination in the script.
__________________________________________________________________________________

sFolder = "c:\testfolder"
dFolder = "\\remoteservername\sharename"
Set objFSO = CreateObject ("scripting.fileSystemObject")
objFSO.CopyFolder sFolder, dFolder

__________________________________________________________________________________


For more info, i have created a video how to do that.




Thursday, February 24, 2011

Script to create a folder


A simple VB script can create a folder on a system. Folder creation is very simple all are known, but why I write this script, because if we want create a folder on all system, we can use this on logon script through group policy.
1)     Open your notepad, copy the below code.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("c:\Serveradmin") 
 msgbox  “Successful created”
  And save as .vbs extension and execute it, now you check the “C” drive, the folder is created. For details check the below video.

Monday, January 24, 2011

List all member of a group in AD


Simple VB script to display members of a group.


Copy the below code and edit as ur requirement and save it as extension .vbs

On Error Resume Next

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
    WScript.echo strMember
Next



Get Last logon of user in AD


Simple powershell script to display last logon of all users.



$searcher = New-Object DirectoryServices.DirectorySearcher([adsi]"")
$searcher.filter = "(objectclass=user)"
$users = $searcher.findall()

Foreach($user in $users)
{
 if($user.properties.item("lastLogon") -ne 0)
  {
   $a = [datetime]::FromFileTime([int64]::Parse($user.properties.item("lastLogon")))
   "$($user.properties.item(`"name`")) $a"
  }
}

Script to search for all domain controller in a domain

Simple powershell script to get all domain controller details in domain.


PowerShell
$objDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()  
$objDomain.FindAllDomainControllers() | Select-Object Name 
Web Hosting