Results 1 to 4 of 4

Thread: Server config file - batch editing script

  1. #1
    Join Date
    Dec 2009
    Posts
    23

    Server config file - batch editing script

    I had seen this question somewhere earlier but can't find the thread. Here is the question reworded.

    Need a script on each computer to open file C:\PLM\...\server1.xml, and replace each "LOCAL_PC_NAME" with the actual name of the computer running the script.

    Here is the script to do that in biterscripting.

    Code:
    # Script Substitute.txt
    var str file, xml, computer
    # Get the computer mame.
    set $computer = getcomputer()
    # Read file in.
    cat $file > $xml
    # Replace each instance of "LOCAL_PC_NAME" with $computer.
    while ( { sen "^LOCAL_PC_NAME^" $xml } > 0 )
        sal "^LOCAL_PC_NAME^" $computer $xml  > null
    # Write file back
    echo $xml > { echo $file }



    Call the script with the following command.

    Code:
    script "Substitute.txt" file("C:\PLM\...\server1.xml")
    Put the script in C:/Scripts or in some directory that's in $path.

    Use the correct full path for the file() argument instead of "C:\PLM\...\server1.xml".

  2. #2
    Join Date
    Jan 2006
    Posts
    3,792

    Re: Server config file - batch editing script

    Hey thanks a lot for giving this post that will be helpful for me to set the my server configuration. I have the same problem and looking for the same so that i can create my own and finally got it here. Need more help actually i am looking for the print server script so help me with that too. A help may be appreciated.

  3. #3
    Join Date
    Aug 2006
    Posts
    122

    Re: Server config file - batch editing script

    Code:
    On Error Resume Next
    Dim strComputer, strExcelPath, objExcel, objSheet, k, objGroup
    Dim objWMIService, colItems, ErrState, Sheet
    'Sheet = spreadsheet page, k = row in sheet
    Sheet = 1
    k = 2
    strComputer = InputBox ("Please type the print server name to check, " & vbCrLf & _
       "Else enter ALL for all CC print servers", "Server Name")
    if strComputer = "" then
      WScript.quit
    end if
    strExcelPath = InputBox ("Please enter the path to save file to: ", "File path", "c:\")
    strExcelPath = strExcelPath & "Printers_" & strComputer & ".xls"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
    ' Bind to Excel object.
    On Error Resume Next
    Set objExcel = CreateObject("Excel.Application")
    If Err.Number <> 0 Then
      On Error GoTo 0
      Wscript.Echo "Excel application not found."
      Wscript.Quit
    End If
    On Error GoTo 0
    ' Create a new workbook.
    objExcel.Workbooks.Add
    'Change this to fit your server situation
    Select Case UCase(strComputer)
      Case "ALL"
        PrintServer("CCPS01")
        Sheet = Sheet + 1
        PrintServer("IRGFS01")
        Sheet = Sheet + 1
        PrintServer("CCFLDR01")
      Case Else
        PrintServer(strComputer)
    End Select
    Function PrintServer(strComputer)
    k=2
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
    ' Bind to worksheet.
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(Sheet)
    objSheet.Name = strComputer
    ' Populate spreadsheet cells with printer attributes.
    objSheet.Cells(1, 1).Value = "Name"
    objSheet.Cells(1, 2).Value = "ShareName"
    objSheet.Cells(1, 3).Value = "Comment"
    objSheet.Cells(1, 4).Value = "Error"
    objSheet.Cells(1, 5).Value = "DriverName"
    objSheet.Cells(1, 6).Value = "EnableBIDI"
    objSheet.Cells(1, 7).Value = "JobCount"
    objSheet.Cells(1, 8).Value = "Location"
    objSheet.Cells(1, 9).Value = "PortName"
    objSheet.Cells(1, 10).Value = "Published"
    objSheet.Cells(1, 11).Value = "Queued"
    objSheet.Cells(1, 12).Value = "Shared"
    objSheet.Cells(1, 13).Value = "Status"
    For Each objItem in colItems
    'put error code into human readable form
    Select Case objItem.DetectedErrorState
      Case 4
        ErrState = "Out of Paper"
      Case 5
        ErrState = "Toner low"
      Case 6
        ErrState = "Printing"
      Case 9
        ErrState = "Offline"
      Case Else
        ErrState = objItem.DetectedErrorState
    End Select
    'populate the row with this printer's data
    objSheet.Cells(k, 1).Value = objItem.Name
    objSheet.Cells(k, 2).Value = objItem.ShareName
    objSheet.Cells(k, 3).Value = objItem.Comment
    objSheet.Cells(k, 4).Value = ErrState
    objSheet.Cells(k, 5).Value = objItem.DriverName
    objSheet.Cells(k, 6).Value = objItem.EnableBIDI
    objSheet.Cells(k, 7).Value = objItem.JobCountSinceLastReset
    objSheet.Cells(k, 8).Value = objItem.Location
    objSheet.Cells(k, 9).Value = objItem.PortName
    objSheet.Cells(k, 10).Value = objItem.Published
    objSheet.Cells(k, 11).Value = objItem.Queued
    objSheet.Cells(k, 12).Value = objItem.Shared
    objSheet.Cells(k, 13).Value = objItem.Status
    k = k + 1
    Next
    ' Format the spreadsheet.
    objSheet.Range("A1:M1").Font.Bold = True
    objSheet.Select
    objSheet.Range("A2").Select
    objExcel.ActiveWindow.FreezePanes = True
    objExcel.Columns(3).ColumnWidth = 25
    objExcel.Columns(5).ColumnWidth = 25
    objExcel.Columns(6).ColumnWidth = 10
    objExcel.Columns(8).ColumnWidth = 25
    objExcel.Columns(1).ColumnWidth = 20
    objExcel.Columns(9).ColumnWidth = 14
    objExcel.Columns(2).ColumnWidth = 15
    End Function
    ' Save the spreadsheet and close the workbook.
    objExcel.ActiveWorkbook.SaveAs strExcelPath
    objExcel.ActiveWorkbook.Close
    ' Quit Excel.
    objExcel.Application.Quit
    ' Clean Up
    Set objUser = Nothing
    Set objGroup = Nothing
    Set objSheet = Nothing
    Set objExcel = Nothing
    WScript.Echo "Printer listing is done"
    This script will work on 2003 server. Using this script you can access a print server, get information about all printers on the server. Hope that you were looking for the same.
    As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau

  4. #4
    Join Date
    Dec 2009
    Posts
    23

    Re: Server config file - batch editing script

    Nice print server script.

Similar Threads

  1. batch script to find a file
    By stevenwhite in forum Software Development
    Replies: 1
    Last Post: 10-04-2012, 12:55 PM
  2. Editing text file using a batch file
    By beelow in forum Software Development
    Replies: 8
    Last Post: 09-03-2010, 12:27 AM
  3. Batch Script Text file parse
    By tator.usenet@gmail.com in forum Windows Server Help
    Replies: 5
    Last Post: 25-03-2009, 02:12 AM
  4. How can I play a Wav file from batch/cmd script?
    By NaFula in forum Windows Vista Performance
    Replies: 3
    Last Post: 13-09-2008, 09:21 PM
  5. How to create a script in a DOS batch file to do a loop?
    By Jon Osborn in forum Windows Server Help
    Replies: 2
    Last Post: 27-05-2008, 06:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,928,275.13831 seconds with 17 queries