Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Problem with populating Excel Spread Sheet

$
0
0

Hi

I'm able to populate a spread sheet with the info from one array but not able to populate the info from the 2nd array:

Code:

$Servers = Get-Content .\EMA.txt

$Dir1 = "\\DSServer1\Express_Gold\Images\Windows7\"

$Dir2 = ForEach ($Server in $Servers) {
"\\$Servers\Express\Images\Windows7\"
}

## Create Excel spread sheet
##############################
$Xlsfile = "C:\Temp\PowerShell\Test.xls"
$Excel = New-Object -Com Excel.Application
$Excel.visible = $False
$Excel.DisplayAlerts = $False
$Excel = $Excel.Workbooks.Add(1)

$S1 = $Excel.WorkSheets.Item(1)
$S1.Cells.Item(1,1) = “Deployment Server Share”
$S1.Cells.Item(1,2) = “Name”
$S1.Cells.Item(1,3) = “Last Modified”

$WorkBook = $S1.UsedRange
$WorkBook.Interior.ColorIndex = 30
$WorkBook.Font.ColorIndex = 2
$WorkBook.Font.Bold = $False
$intRow = 2

## Rename Sheet1
#################
$s1 = $Excel.sheets | where {$_.name -eq 'Sheet1'}
$s1.Name = "Deployment Solution"

$Files = Get-ChildItem $Dir1 -Recurse

ForEach ($file in $files){
$file.DirectoryName
$file.Name
$file.LastWriteTime
## Populate Work Sheet1
########################
  $S1.Cells.Item($intRow,1) = $file.DirectoryName
  $S1.Cells.Item($intRow,2) = $file.Name
  $S1.Cells.Item($intRow,3) = $file.LastWriteTime
  $intRow = $intRow + 1       
}

ForEach ($file2 in $files2){
$file2.DirectoryName
$file2.Name
$file2.LastWriteTime
 
}
#>
## Autofit Rows & Columns
#########################
$WorkBook.EntireColumn.AutoFit()
Clear

## Save Excel SS and create powershell folder
#############################################
if (Test-Path C:\Temp\Powershell)
 {
## Save spread sheet
####################
$Excel.SaveAS($Xlsfile,1)#<--overwrites if file already exists
 }
else
 {
 New-Item c:\Temp\PowerShell -type directory
 ## Save spread sheet
#####################
$Excel.SaveAS($Xlsfile,1)
 }
############################################
Write-Host "File location-->"  $XlsFile -fore Blue
############################################

## Open excel SS
############################################
Invoke-Expression $XlsFile
############################################

### End of script ###

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles