2016-12-28 17 views
0

データベースのファイルからテープへのジョブをチェックし、Excelシートで出力します。私は変数にOutput.xlsxの内容をインポートしようとすると、PowerShellでExcelシートを読み込めない形式で保存する

$date = Get-Date 
$day = $date.Day 
$hour = $date.Hour 
$Excel = New-Object -ComObject Excel.Application 
$Excel.visible = $true 
$Excel.DisplayAlerts = $false 
$Workbook = $Excel.Workbooks.Add() 
$Sheet = $Excel.Worksheets.Item(1) 
#Counter variable for rows and columns 
$intRow = 1 
$intCol = 1 

$Sheet.Cells.Item($intRow,1) = "Tasks/Servers"  
$Sheet.Cells.Item($intRow,2) = "DateLastRun" 
$Sheet.Cells.Item($intRow,3) = "PRX1CSDB01" 
$Sheet.Cells.Item($intRow,4) = "PRX1CSDB02" 
$Sheet.Cells.Item($intRow,5) = "PRX1CSDB03" 
$Sheet.Cells.Item($intRow,6) = "PRX1CSDB11" 
$Sheet.Cells.Item($intRow,7) = "PRX1CSDB12" 
$Sheet.Cells.Item($intRow,8) = "PRX1CSDB13" 
$Sheet.Cells.Item($intRow+1,1) = "File To Tape weekly Full Backup" 
$Sheet.UsedRange.Rows.Item(1).Borders.LineStyle = 1 

#FTT.txt contains the path for a list of servers 
$path = Get-Content D:\Raghav\DB_Integrated\FTT.txt 

foreach ($server in $path) 
{ 
If (Test-Path $server) 
{ 
$BckpWeek = gci -path $server | select-object | where {$_.Name -like "*logw*"} | sort LastWriteTime | select -last 1 
$Sheet.Cells.Item($intRow+1,$intCol+1) = $BckpWeek.LastWriteTime.ToString('MMddyyyy') 
$Sheet.UsedRange.Rows.Item($intRow).Borders.LineStyle = 1 
$x = (get-date) - ([datetime]$BckpWeek.LastWriteTime) 
if($x.days -gt 7){$status_week = "Failed"} 
else{$status_week = "Successful"} 
$Sheet.Cells.Item($intRow+1,$intCol+2) = $status_week 
$intCol++ 
} 
else 
{ 
$Sheet.Cells.Item($intRow+1,$intCol+2) = "Path Not Found" 
$intCol++ 
} 
} 
$Sheet.UsedRange.EntireColumn.AutoFit() 
$workBook.SaveAs("C:\Users\Output.xlsx",51) 
$excel.Quit() 

はしかし、私は読めない形式でデータを取得し、$cc言います。

$cc = Import-Csv "C:\Users\Output.xlsx" 

添付ファイルは、output.xlsxを$ ccにエクスポートするためのイメージです。私はcsv形式でも出力を入れようとしました。しかし、それはまた、役に立たないようです。 output fileこれについて何か考えている人や、これまでに似たような状況に直面している人はいますか?

+3

こんにちは、なぜ 'Import-CSV'を使うのですか? 'xslx'は' CSV'とは異なります。 – sodawillow

+0

申し訳ありませんが、PowerShellを初めて使用しています。 xlsxファイルの内容をpowershellの変数にインポートする方法はありますか? –

+1

確かに、ここにある[例](http://stackoverflow.com/questions/19211632/read-excel-sheet-in-powershell) – sodawillow

答えて

0

@ZevSpitz - OleDbConnectionクラスを探して、私はhttps://blogs.technet.microsoft.com/pstips/2014/06/02/get-excel-data-without-excel/に上陸しました。これは私が探していたものです。正しい方向に私を指摘してくれてありがとう。

@MikeGaruccio - 残念ながら、Get-HelpメニューでImport-Excelコマンドが見つかりませんでした。私はPowershell 4.0を使用しています。とにかく、提案に感謝します。

関連する問題