@@ -30,7 +30,10 @@ function Export-Database {
3030 # The Zero Trust pillar to assess. Defaults to All.
3131 [ValidateSet (' All' , ' Identity' , ' Devices' , ' Network' , ' Data' )]
3232 [string ]
33- $Pillar = ' All'
33+ $Pillar = ' All' ,
34+
35+ [string ]
36+ $LogsPath
3437 )
3538
3639 # region Utility Function
116119 }
117120 # endregion Utility Function
118121
122+ # region Logged Import Helper
123+ function Import-EntraTableLogged {
124+ [CmdletBinding ()]
125+ param (
126+ [Parameter (Mandatory = $true )]
127+ [DuckDB.NET.Data.DuckDBConnection ]
128+ $Database ,
129+
130+ [Parameter (Mandatory = $true )]
131+ [string ]
132+ $ExportPath ,
133+
134+ [Parameter (Mandatory = $true )]
135+ [string ]
136+ $TableName ,
137+
138+ [string ]
139+ $LogsPath
140+ )
141+
142+ Write-ZtDatabaseLog - TableName $TableName - LogsPath $LogsPath - Action Started
143+ $tableStart = Get-Date
144+ try {
145+ Import-EntraTable - Database $Database - ExportPath $ExportPath - TableName $TableName
146+ $tableDuration = (Get-Date ) - $tableStart
147+ Write-ZtDatabaseLog - TableName $TableName - LogsPath $LogsPath - Action Completed - Duration $tableDuration
148+ }
149+ catch {
150+ $tableDuration = (Get-Date ) - $tableStart
151+ Write-ZtDatabaseLog - TableName $TableName - LogsPath $LogsPath - Action Failed - Duration $tableDuration - ErrorMessage $_
152+ throw
153+ }
154+ }
155+ # endregion Logged Import Helper
156+
119157 $activity = " Creating database"
120158 Write-ZtProgress - Activity $activity - Status " Starting"
121159 Update-ZtProgressState - WorkerId ' database' - WorkerName ' Creating Database' - WorkerStatus ' Running' - WorkerDetail ' Initializing...'
142180 }
143181
144182 if ($Pillar -in (' All' , ' Identity' )) {
145- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' User'
146- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' Application'
147- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipal'
148- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipalSignIn'
149- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' SignIn'
150- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleDefinition'
151- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignment'
152- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentGroup'
153- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstance'
154- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstanceGroup'
155- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstance'
156- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstanceGroup'
157- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleManagementPolicyAssignment'
158- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' UserRegistrationDetails'
183+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' User' - LogsPath $LogsPath
184+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' Application' - LogsPath $LogsPath
185+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipal' - LogsPath $LogsPath
186+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipalSignIn' - LogsPath $LogsPath
187+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' SignIn' - LogsPath $LogsPath
188+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleDefinition' - LogsPath $LogsPath
189+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignment' - LogsPath $LogsPath
190+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentGroup' - LogsPath $LogsPath
191+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstance' - LogsPath $LogsPath
192+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstanceGroup' - LogsPath $LogsPath
193+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstance' - LogsPath $LogsPath
194+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstanceGroup' - LogsPath $LogsPath
195+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleManagementPolicyAssignment' - LogsPath $LogsPath
196+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' UserRegistrationDetails' - LogsPath $LogsPath
159197
160198 New-ViewRole - Database $database
161199 }
162200
163201 if ($Pillar -in (' All' , ' Devices' )) {
164- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' Device'
165- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' ConfigurationPolicy'
202+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' Device' - LogsPath $LogsPath
203+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' ConfigurationPolicy' - LogsPath $LogsPath
166204 }
167205
168206 if ($Pillar -in (' All' , ' Network' )) {
169- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' User'
170- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' Application'
171- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipal'
172- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleDefinition'
173- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignment'
174- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentGroup'
175- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstance'
176- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstanceGroup'
177- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstance'
178- Import-EntraTable - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstanceGroup'
207+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' User' - LogsPath $LogsPath
208+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' Application' - LogsPath $LogsPath
209+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' ServicePrincipal' - LogsPath $LogsPath
210+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleDefinition' - LogsPath $LogsPath
211+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignment' - LogsPath $LogsPath
212+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentGroup' - LogsPath $LogsPath
213+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstance' - LogsPath $LogsPath
214+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleAssignmentScheduleInstanceGroup' - LogsPath $LogsPath
215+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstance' - LogsPath $LogsPath
216+ Import-EntraTableLogged - Database $database - ExportPath $ExportPath - TableName ' RoleEligibilityScheduleInstanceGroup' - LogsPath $LogsPath
179217
180218 New-ViewRole - Database $database
181219 }
0 commit comments