Last active
June 13, 2019 07:59
-
-
Save pkhabazi/7bbe7e722d25da43a161fc07d9b777bb to your computer and use it in GitHub Desktop.
This is a example how to get all azure resources for each subscription and save in word as table separated by chapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
to save to wod | |
https://github.com/microsoftgraph/security-api-solutions/tree/master/Samples/PowerShell | |
to get security alerts: | |
https://github.com/microsoftgraph/security-api-solutions/tree/master/Samples/PowerShell | |
#> | |
try { | |
Import-Module PSWriteWord #-Force | |
Import-Module AzureRM | |
} | |
catch { | |
Write-Error $_. -ErrorAction Stop | |
} | |
$FilePath = "C:\sources\pkm-code\Azure\reporing\output\PSWriteWord.docx" | |
$ListOfHeaders = @( | |
'This is 1st section', | |
'This is 2nd section' | |
) | |
<# | |
Get info | |
#> | |
$Subscriptions = Get-AzureRmSubscription | |
$Subscriptions | ForEach-Object { | |
$ListOfHeaders += $_.Name | |
} | |
$WordDocument = New-WordDocument -FilePath $FilePath | |
Add-WordToc -WordDocument $WordDocument -Title 'Table of content' -Switches C, A -RightTabPos 15 -HeaderStyle Heading1 -Supress $True | |
### This list will be converted into Headings for Numbered Table of Contents | |
$ListHeaders = Add-WordList -WordDocument $WordDocument -ListType Numbered -ListData $ListOfHeaders -Supress $false | |
### Converts List into numbered Headings for Table of Content | |
$Headings = Convert-ListToHeadings -WordDocument $WordDocument -List $ListHeaders | |
Add-WordText -WordDocument $WordDocument ` | |
-Paragraph $Headings[0] -Text 'blablabla', ' 1st ', 'section' -Color Black, Red, Black -Supress $false | |
foreach ($Subscription in $Subscriptions) { | |
$paragraph = $null | |
$Heading = $null | |
try { | |
Set-AzureRmContext -SubscriptionObject $Subscription | |
} | |
catch { | |
Write-Error $_ | |
} | |
$Heading = $Headings | Where-Object {$_.Text -like $($Subscription.Name)} | |
$paragraph = Add-WordText -WordDocument $WordDocument ` | |
-Paragraph $Heading -Text 'This is a text that will be added to ', ' 1st ', 'section' -Color Black, Red, Black -Supress $false | |
$Object = Get-AzureRmResource | ForEach-Object { | |
[PSCustomObject]@{ | |
"Name" = $_.Name | |
"ResourceGroupName" = $_.ResourceGroupName | |
"ResourceType" = ($_.ResourceType).Split('/')[-1] | |
"Location" = $_.Location | |
} | |
} | |
$paragraph = Add-WordTable -WordDocument $WordDocument -Paragraph $paragraph -DataTable $Object -Design 'ColorfulList' #-Verbose | |
} | |
Save-WordDocument $WordDocument -Language 'en-US' -Supress $True -OpenDocument |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment