Automate Windows Administration - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Automate Windows Administration

Description:

Logon Scripts Common Tasks. Inform/Ask User about ... WScript.Shell. WScript.Network ... http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx ... – PowerPoint PPT presentation

Number of Views:104
Avg rating:3.0/5.0
Slides: 37
Provided by: mutuallyb
Category:

less

Transcript and Presenter's Notes

Title: Automate Windows Administration


1
Automate Windows Administration
  • David Lundell, MBA
  • MCITP Database Administrator, Database
    Developer, MCDBA MCT MCSE MCSD
  • Mutually Beneficial Inc
  • David_at_MutuallyBeneficial.com
  • www.MutuallyBeneficial.com

For updated slides go to www.mutuallybeneficial.co
m/index_files/articles.htm
2
Why Automate
  • Automate administration
  • Free up your time for serious work
  • Make your job fun
  • Make time for training
  • Make time for being proactive

3
Keys to Automating Windows
  • Know a scripting language
  • VBScript
  • Jscript
  • Perl
  • Know ADSI
  • Understand logon scripts
  • Know your Script environment
  • Understand WMI
  • Understand the best command line tools

4
VBScript
  • Simplified Version of Visual Basic
  • Has the most scripting examples
  • Often the easiest for non-programmers to
    assimilate

Dim oOU Set oDom GetObject("LDAP//dcmbi,dcco
m") Set oOU oDom.Create("organizationalUnit",
"oulopsa") oOU.Description League of
Professional System Administrators oOU.SetInfo
5
JScript
  • Also provided with Windows Script Host
  • Similar to C and Java
  • More powerful but more difficult
  • var oDom GetObject("LDAP//dcmbi,dccom")
  • var oOU oDom.Create("organizationalUnit",
    "oulopsa")
  • oOU.Description "League of Professional System
    Administrators"
  • oOU.SetInfo()

6
Perl
  • Must download from ActiveState
  • use strict
  • use Win32OLE('in')
  • use Win32OLEVariant support for OLE data
    types
  • use Win32OLEConst ('Active DS') Load ADSI
    Constants
  • my objDom Win32OLE-gtGetObject("LDAP//dcm
    bi,dccom")
  • my objOU objDom-gtCreate("organizationalUnit
    ","oulopsa")
  • objOU-gtDescription "League of
    Professional System Administrators"
  • objOU-gtSetInfo()

7
ADSI and VBScript -- Create an OU explained
  • Dim oOU in VBscript dimension variables is not
    required
  • Serverless Binding to ADSI it uses DNS to
    find a DC
  • Set oDom GetObject("LDAP//dcmutuallybeneficial
    ,dccom")
  • Create the OU
  • Set oOU oDom.Create("organizationalUnit",
    "oulopsa")
  • Set some attributes
  • oOU.Put Description, League of Professional
    System Administrators
  • Until SetInfo is called changes are in local
    cache only
  • oOU.SetInfo

8
ADSI
  • Simplified Interface for accessing LDAP
    (including AD), NT, NDS
  • Binding
  • Server
  • Server less
  • Root DSE
  • Easy way to create new objects
  • Remember to SetInfo after making changes

9
Lopsa OU created
10
Create a User
  • Dim oOu, oUsr
  • Set oOU _ GetObject("LDAP//OUlopsa,dcmbi,dcc
    om")
  • We bind to the object we need and then call a
    method
  • Set oUsr oOU.Create("User", cn
    SysAdofTheYear")
  • oUsr.Put Description, Sys Admin of the Year
  • oUsr.Put "sAMAccountName", "SysAdminOTY
  • oUsr.SetInfo

11
Microsoft Identity Integration Server
  • Identity Management/MetaDirectory solution
  • Integrate identities from AD, LDAP, Novell, IBM,
    Sun
  • Provision Accounts based on HR Database
  • Deprovision Accounts based on Status from HR
  • Allows attributes, such as phone to be updated
    in one place and flowed to the others

12
Logon Scripts
  • Assigned through AD Users and Computers
  • OR through Group Policy
  • Logon and Logoff scripts
  • Startup and Shutdown
  • Batch File can call script file

13
Setting Logon Scripts
14
Logon Scripts Common Tasks
  • Inform/Ask User about upcoming installations
  • WScript.Echo WScript.Shell.Popup or MsgBox
  • Map Drives
  • WScript.Network.MapNetworkDrive
  • Map Printers
  • WScript.Network.AddWindowsPrinterConnection
  • Creating Shortcuts
  • WScript.Shell.CreateShortcut
  • Running other utilities
  • WScript.Shell.Run

15
Logon scripts without scripting (batch files)
  • _at_net use U /del
  • _at_net use P /del
  • net use U \\SERVER1\users
  • net use P \\SERVER1\public
  • net time \\MY_PDC /set /yes
  • copy \\MY_PDC\netlogon\notepad.exe.lnkc\windows\
    sendto

16
Logon Scripts with Scripting
  • Still starts as a batch file
  • Then calls a script using CScript.exe
  • Can add more intelligence
  • Look at group memberships
  • Handle failures
  • Double check assumptions

17
Windows Script Host
  • CScript.exe
  • An executable for executing scripts from command
    line
  • WScript.exe
  • Executable from executing them in more of a
    windows mode
  • Provides easy access to handy objects
  • WScript
  • WScript.Shell
  • WScript.Network

18
WScript
  • WScript.Echo I really enjoyed LOPSA Phoenix
    SysAdmin Days
  • WScript.Sleep

19
WScript.Shell
  • Set oShell CreateObject("WScript.Shell")
  • Set oShort oShell.CreateShortcut("MyLink.lnk")
  • oShort.TargetPath "C\MyLink.txt"
  • oShort.Save
  • Set oUrlLink oShell.CreateShortcut("MyWeb
    Site.URL")
  • oUrlLink.TargetPath "http//www.myweb.com"
  • oUrlLink.Save

20
WScript.Network
  • Set oNetwork WScript.CreateObject("WScript.Netwo
    rk")
  • oNetwork.MapNetworkDrive U", \\Server1\Users
  • oNetwork.AddWindowsPrinterConnection
    "\\Server1\HP LaserJet"

21
2nd Half
  • Windows Management Instrumentation
  • Even greater automation capabilities
  • Scriptomatic
  • Generate Scripts in VBScript, Perl, Jscript
  • WMI Code Creator
  • Managing Event Logs
  • LogParser tool

22
WMI Windows Management Instrumentation
  • Can be used to manage all sorts of services and
    applications
  • Can be used to interrogate hardware
  • With a WQL filter on GPO to limit which computers
    will have a GPO apply.

23
WMI Scriptomatic
  • Microsoft Downloads
  • Generate scripts using WMI
  • VBScript
  • Jscript
  • Perl
  • Python
  • Run code right then and display in
  • Text
  • Excel
  • HTML
  • XML

24
(No Transcript)
25
WMI Code Creator
  • Download from Microsoft
  • Generate
  • VBScript
  • VB.NET
  • C
  • Easier to navigate
  • Query Data
  • Execute a Method
  • Receive an Event
  • Browse NameSpaces

26
(No Transcript)
27
(No Transcript)
28
WMI Summary
  • Providers
  • Namespace
  • Classes

29
Copy Event Log to a Database
  • Could use some complex WMI and ADO queries
  • Instead use the Log Parser 2.2 from MS
  • "C\Program Files\Log Parser 2.2\LogParser.exe"
    "SELECT ComputerName, EventLog, EventID,
    TimeGenerated, Message, EventTypeName,
    EventCategoryName, SourceName
  • INTO dbo.ApplicationLog FROM Application"
  • -oSQL -server. -databaseAppLog -driver"SQL
    Server" -usernameAppLogger -passwordapplogger
    -createTableON

30
Backup and Clear Events from Event Log
  • Set cLogFiles objWMIService.ExecQuery _
    ("Select from Win32_NTEventLogFile where
    LogFileName IN ('Application', 'System)")
  • For Each oLogfile in colLogFiles
  • iBackResult oLogFile.Backup(c\EvtLogs\oLogF
    ile.Name)
  • If iBackResult 0 Then
  • oLogFile.ClearEventLog()
  • Else
  • Wscript.Echo Could not backup event log and
    did not clear it
  • End If
  • Next

31
Use LogParser from Code and grab log from backup
file
  • Set oLogQuery CreateObject("MSUtil.LogQuery")
  • Set oEVTInputFormat CreateObject("MSUtil.LogQuer
    y.EventLogInputFormat")
  • Set oSQLOutputFormat CreateObject("MSUtil.LogQue
    ry.SQLOutputFormat")
  • ' Set output format parameters
  • oSQLOutputFormat.Server"."
  • oSQLOutputFormat.database"AppLog"
  • ' Create query text
  • strQuery "SELECT ComputerName, EventLog,
    EventID, TimeGenerated, Message, EventTypeName,
    EventCategoryName, SourceName INTO
    AppLogger.ApplicationLog FROM c\EvtLogs\Applicati
    on"
  • ' Execute query
  • oLogQuery.ExecuteBatch strQuery, oEVTInputFormat,
    oSQLOutputFormat

32
Copy and Clear
  • Combine the LogParser from code script with the
    clear log code
  • Or even better backup the log to file, clear it
    and then load from the backup file

33
Microsoft Operations Manager
  • Can search your event logs for important events
  • Consumes WMI Data
  • Management packs for different apps are available
    for download preconfigured with events to
    monitor and WMI data to capture and monitor

34
More Information
  • Script Center Script Repository
  • http//www.microsoft.com/technet/scriptcenter/scri
    pts/default.mspx
  • Microsoft Identity Integration Server
  • Microsoft Operations Manager
  • Mindworks -- MS Gold Partner Learning Solutions
    Scottsdale
  • MOC 2433 VB Scripting (3 days)
  • MOC 2439 Windows Management Instrumentation (2
    days)

35
More info -- continued
  • http//www.roth.net/books/handbook/
  • Win32 Perl Scripting The Administrator's
    Handbook
  • http//www.windowsnetworking.com/kbase/WindowsTips
    /WindowsNT/AdminTips/Logon/WindowsNTLoginScriptTri
    cksandTips.html

36
Questions
  • David_at_MutuallyBeneficial.com
Write a Comment
User Comments (0)
About PowerShow.com