diff --git a/module/Entra/Microsoft.Entra/Applications/Microsoft.Entra.Applications.format.ps1xml b/module/Entra/Microsoft.Entra/Applications/Microsoft.Entra.Applications.format.ps1xml new file mode 100644 index 0000000000..eab4c70e85 --- /dev/null +++ b/module/Entra/Microsoft.Entra/Applications/Microsoft.Entra.Applications.format.ps1xml @@ -0,0 +1,33 @@ + + + + + + EntraApplicationView + + Microsoft.Entra.Application + + + + + + + + + + + + + + id + displayName + appId + signInAudience + publisherDomain + + + + + + + \ No newline at end of file diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 index b0132b61c0..26398ad793 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUser.ps1 @@ -126,6 +126,7 @@ function Get-EntraUser { $propertyValue = $_.Value $userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $userType.PSTypeNames.Insert(0, "Microsoft.Entra.User.Simple") $userList += $userType } $userList diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 index c2ab20f0b6..7d1e9e1958 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserDirectReport.ps1 @@ -79,6 +79,7 @@ function Get-EntraUserDirectReport { $propertyValue = $_.Value $userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $userType.PSTypeNames.Insert(0, "Microsoft.Entra.User.Manager") $userList += $userType } $userList diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 index eea6f1bff8..56aec0f8b3 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserManager.ps1 @@ -57,6 +57,7 @@ function Get-EntraUserManager { $propertyValue = $_.Value $userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $userType.PSTypeNames.Insert(0, "Microsoft.Entra.User.Manager") $userList += $userType } $userList diff --git a/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 b/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 index dd8032147f..2214038a56 100644 --- a/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 +++ b/module/Entra/Microsoft.Entra/Users/Get-EntraUserSponsor.ps1 @@ -101,6 +101,7 @@ function Get-EntraUserSponsor { $propertyValue = $_.Value $memberType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $memberType.PSTypeNames.Insert(0, "Microsoft.Entra.User.Simple") $memberList += $memberType } return $memberList diff --git a/module/Entra/Microsoft.Entra/Users/Microsoft.Entra.Users.format.ps1xml b/module/Entra/Microsoft.Entra/Users/Microsoft.Entra.Users.format.ps1xml new file mode 100644 index 0000000000..30055de14a --- /dev/null +++ b/module/Entra/Microsoft.Entra/Users/Microsoft.Entra.Users.format.ps1xml @@ -0,0 +1,91 @@ + + + + + + EntraUserStandardView + + Microsoft.Entra.User + + + + + + + + + + + + + + id + displayName + userPrincipalName + userType + accountEnabled + + + + + + + + + EntraUserSimpleView + + Microsoft.Entra.User.Simple + + + + + + + + + + + + id + displayName + userType + + + + + + + + + EntraUserManagerView + + Microsoft.Entra.User.Manager + + + + + + + + + + + + + + + + id + displayName + userPrincipalName + createdDateTime + accountEnabled + userType + securityIdentifier + + + + + + + \ No newline at end of file diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Applications/Get-EntraBetaApplicationProxyConnector.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Applications/Get-EntraBetaApplicationProxyConnector.ps1 index fe0fc24770..73e531f866 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Applications/Get-EntraBetaApplicationProxyConnector.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Applications/Get-EntraBetaApplicationProxyConnector.ps1 @@ -64,6 +64,7 @@ function Get-EntraBetaApplicationProxyConnector { $propertyValue = $_.Value $targetType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $targetType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.Application") $targetList += $targetType } $targetList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Applications/Microsoft.Entra.Beta.Applications.format.ps1xml b/module/EntraBeta/Microsoft.Entra.Beta/Applications/Microsoft.Entra.Beta.Applications.format.ps1xml new file mode 100644 index 0000000000..bd7b6c99ae --- /dev/null +++ b/module/EntraBeta/Microsoft.Entra.Beta/Applications/Microsoft.Entra.Beta.Applications.format.ps1xml @@ -0,0 +1,33 @@ + + + + + + EntraBetaApplicationView + + Microsoft.Entra.Beta.Application + + + + + + + + + + + + + + id + displayName + appId + signInAudience + publisherDomain + + + + + + + \ No newline at end of file diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 index b11a395420..6793eab85e 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUser.ps1 @@ -135,6 +135,7 @@ ErrorCode: Request_ResourceNotFound" $propertyValue = $_.Value $userType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $userType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Simple") $userList += $userType } $userList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 index cfd4d96baa..6e4297ddec 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserDirectReport.ps1 @@ -69,6 +69,7 @@ function Get-EntraBetaUserDirectReport { $propertyValue = $_.Value $targetType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $targetType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Manager") $targetList += $targetType } $targetList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 index 99d74153e9..be6f8a58dd 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserManager.ps1 @@ -80,6 +80,7 @@ function Get-EntraBetaUserManager { $propertyValue = $_.Value $targetType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $targetType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Manager") $targetList += $targetType } $targetList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 index eb4f23ea67..7c538f894c 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserOwnedObject.ps1 @@ -63,6 +63,7 @@ function Get-EntraBetaUserOwnedObject { $propertyValue = $_.Value $targetType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $targetType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Simple") $targetList += $targetType } $targetList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 index e9bf95ce06..631aa6a1e5 100644 --- a/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Get-EntraBetaUserSponsor.ps1 @@ -74,7 +74,6 @@ function Get-EntraBetaUserSponsor { $response = Invoke-GraphRequest -Headers $customHeaders -Uri $($params.Uri) -Method GET | ConvertTo-Json -Depth 10 | ConvertFrom-Json try { $data = $response.value | ConvertTo-Json -Depth 10 | ConvertFrom-Json - $directoryObjectList = @() $all = $All.IsPresent $increment = $topCount - $data.Count @@ -103,6 +102,7 @@ function Get-EntraBetaUserSponsor { $propertyValue = $_.Value $memberType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force } + $memberType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Simple") $memberList += $memberType } return $memberList diff --git a/module/EntraBeta/Microsoft.Entra.Beta/Users/Microsoft.Entra.Beta.Users.format.ps1xml b/module/EntraBeta/Microsoft.Entra.Beta/Users/Microsoft.Entra.Beta.Users.format.ps1xml new file mode 100644 index 0000000000..9ec98cff33 --- /dev/null +++ b/module/EntraBeta/Microsoft.Entra.Beta/Users/Microsoft.Entra.Beta.Users.format.ps1xml @@ -0,0 +1,91 @@ + + + + + + EntraBetaUserStandardView + + Microsoft.Entra.Beta.User + + + + + + + + + + + + + + id + displayName + userPrincipalName + userType + accountEnabled + + + + + + + + + EntraBetaUserSimpleView + + Microsoft.Entra.Beta.User.Simple + + + + + + + + + + + + id + displayName + userType + + + + + + + + + EntraUserManagerView + + Microsoft.Entra.Beta.User.Manager + + + + + + + + + + + + + + + + id + displayName + userPrincipalName + createdDateTime + accountEnabled + userType + securityIdentifier + + + + + + + \ No newline at end of file diff --git a/src/EntraModuleBuilder.ps1 b/src/EntraModuleBuilder.ps1 index 46be66f2e4..02f36f0f27 100644 --- a/src/EntraModuleBuilder.ps1 +++ b/src/EntraModuleBuilder.ps1 @@ -77,11 +77,27 @@ Set-StrictMode -Version 5 Log-Message "[EntraModuleBuilder] Creating .psm1 file: $psm1FilePath" $psm1Content = $this.headerText + "`n" # Add a newline after the header + $ps1xmlContent = "" # Xml content to be appended later # Get-ChildItem returns different types depending on the number of items it finds. - # When there is only one item, it returns a single object rather than an array - # Using @() we force the result to be treated as an array, even if there is only one item. - $ps1Files = @(Get-ChildItem -Path $currentDirPath -Filter "*.ps1") + $ps1Files = @(Get-ChildItem -Path $currentDirPath -Include "*.ps1" -Recurse:$true) + + $ps1xmlFiles = @(Get-ChildItem -Path $currentDirPath -Filter "*.format.ps1xml") + if ($ps1xmlFiles.Count -gt 0) { + foreach ($ps1xmlFile in $ps1xmlFiles) { + Log-Message "[EntraModuleBuilder] Appending formmatting content from file: $($ps1xmlFile.Name)" -ForegroundColor Cyan + $ps1xmlContent = Get-Content -Path $ps1xmlFile.FullName -Raw + + $ps1xmlFilePath = Join-Path -Path $destDirectory -ChildPath $ps1xmlFile.Name + Log-Message "[EntraModuleBuilder] Writing .ps1xml file to disk: $ps1xmlFilePath" + + # Use UTF-8 with BOM for PowerShell 5.1 compatibility + $utf8WithBom = New-Object System.Text.UTF8Encoding($true) + [System.IO.File]::WriteAllText($ps1xmlFilePath, $ps1xmlContent, $utf8WithBom) + + Log-Message "[EntraModuleBuilder] Module Formating file created: $ps1xmlFilePath" -Level 'SUCCESS' + } + } if ($ps1Files.Count -eq 0) { Log-Message "[EntraModuleBuilder] Warning: No .ps1 files found in directory $currentDirPath" -Level 'ERROR' @@ -237,8 +253,6 @@ Set-StrictMode -Version 5 } } - - # Main function to create the root module [void] CreateRootModule([string] $Module) { #We only generate the .psm1 file with Enable-EntraAzureADAlias if it's 'Microsoft.Entra' module @@ -499,10 +513,15 @@ $($requiredModulesEntries -join ",`n") exit } - # Get all files in the specified directory and its subdirectories, without extensions - $allFunctions = @(Get-ChildItem -Path $subDir.FullName -Recurse -File | ForEach-Object { $_.BaseName }) + # Get all files in the specified directory and its subdirectories + $allFiles = @(Get-ChildItem -Path $subDir.FullName -Recurse -File) + $filteredFunctions = $allFiles | Where-Object { $_.Extension -eq ".ps1"} + $functions = @($filteredFunctions | ForEach-Object { $_.BaseName }) + "Enable-EntraAzureADAlias" + "Get-EntraUnsupportedCommand" - $functions = $allFunctions + "Enable-EntraAzureADAlias" + "Get-EntraUnsupportedCommand" + # Get formatting file for submodule + $filteredFormattingFiles = $allFiles | Where-Object { $_.Extension -eq ".ps1xml"} + $formattingFiles = @($filteredFormattingFiles | ForEach-Object { $_.Name }) + #QuickFix: TODO: Generalize to use this with any sub-module, by auto-extracting the alias $aliasesToExport = $this.ExtractSubModuleAliases($subDir.FullName, $moduleName) @@ -536,7 +555,7 @@ $($requiredModulesEntries -join ",`n") AliasesToExport = $aliasesToExport Author = $($content.authors) CompanyName = $($content.owners) - FileList = @("$manifestFileName", "$moduleFileName", "$helpFileName") + FileList = @("$manifestFileName", "$moduleFileName", "$helpFileName", "$formattingFiles") RootModule = "$moduleFileName" Description = $content.moduleName DotNetFrameworkVersion = $([System.Version]::Parse($content.dotNetVersion)) @@ -544,6 +563,7 @@ $($requiredModulesEntries -join ",`n") CompatiblePSEditions = @('Desktop', 'Core') RequiredModules = $requiredModules NestedModules = @() + FormatsToProcess = $formattingFiles }