Hi,
You can read Excel spreadsheets using COM objects from powershell.
$File = "C:\gpo.xlsx"
$Excel = New-Object -ComObject Excel.Application
$WorkBook = $Excel.Workbooks.Open($File)
$WorkSheet = $WorkBook.Worksheets.Item(1)
$UsedRange = $WorkSheet.UsedRange
$Rows = $UsedRange.Rows.Count
$Objs = @()
for($Row=2; $Row -le $Rows; $Row++){
$Objs += [PSCustomObject]@{
GPO = $UsedRange.Cells($Row,1).Text
Group = $UsedRange.Cells($Row,2).Text
Drive = $UsedRange.Cells($Row,3).Text
Comment = $UsedRange.Cells($Row,4).Text
Target = $UsedRange.Cells($Row,5).Text
}
}
$WorkBook.Close($false)
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) | Out-Null
Stop-Process -Name "EXCEL"
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.