working with Excel sheets, I've the following array (coming from the Import-Excel module)
PS C:\Projects> $AllSheets = Get-ExcelSheetInfo $excel_path
PS C:\Projects> $AllSheets
Name Index Hidden Path
---- ----- ------ ----
Applications 1 Visible C:\Projects\Data\policy.xlsx
Certificates 2 Visible C:\Projects\Data\policy.xlsx
Webdomains 3 Visible C:\Projects\Data\policy.xlsx
Ips_Hosts 4 Visible C:\Projects\Data\policy.xlsx
Ips_Hosts_subnet 5 Visible C:\Projects\Data\policy.xlsx
Extensions 6 Visible C:\Projects\Data\policy.xlsx
Files 7 Visible C:\Projects\Data\policy.xlsx
Directories 8 Visible C:\Projects\Data\policy.xlsx
I used to import (with Import-Excel module) data in a single variable like this :
$AllItemsInAllSheets = $AllSheets | ForEach-Object { Import-Excel $_.Path -WorksheetName $_.Name }
But once my sheets are not with the same structure, it's getting messy. I was thinking of dynamically assign the content of each sheet to its own variable like this :
$AllSheets | ForEach-Object { $"$_.name" = Import-Excel $_.Path -WorksheetName $_.Name }
Thinking it would create all $Applications, $Certificates etc... I'm guessing I can't get the syntax right or am not escaping correctly the "$"