Hey CheckYourLogs fans!
While working on a recent engagement, we wanted to populate a 1E Shopping site with a rather lengthy list of icons for client-facing applications. The admin had already painstakingly added all the icons into Software Center, but we couldn’t find a method to pull them out en masse. We found a script on https://www.sqlshack.com that could be used to extract icons from a SQL database, and my client made a few tweaks to make it work with Configuration Manager. Thanks for letting me share it, Mike!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | $Server = "SCCM.SERVER.FQDN" ; $Database = "cm_ps1" ; $Dest = "C:\Drivers\Icons\" ; $bufferSize = 8192; $Sql = "SELECT Distinct([Icon]), [Title] FROM [CM_QD1].[dbo].[CI_LocalizedCIClientProperties] where icon is not null " ; $con = New-Object Data.SqlClient.SqlConnection; $con .ConnectionString = "Data Source=$Server;" + "Integrated Security=True;" + "Initial Catalog=$Database" ; $con .Open(); Write-Output (( Get-Date -format yyyy-MM-dd-HH:mm:ss) + ": Export ICON objects Started ..." ); $cmd = New-Object Data.SqlClient.SqlCommand $Sql , $con ; $rd = $cmd .ExecuteReader(); $out = [array] ::CreateInstance( 'Byte' , $bufferSize ) While ( $rd .Read()) { try { Write-Output ( "Exporting Objects from FILESTREAM container: {0}" -f $rd .GetString(1)); # New BinaryWriter $fs = New-Object System.IO.FileStream ( $Dest + $rd .GetString(1) + ".png" ), Create, Write; $bw = New-Object System.IO.BinaryWriter $fs ; $start = 0; # Read first byte stream $received = $rd .GetBytes(0, $start , $out , 0, $bufferSize - 1); While ( $received -gt 0) { $bw .Write( $out , 0, $received ); $bw .Flush(); $start += $received ; # Read next byte stream $received = $rd .GetBytes(0, $start , $out , 0, $bufferSize - 1); } $bw .Close(); $fs .Close(); } catch { Write-Output ( $_ .Exception.Message) } finally { $fs .Dispose(); } } $rd .Close(); $cmd .Dispose(); $con .Close(); Write-Output ( "Finished" ); Read-Host -Prompt "Press Enter to exit" |
Hope this helps!
É