Skip to content

Commit

Permalink
Merge pull request #47 from AzureAD/preview
Browse files Browse the repository at this point in the history
Promote Preview
  • Loading branch information
cblomart authored May 19, 2022
2 parents c2abb95 + c3c1361 commit e1fbadd
Show file tree
Hide file tree
Showing 31 changed files with 1,179 additions and 442 deletions.
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-vscode.powershell"
]
}
17 changes: 11 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
"type": "PowerShell",
"request": "launch",
"preLaunchTask": "",
"script": "${workspaceRoot}/Launch-PSModule.ps1",
"script": "${workspaceRoot}/build/Launch-PSModule.ps1",
"cwd": "${workspaceRoot}",
"args":[
"-ModuleManifestPath './src/*.psd1'",
"-NoNewWindow"
]
},
{
"name": "PowerShell Launch Module and Connect",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceRoot}/Launch-PSModule.ps1",
"script": "${workspaceRoot}/build/Launch-PSModule.ps1",
"cwd": "${workspaceRoot}",
"args": [
"-ModuleManifestPath './src/*.psd1'",
"-PostImportScriptBlock { New-MsalClientApplication -ClientId c62a9fcb-53bf-446e-8063-ea6e2bfcc023 -RedirectUri 'http://localhost' | Enable-MsalTokenCacheOnDisk -PassThru | Connect-AADAssessment }",
"-NoNewWindow"
]
Expand All @@ -30,9 +32,10 @@
"name": "PowerShell Launch Module, Connect, and Current Function",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceRoot}/Launch-PSModule.ps1",
"script": "${workspaceRoot}/build/Launch-PSModule.ps1",
"cwd": "${workspaceRoot}",
"args": [
"-ModuleManifestPath './src/*.psd1'",
"-PostImportScriptBlock { New-MsalClientApplication -ClientId c62a9fcb-53bf-446e-8063-ea6e2bfcc023 -RedirectUri 'http://localhost' | Enable-MsalTokenCacheOnDisk -PassThru | Connect-AADAssessment; ${fileBasenameNoExtension} }",
"-NoNewWindow"
]
Expand All @@ -41,9 +44,10 @@
"name": "PowerShell Launch Module and Connect in New External Console",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceRoot}/Launch-PSModule.ps1",
"script": "${workspaceRoot}/build/Launch-PSModule.ps1",
"cwd": "${workspaceRoot}",
"args": [
"-ModuleManifestPath './src/*.psd1'",
"-PostImportScriptBlock { New-MsalClientApplication -ClientId c62a9fcb-53bf-446e-8063-ea6e2bfcc023 -RedirectUri 'http://localhost' | Enable-MsalTokenCacheOnDisk -PassThru | Connect-AADAssessment }",
"-PowerShellPaths 'powershell'",
"-NoNewWindow:$false"
Expand All @@ -54,9 +58,10 @@
"type": "PowerShell",
"request": "launch",
"preLaunchTask": "",
"script": "${workspaceRoot}/Launch-PSModule.ps1",
"script": "${workspaceRoot}/build/Launch-PSModule.ps1",
"cwd": "${workspaceRoot}",
"args": [
"-ModuleManifestPath './src/*.psd1'",
"-PowerShellPaths 'pwsh','powershell'",
"-NoNewWindow:$false"
]
Expand All @@ -75,4 +80,4 @@
"runspaceId": 1
}
]
}
}
24 changes: 24 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// PowerShell Code Formatting
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
"powershell.codeFormatting.alignPropertyValuePairs": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.openBraceOnSameLine": true,
"powershell.codeFormatting.pipelineIndentationStyle": "NoIndentation",
"powershell.codeFormatting.preset": "Stroustrup",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
//"powershell.codeFormatting.useConstantStrings": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceAfterSeparator": true,
"powershell.codeFormatting.whitespaceAroundOperator": true,
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.codeFormatting.whitespaceInsideBrace": true

// Editor Settings
//"editor.formatOnSave": true,
//"editor.formatOnSaveMode": "modificationsIfAvailable"
}
Binary file modified assets/AzureADAssessment-ConditionalAccess.pbit
Binary file not shown.
Binary file removed assets/AzureADAssessment-PowerShell.pbit
Binary file not shown.
Binary file modified assets/AzureADAssessment.pbit
Binary file not shown.
80 changes: 40 additions & 40 deletions Launch-PSModule.ps1 → build/Launch-PSModule.ps1
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
param
(
# Module to Launch
[Parameter(Mandatory = $false)]
[string] $ModuleManifestPath = ".\src\*.psd1",
# ScriptBlock to Execute After Module Import
[Parameter(Mandatory = $false)]
[scriptblock] $PostImportScriptBlock,
# Paths to PowerShell Executables
[Parameter(Mandatory = $false)]
[string[]] $PowerShellPaths = @(
'pwsh'
'powershell'
),
# Import Module into the same session
[Parameter(Mandatory = $false)]
[switch] $NoNewWindow #= $true
)

if ($NoNewWindow) {
Import-Module $ModuleManifestPath -PassThru -Force
if ($PostImportScriptBlock) { Invoke-Command -ScriptBlock $PostImportScriptBlock -NoNewScope }
}
else {
[scriptblock] $ScriptBlock = {
param ([string]$ModulePath, [scriptblock]$PostImportScriptBlock)
## Force WindowsPowerShell to load correct version of built-in modules when launched from PowerShell 6+
if ($PSVersionTable.PSEdition -eq 'Desktop') { Import-Module 'Microsoft.PowerShell.Management', 'Microsoft.PowerShell.Utility', 'CimCmdlets' -MaximumVersion 5.9.9.9 }
Import-Module $ModulePath -PassThru -ArgumentList @{
'ai.instrumentationKey' = 'f7c43a96-9493-41e3-ad62-4320f5835ce2'
}
Invoke-Command -ScriptBlock $PostImportScriptBlock -NoNewScope
}
$strScriptBlock = 'Invoke-Command -ScriptBlock {{ {0} }} -ArgumentList {1}, {{ {2} }}' -f $ScriptBlock, $ModuleManifestPath, $PostImportScriptBlock
#$strScriptBlock = 'Import-Module {0} -PassThru' -f $ModuleManifestPath

foreach ($Path in $PowerShellPaths) {
Start-Process $Path -ArgumentList ('-NoExit', '-NoProfile', '-EncodedCommand', [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($strScriptBlock)))
}
}
param
(
# Module to Launch
[Parameter(Mandatory = $false)]
[string] $ModuleManifestPath = ".\src\*.psd1",
# ScriptBlock to Execute After Module Import
[Parameter(Mandatory = $false)]
[scriptblock] $PostImportScriptBlock,
# Paths to PowerShell Executables
[Parameter(Mandatory = $false)]
[string[]] $PowerShellPaths = @(
'pwsh'
'powershell'
),
# Import Module into the same session
[Parameter(Mandatory = $false)]
[switch] $NoNewWindow #= $true
)

if ($NoNewWindow) {
Import-Module $ModuleManifestPath -PassThru -Force
if ($PostImportScriptBlock) { Invoke-Command -ScriptBlock $PostImportScriptBlock -NoNewScope }
}
else {
[scriptblock] $ScriptBlock = {
param ([string]$ModulePath, [scriptblock]$PostImportScriptBlock)
## Force WindowsPowerShell to load correct version of built-in modules when launched from PowerShell 6+
if ($PSVersionTable.PSEdition -eq 'Desktop') { Import-Module 'Microsoft.PowerShell.Management', 'Microsoft.PowerShell.Utility', 'CimCmdlets' -MaximumVersion 5.9.9.9 }
Import-Module $ModulePath -PassThru -ArgumentList @{
'ai.instrumentationKey' = 'f7c43a96-9493-41e3-ad62-4320f5835ce2'
}
Invoke-Command -ScriptBlock $PostImportScriptBlock -NoNewScope
}
$strScriptBlock = 'Invoke-Command -ScriptBlock {{ {0} }} -ArgumentList {1}, {{ {2} }}' -f $ScriptBlock, $ModuleManifestPath, $PostImportScriptBlock
#$strScriptBlock = 'Import-Module {0} -PassThru' -f $ModuleManifestPath

foreach ($Path in $PowerShellPaths) {
Start-Process $Path -ArgumentList ('-NoExit', '-NoProfile', '-EncodedCommand', [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($strScriptBlock)))
}
}
3 changes: 2 additions & 1 deletion build/Update-PSModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ if ($Prerelease) { $paramUpdateModuleManifest['Prerelease'] = $Prerelease }

## Read Module Manifest
$ModuleManifest = Import-PowerShellDataFile $ModuleManifestFileInfo.FullName
$paramUpdateModuleManifest['NestedModules'] = $ModuleManifest.NestedModules
if ($ModuleManifest.NestedModules) { $paramUpdateModuleManifest['NestedModules'] = $ModuleManifest.NestedModules }
$paramUpdateModuleManifest['FunctionsToExport'] = $ModuleManifest.FunctionsToExport
$paramUpdateModuleManifest['CmdletsToExport'] = $ModuleManifest.CmdletsToExport
$paramUpdateModuleManifest['AliasesToExport'] = $ModuleManifest.AliasesToExport
[System.IO.DirectoryInfo] $ModuleOutputDirectoryInfo = $ModuleManifestFileInfo.Directory
Expand Down
12 changes: 11 additions & 1 deletion build/azure-pipelines/azure-pipelines-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ stages:
Path: '$(Pipeline.Workspace)/CI/$(artifactModule)'
Settings: 'required'
Recurse: true

- task: ManifestGeneratorTask@0
inputs:
BuildDropPath: '$(Pipeline.Workspace)/CI/$(artifactModule)'
- task: PublishPipelineArtifact@1
displayName: 'Publish PowerShell Module Artifact'
inputs:
targetPath: '$(Pipeline.Workspace)/CI/$(artifactModule)'
artifact: '$(artifactModule)'
publishLocation: 'pipeline'

- job: Sign
dependsOn:
- Prepare
Expand All @@ -75,6 +84,7 @@ stages:
parameters:
moduleName: '$(moduleName)'
pipelineId: 'CI'
EsrpCodeSigningServiceName: 'ESRP - MSFT Identity - Community Projects'

- stage: Package
displayName: 'Standalone Package'
Expand Down
9 changes: 9 additions & 0 deletions build/azure-pipelines/template-psmodule-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ parameters:
- name: artifactOutput
type: string
default: 'PSModule'
- name: GenerateManifest
type: boolean
default: false

steps:
- task: CopyFiles@2
Expand Down Expand Up @@ -81,6 +84,12 @@ steps:
arguments: '-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.artifactOutput }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}/${{ coalesce(parameters.moduleRename,parameters.moduleName) }}.psd1" -Guid "${{ parameters.moduleGuid }}" -ModuleVersion "${{ parameters.moduleVersion }}" -Prerelease "${{ parameters.prereleaseTag }}" -SkipRequiredAssemblies'
pwsh: true

- ${{ if parameters.GenerateManifest }}:
- task: ManifestGeneratorTask@0
displayName: 'Generate Software Bill of Materials (SBOM)'
inputs:
BuildDropPath: '$(Pipeline.Workspace)/${{ parameters.artifactOutput }}'

- task: PublishPipelineArtifact@1
displayName: 'Publish PowerShell Module Artifact'
inputs:
Expand Down
6 changes: 5 additions & 1 deletion build/azure-pipelines/template-psmodule-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ steps:
displayName: 'Publish PowerShell Module'
inputs:
filePath: '$(System.DefaultWorkingDirectory)/build/Publish-PSModule.ps1'
arguments: '-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.pipelineId }}/${{ parameters.artifactInput }}/${{ parameters.moduleName }}" -RepositorySourceLocation ${{ parameters.RepositorySourceLocation }} -NuGetApiKey (ConvertTo-SecureString "$(${{ parameters.NuGetApiKeySecretName }})" -AsPlainText) -Unlist:$${{ parameters.Unlist }}'
arguments: >
-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.pipelineId }}/${{ parameters.artifactInput }}/${{ parameters.moduleName }}"
-RepositorySourceLocation ${{ parameters.RepositorySourceLocation }}
-NuGetApiKey (ConvertTo-SecureString "$(${{ parameters.NuGetApiKeySecretName }})" -AsPlainText)
-Unlist:$${{ parameters.Unlist }}
pwsh: true
11 changes: 9 additions & 2 deletions build/azure-pipelines/template-psmodule-sign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ parameters:
default:

steps:
- ${{ if eq(coalesce(parameters.SigningCertificateSecretName, parameters.EsrpCodeSigningServiceName, ''),'') }}:
- pwsh: 'exit 1'
displayName: 'Required Template Parameter Error'

#- download: none
- checkout: self

Expand All @@ -53,7 +57,10 @@ steps:
displayName: 'Sign PowerShell Module Files'
inputs:
filePath: '$(System.DefaultWorkingDirectory)/build/Sign-PSModule.ps1'
arguments: '-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.artifactOutput }}/*" -SigningCertificate "$(${{ parameters.SigningCertificateSecretName }})" -AddCatalogFile'
arguments: >
-ModuleManifestPath "$(Pipeline.Workspace)/${{ parameters.artifactOutput }}/*"
-SigningCertificate "$(${{ parameters.SigningCertificateSecretName }})"
-AddCatalogFile
pwsh: true

- ${{ if ne(parameters.EsrpCodeSigningServiceName,'') }}:
Expand All @@ -62,7 +69,7 @@ steps:
inputs:
ConnectedServiceName: '${{ parameters.EsrpCodeSigningServiceName }}'
FolderPath: '$(Pipeline.Workspace)/${{ parameters.artifactOutput }}'
Pattern: '*.psd1,*.psm1,*.ps1'
Pattern: '*.psd1,*.psm1,*.ps1*'
signConfigType: inlineSignParams
inlineOperation: >-
[
Expand Down
Loading

0 comments on commit e1fbadd

Please sign in to comment.