Almost there but can't figure how to get this to complete

Author Message
addicted

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 5/12/2009
  • Status: offline
Almost there but can't figure how to get this to complete Friday, June 05, 2009 6:58 AM (permalink)
0
I think I am on the right track with this script but I know Im missing some very important information.
 
The purpose of this script is to tell me the following:
 
1. The computers host name
2. The file it scanned
3. The file's location on the hard drive
4. The version of the file it found
 
I am looking to find all versions of the file GDIPLUS.DLL that is on a computers hard drive. This file is used by many different programs and is found in various locations on the hard drive as it is dependant on what softwares loaded on that computer. I have to check several hundred computers and would like to use Power Shell for this.
 
The way I have this written is I click on a BAT file to launch it. That opens a text file I will be using to put in the hosts I want to scan. Then it starts a scan on a remote computer thats listed in the forst text file. An Excel document opens and is supposed to fill in the information but I can't figure out how to get it to do that. That's the missing information.
 
Here is the script I have, can anyone help me finish this please?
 
 
 

$WorksheetName = "Software Versions"
$ServerList = "C:\script\servers.txt"
$SaveFile = "C:\script\Software_Versions.xlsx"
$SaveFileHTM = "C:\Inetpub\wwwroot\Software_Versions.htm"
$LastColumn = "O"
 
$xlAutomatic = -4105
$xlBottom = -4107
$xlCenter = -4108
$xlContext = -5002
$xlContinuous = 1
$xlDiagonalDown = 5
$xlDiagonalUp = 6
$xlEdgeBottom = 9
$xlEdgeLeft = 7
$xlEdgeRight = 10
$xlEdgeTop = 8
$xlInsideHorizontal = 12
$xlInsideVertical = 11
$xlNone = -4142
$xlThin = 2
 
$erroractionpreference = "SilentlyContinue"
 
######################################################
#   Create Excel document and format Header
######################################################
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$b.workSheets.item(3).delete()
$b.workSheets.item(2).delete()
$b.WorkSheets.item(1).Name = $WorksheetName
$c = $b.Worksheets.Item(1)
$c.Application.ActiveWindow.SplitColumn = 1
$c.Application.ActiveWindow.SplitRow = 1
$c.Application.ActiveWindow.FreezePanes=$true
 
$c.Cells.Item(1,1) = "Server Name"
$c.Cells.Item(1,2) = "GDIPLUS.DLL"
$c.Cells.Item(1,3) = "File Location"
$c.Cells.Item(1,4) = "Version Number"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2

######################################################
#       ROWS - data
######################################################

$colComputers = get-content $serverList
foreach ($strComputer in $colComputers)
{

$GDIPLUS = " "

$GDI = [system.diagnostics.fileversioninfo]::GetVersionInfo("\\$strComputer\admin$\GDIPLUS.DLL").ProductVersion
 

$c.Cells.Item($intRow,1) = $strComputer.Toupper()
$c.Cells.Item($intRow,2) = $GDIVersion
 
$intRow = $intRow + 1
}

######################################################
#   Format data
######################################################
$FormatRange = ("A1:" + $LastColumn) + ($intRow - 1)
$ws = $b.worksheets | where {$_.name -eq $WorksheetName}
$selection = $ws.range($FormatRange)
$selection.select()
$selection.HorizontalAlignment = $xlCenter
$selection.VerticalAlignment = $xlBottom
$selection.WrapText = $false
$selection.Orientation = 0
$selection.AddIndent = $false
$selection.IndentLevel = 0
$selection.ShrinkToFit = $false
$selection.ReadingOrder = $xlContext
$selection.MergeCells = $false
$selection.Borders.Item($xlInsideHorizontal).Weight = $xlThin
$selection.Borders.Item($xlInsideHorizontal).LineStyle = $xlContinuous
$selection.Borders.Item($xlInsideHorizontal).ColorIndex = $xlAutomatic
$selection.Borders.Item($xlInsideVertical).Weight = $xlThin
$selection.Borders.Item($xlInsideVertical).LineStyle = $xlContinuous
$selection.Borders.Item($xlInsideVertical).ColorIndex = $xlAutomatic
$selection.Borders.Item($xlEdgeLeft).Weight = $xlThin
$selection.Borders.Item($xlEdgeLeft).LineStyle = $xlContinuous
$selection.Borders.Item($xlEdgeLeft).ColorIndex = $xlAutomatic
$selection.Borders.Item($xlEdgeRight).Weight = $xlThin
$selection.Borders.Item($xlEdgeRight).LineStyle = $xlContinuous
$selection.Borders.Item($xlEdgeRight).ColorIndex = $xlAutomatic
$selection.Borders.Item($xlEdgeTop).Weight = $xlThin
$selection.Borders.Item($xlEdgeTop).LineStyle = $xlContinuous
$selection.Borders.Item($xlEdgeTop).ColorIndex = $xlAutomatic
$selection.Borders.Item($xlEdgeBottom).Weight = $xlThin
$selection.Borders.Item($xlEdgeBottom).LineStyle = $xlContinuous
$selection.Borders.Item($xlEdgeBottom).ColorIndex = $xlAutomatic
$Selection.Font.Size = 10
$Selection.AutoFilter()
$d.EntireColumn.AutoFit()
 
 
######################################################
#   Save as XLSX
######################################################
$xlExcel8 = 51
$b.SaveAs($SaveFile,$xlExcel8)
$xlExcel8 = 44
$b.SaveAs($SaveFileHTM,$xlExcel8)
$a.Quit()

 
#1
    ebgreen

    • Total Posts : 8219
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Almost there but can't figure how to get this to complete Friday, June 05, 2009 7:05 AM (permalink)
    0
    Ok, so right now your problem is getting the information into Excel? They way I would do this is to start by creating an arraylist up at the top:

    $results = New-Object System.Collections.ArrayList


    Then in the loop where you actually collect the file in formation I would make it this:

    oreach ($strComputer in $colComputers)
    {

    $GDIPLUS = " "

    $GDI = [system.diagnostics.fileversioninfo]::GetVersionInfo("\\$strComputer\admin$\GDIPLUS.DLL").ProductVersion

    $temp = '' | Select-Object Computer, VersionInfo
    $temp.Computer = $strComputer.ToUpper()
    $VersionInfo = $GDI
    $results.Add($temp)
    }

    Then at the end where you have all that Excel formatting stuff I would get rid of the excel stuff and do:

    $results | Export-CSV 'C:\path\to\outputfile.csv'

    Now you have a csv that you can open in Excel.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      addicted

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 5/12/2009
      • Status: offline
      RE: Almost there but can't figure how to get this to complete Friday, June 05, 2009 7:43 AM (permalink)
      0
      Thank you for your reply. I need this to do two things. The first is I need this to scan the entire C partition, skipping no folders. I also need to know where the files it finds that are named GDIPLUS.DLL exist. How do I do that?
       
      #3
        addicted

        • Total Posts : 4
        • Scores: 0
        • Reward points : 0
        • Joined: 5/12/2009
        • Status: offline
        RE: Almost there but can't figure how to get this to complete Friday, June 05, 2009 8:53 AM (permalink)
        0
        When I ran what you told me to here it gave me this error:
         
        Unexpected token 'in' in expression or statement.
        At char:24
        + oreach ($strComputer in  <<<< $colComputers)
         
        Any idea?
         
         
         
         
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9