Replies: 2 comments 1 reply
-
You dont need this line: The final block refactored: $sqlVersionRowsArray = [System.Collections.Generic.List[object]]::new()
$rows = Foreach ($version in $sqlVersions) {
$sqlVersionRows = Import-Excel -Path $sqlVersionFile -WorksheetName $version -AsDate 'Release Date'
$sqlVersionRows | Add-Member -MemberType NoteProperty -Name Version -Value $version
[pscustomobject]@{
'Version' = $version
'Build Number' = $sqlVersionRows.'Build Number'.Get(1)
'KB Number' = $sqlVersionRows.'KB Number'.Get(1)
'KB URL' = $sqlVersionRows.'KB URL'.Get(1)
'Release Date' = $sqlVersionRows.'Release Date'.Get(1)
'Service Pack Level' = $sqlVersionRows.'Service Pack Level'.Get(1)
'Cumulative Update or Security ID' = $sqlVersionRows.'Cumulative Update or Security ID'.Get(1)
'Servicing Model' = $sqlVersionRows.'Servicing Model'.Get(1)
'Notes' = $sqlVersionRows.'Notes'.Get(1)
}
$sqlVersionRowsArray.Add($sqlVersionRows.Get(1))
}
$rows | Export-Excel -Path $mssqlCMSFile -WorksheetName 'SQL Versions' |
Beta Was this translation helpful? Give feedback.
1 reply
-
it works just fine $sqlVersions = '2008 R2', '2012', '2014', '2016', '2017', '2019', '2022'
$sqlVersionsUrl = "https://aka.ms/sqlserverbuilds"
$sqlVersionFile = 'SqlUpates.xlsx'
Invoke-WebRequest $sqlVersionsUrl -OutFile $sqlVersionFile
$rows = Foreach ($version in $sqlVersions) {
$sqlVersionRows = Import-Excel -Path $sqlVersionFile -WorksheetName $version -AsDate 'Release Date'
[pscustomobject]@{
'Version' = $version
'Build Number' = $sqlVersionRows.'Build Number'.Get(1)
'KB Number' = $sqlVersionRows.'KB Number'.Get(1)
'KB URL' = $sqlVersionRows.'KB URL'.Get(1)
'Release Date' = $sqlVersionRows.'Release Date'.Get(1)
'Service Pack Level' = $sqlVersionRows.'Service Pack Level'.Get(1)
'Cumulative Update or Security ID' = $sqlVersionRows.'Cumulative Update or Security ID'.Get(1)
'Servicing Model' = $sqlVersionRows.'Servicing Model'.Get(1)
'Notes' = $sqlVersionRows.'Notes'.Get(1)
}
}
$mssqlCMSFile = "Mssql_instance_list.xlsx"
$rows | Export-Excel -Path $mssqlCMSFile -WorksheetName 'SQL Versions' It is probably something wrong with your module setup UPDATETry different file locations (not TEMP) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear all,
I am trying to save some data to a specific Excel sheet.
The source is an Excel file (sqlVersionFile) with different worksheets for reach SQL Server Version where I read the data from, then add one more column (SQL Server Version) and then I want to save it to the an existing target (mssqlCMSFile) with the worksheet name 'SQL Versions'.
I tried it with an array of objects and one time using Export-Excel.
I tried it with Export-Excel for each row to save (current listing).
I tried Set-Row.
But whatever I try, I am stuck: With Export-Excel I always get the error
When using Set-Row instead of Export-Excel I get nothing and nothing is saved to the target.
Can you please point me in the right direction?
Thank you very much and kind regards,
Olaf
Listing:
Beta Was this translation helpful? Give feedback.
All reactions