Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

LastWriteTime help needed

$
0
0

Hi

I have searched around for a while and decided best to ask.

The Environment and what I have done thus far:

I have a lot of computers that are part of 1 domain

I have all of the computer names listed in a notepad file (1 per line)

I have very little experience with powershell, I'm on a steep learning curve.

I have executed this script to get the information of OS Service Pack version:

                   

# Author: Manoj R. Nair 
# www.manojnair.net 

$erroractionpreference = "SilentlyContinue" 

# Create a New Excel Object for storing Data 

$a = New-Object -comobject Excel.Application 
$a.visible = $True  

$b = $a.Workbooks.Add() 
$c = $b.Worksheets.Item(1) 

# Create the title row 

$c.Cells.Item(1,1) = "Machine Name" 
$c.Cells.Item(1,2) = "OS" 
$c.Cells.Item(1,3) = "Description" 
$c.Cells.Item(1,4) = "Service Pack" 

$d = $c.UsedRange 
$d.Interior.ColorIndex = 23 
$d.Font.ColorIndex = 2 
$d.Font.Bold = $True 
$d.EntireColumn.AutoFit($True) 

$intRow = 2 

$colComputers = get-content C:\Scripts\Servers.txt 

# Run through the Array of Computers 

foreach ($strComputer in $colComputers) 


$c.Cells.Item($intRow, 1) = $strComputer.ToUpper() 

# Get Operating System Info 

$colOS =Get-WmiObject -class Win32_OperatingSystem -computername $Strcomputer 

foreach($objComp in $colOS) 

$c.Cells.Item($intRow, 2) = $objComp.Caption 
$c.Cells.Item($intRow, 3) = $objComp.Description 
$c.Cells.Item($intRow, 4) = $objComp.ServicePackMajorVersion 


$intRow = $intRow + 1 


$intRow = $intRow + 1 

# Save workbook data 

$b.SaveAs("C:\Scripts\Checklist.xlsx") 

I changed this a bit and This worked very well and I gathered my information.

What I need to do now is very similar to the above script instead of OS Service pack version i need to get the LastWriteTime to be written in the .xlx worksheet. this is what I have mustered together

$a = New-Object -comobject Excel.Application 
$a.visible = $True  

$b = $a.Workbooks.Add() 
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name" 
$c.Cells.Item(1,2) = "Date Modified"

$d=$c.UsedRange
$d.Interior.ColorIndex = 23 
$d.Font.ColorIndex = 2 
$d.Font.Bold = $True 
$d.EntireColumn.AutoFit($True) 

$intRow = 2 

###############################

$Computers = Get-Content .\ServersROTest.txt

foreach ($strComputer in $Computers)
{
$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()

$colDate = (get-item c:\program files\xxx\xxx\xxx.rpl).LastWriteTime

$c.cells.Item($intRow, 2) = ???

how to I get it to display the results in .csv like this "PCname;LastWriteTime;"

thank you in advance


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>