From e6237245287fdf8df7ec014e67f0188a5590a167 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jul 2022 11:15:42 -0700 Subject: [PATCH 1/5] Publish packages from AppVeyor, not Whiskey. --- appveyor.yml | 66 +++++++++++++++++++++++++++++++------------------ whiskey.yml | 69 +++++++++++++++++++++------------------------------- 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index bbafa68..1059af1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,39 +1,59 @@ -version: 0.0.{build} +version: 0.0.0+{build} skip_tags: true skip_branch_with_pr: true -image: -- Visual Studio 2015 -- Visual Studio 2017 -- Visual Studio 2019 -- Ubuntu -- macOS - build: verbosity: minimal -build_script: -- pwsh: .\build.ps1 -Verbose +environment: + WHISKEY_DISABLE_ERROR_FORMAT: True + matrix: + - job_name: .NET 4.6.2 + job_group: ps + appveyor_build_worker_image: Visual Studio 2013 + + - job_name: Windows PowerShell 5.1 on Windows Server 2012R2 + job_group: ps + appveyor_build_worker_image: Visual Studio 2015 + + - job_name: PowerShell 6 on Windows Server 2012R2 + job_group: pwsh + appveyor_build_worker_image: Visual Studio 2015 + + - job_name: Windows PowerShell 5.1 on Windows Server 2016 + job_group: ps + appveyor_build_worker_image: Visual Studio 2017 + + - job_name: PowerShell 6 on Windows Server 2016 + job_group: pwsh + appveyor_build_worker_image: Visual Studio 2017 + + - job_name: Windows PowerShell 5.1 on Windows Server 2019 + job_group: ps + appveyor_build_worker_image: Visual Studio 2019 + + - job_name: PowerShell 7 on Windows Server 2019 + job_group: pwsh + appveyor_build_worker_image: Visual Studio 2019 + + +artifacts: +- path: .output\* + for: +# Build in Windows PowerShell - matrix: only: - - image: Visual Studio 2015 - - image: Visual Studio 2017 + - job_group: ps build_script: - - ps: .\build.ps1 -Verbose - - pwsh: .\build.ps1 -Verbose + - ps: .\build.ps1 +# Build in PowerShell - matrix: only: - - image: Ubuntu - environment: - LANG: us_US.UTF-8 - -- matrix: - only: - - image: Visual Studio 2019 - environment: - PUBLISH: True + - job_group: pwsh + build_script: + - pwsh: ./build.ps1 diff --git a/whiskey.yml b/whiskey.yml index ab955aa..eeb7699 100644 --- a/whiskey.yml +++ b/whiskey.yml @@ -1,11 +1,14 @@ -PublishOn: -- main -- prerelease - Build: - Version: Path: Carbon.Core\Carbon.Core.psd1 + Prerelease: + - "*/*": alpha$(WHISKEY_BUILD_NUMBER) + - develop: rc$(WHISKEY_BUILD_NUMBER) +- Exec: + OnlyBy: BuildServer + Path: appveyor + Argument: [ UpdateBuild, -Version, "$(WHISKEY_SEMVER2)+$(WHISKEY_BUILD_NUMBER)" ] # Dot-sourcing files is expensive. Move all functions into your .psm1 file to # improve import speed. Do this before testing to ensure your module still # works. @@ -22,6 +25,7 @@ Build: Path: - LICENSE - NOTICE + - README.md DestinationDirectory: Carbon.Core # Needed to install test users. - GetPowerShellModule: @@ -33,46 +37,29 @@ Build: - PowerShell: OnlyDuring: Clean Path: reset.ps1 -- Pester4: - Script: Tests\*.Tests.ps1 + +- PublishPowerShellModule: + Path: Carbon.Core +- Exec: + OnlyBy: BuildServer + Path: appveyor + Argument: [ + 'PushArtifact', + '.output/Carbon.Core.$(WHISKEY_SEMVER2_NO_BUILD_METADATA).nupkg', + '-DeploymentName', + 'PowerShellGallery' + ] + - Delete: Path: .output\*.zip - Zip: - ArchivePath: .output\Carbon.Core.zip + ArchivePath: .output\Carbon.Core-$(WHISKEY_SEMVER2).zip Path: - Carbon.Core +- Exec: + OnlyBy: BuildServer + Path: appveyor + Argument: [ 'PushArtifact', '.output/Carbon.Core-$(WHISKEY_SEMVER2).zip', '-DeploymentName', 'GitHub' ] -Publish: -- AppVeyorWaitForBuildJobs: - IfExists: env:PUBLISH - UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER - ApiKeyID: AppVeyorBearerToken - -- PublishPowerShellModule: - IfExists: env:PUBLISH - UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER - RepositoryName: PSGallery - RepositoryUri: https://powershellgallery.com/api/v2/ - Path: Carbon.Core - ApiKeyID: PowerShellGalleryApiKey - -- SetVariableFromPowerShellDataFile: - Path: Carbon.Core\Carbon.Core.psd1 - Variables: - PrivateData: - PSData: - ReleaseNotes: RELEASE_NOTES - -- GitHubRelease: - IfExists: env:PUBLISH - UnlessExists: env:APPVEYOR_PULL_REQUEST_NUMBER - RepositoryName: webmd-health-services/Carbon.Core - ApiKeyID: GitHubAccessToken - Tag: $(WHISKEY_SEMVER2_NO_BUILD_METADATA) - Commitish: $(WHISKEY_SCM_COMMIT_ID) - Name: $(WHISKEY_SEMVER2_NO_BUILD_METADATA) - Description: $(RELEASE_NOTES) - Assets: - - Path: .output\Carbon.Core.zip - ContentType: application/zip - Name: Carbon.Core-$(WHISKEY_SEMVER2_NO_BUILD_METADATA).zip \ No newline at end of file +- Pester4: + Script: Tests\*.Tests.ps1 From 8eac754618428e85483bdce63c9ec51966d2f904 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jul 2022 11:17:58 -0700 Subject: [PATCH 2/5] Release notes should be in a CHANGELOG.md file. --- CHANGELOG.md | 55 +++++++++++++++++++++++++++++++++ Carbon.Core/Carbon.Core.psd1 | 59 ++---------------------------------- whiskey.yml | 1 + 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9166c3a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,55 @@ + +# 1.0.0 + +## Upgrade Instructions + +We're breaking up Carbon into smaller and more targeted modules. Hopefully, this will help maintenance, and make it +easier to use Carbon across many versions and editions of PowerShell. This module will be the place where core functions +used by other Carbon modules will be put. + +If you're upgrading from Carbon to this module, you should do the following: + +* Replace usages of `Test-COSIs64Bit` with `Test-COperatingSystem -Is64Bit`. +* Replace usages of `Test-COSIs32Bit` with `Test-COperatingSystem -Is32Bit`. +* Replace usages of `Test-CPowerShellIs32Bit` with `Test-CPowerShell -Is32Bit`. +* Replace usages of `Test-CPowerShellIs64Bit` with `Test-CPowerShell -Is64Bit`. +* Rename usages of the `ConvertTo-CBase64` function's `Value` parameter to `InputObject`, or pipe the value to the +function instead. + +We made a lot of changes to the `Invoke-CPowerShell` function: + +* The `Invoke-CPowerShell` function no longer allows you to pass script blocks. Instead, convert your script block to +a string, and pass that string to the `Command` parameter. This will base64 encode the command and pass it to +PowerShell's -EncodedCommand property. +* The `Invoke-CPowerShell` function no longer has `FilePath`, `OutputFormat`, `ExecutionPolicy`, `NonInteractive`, +or `Runtime` parameters. Instead, pass these as arguments to the `ArgumentList` parameter, e.g. +`-ArgumentList @('-NonInteractive', '-ExecutionPolicy', 'Bypasss'). You are now responsible for passing all PowerShell +arguments via the `ArgumentList` parameter. +* The `Invoke-CPowerShell` function no longer supports running PowerShell 2 under .NET 4. +* Remove the `-Encode` switch. `Invoke-CPowerShell` now always base64 encodes the value of the `Command` parameter. +* The `Invoke-CPowerShell` function only accepts strings to the `-Command` parameter. Check all usages to ensure you're +passing a string. +* The `Invoke-CPowerShell` function now returns output when running PowerShell as a different user. You may see more +output in your scripts. + + +## Changes Since Carbon 2.9.4 + +* Migrated `Invoke-CPowerShell` and `ConvertTo-CBase64` from Carbon. +* `ConvertTo-CBase64` now converts chars, ints (signed and unsigned, 16, 32, and 64-bit sizes), floats, and doubles to +base64. You can now also pipe an array of bytes or chars and it will collect each item in the array and encode them at +as one unit. +* Renamed the `ConvertTo-CBase64` function's `Value` parameter to `InputObject`. +* Created `Test-COperatingSystem` function that can test if the current OS is 32-bit, 62-bit, Windows, Linux, and/or +macOS. This function was adapted from and replaces's Carbon's `Test-COSIs64Bit` and `Test-COSIs32Bit`. +* Created `Test-CPowerShell` function that can test if the current PowerShell instance is 32-bit, 64-bit, Core edition, +or Desktop edition. It treats versions of PowerShell that don't specify a version as "Desktop". This function was +adapted from and replaces Carbon's `Test-CPowerShellIs32Bit` and `Test-CPowerShellIs64Bit` functions. +* `Invoke-CPowerShell` now works on Linux and macOS. On Windows, it will start a new PowerShell process using the same +edition. If you want to use a custom version of PowerShell, pass the path to the PowerShell executable to use to the +new `Path` parameter. + +## Known Issues +* There is a bug in PowerShell Core on Linux/macOS that fails when running `Start-Job` with a custom credential. The +`Invoke-CPowerShell` function will fail when run on Linux/MacOS using a custom credential. See +https://github.com/PowerShell/PowerShell/issues/7172 for more information. \ No newline at end of file diff --git a/Carbon.Core/Carbon.Core.psd1 b/Carbon.Core/Carbon.Core.psd1 index 6f31dab..ae907e4 100644 --- a/Carbon.Core/Carbon.Core.psd1 +++ b/Carbon.Core/Carbon.Core.psd1 @@ -110,8 +110,8 @@ # Tags applied to this module. These help with module discovery in online galleries. Tags = @( 'Carbon', 'Desktop', 'Core', 'encoding', 'convert', 'convertto', 'text', 'base64', 'invoke', 'os', - 'operating-system', 'architecture', 'powershell', 'pwsh', 'runas', 'credential', 'x86', 'x64', - 'windows', 'linux', 'macos' ) + 'operating', 'system', 'architecture', 'powershell', 'pwsh', 'runas', 'credential', 'x86', 'x64', + 'windows', 'linux', 'macos', 'type', 'data', 'update-typedata', 'member', 'add-member' ) # A URL to the license for this module. LicenseUri = 'http://www.apache.org/licenses/LICENSE-2.0' @@ -125,60 +125,7 @@ Prerelease = '' # ReleaseNotes of this module - ReleaseNotes = @' -# Upgrade Instructions - -We're breaking up Carbon into smaller and more targeted modules. Hopefully, this will help maintenance, and make it -easier to use Carbon across many versions and editions of PowerShell. This module will be the place where core functions -used by other Carbon modules will be put. - -If you're upgrading from Carbon to this module, you should do the following: - -* Replace usages of `Test-COSIs64Bit` with `Test-COperatingSystem -Is64Bit`. -* Replace usages of `Test-COSIs32Bit` with `Test-COperatingSystem -Is32Bit`. -* Replace usages of `Test-CPowerShellIs32Bit` with `Test-CPowerShell -Is32Bit`. -* Replace usages of `Test-CPowerShellIs64Bit` with `Test-CPowerShell -Is64Bit`. -* Rename usages of the `ConvertTo-CBase64` function's `Value` parameter to `InputObject`, or pipe the value to the -function instead. - -We made a lot of changes to the `Invoke-CPowerShell` function: - -* The `Invoke-CPowerShell` function no longer allows you to pass script blocks. Instead, convert your script block to -a string, and pass that string to the `Command` parameter. This will base64 encode the command and pass it to -PowerShell's -EncodedCommand property. -* The `Invoke-CPowerShell` function no longer has `FilePath`, `OutputFormat`, `ExecutionPolicy`, `NonInteractive`, -or `Runtime` parameters. Instead, pass these as arguments to the `ArgumentList` parameter, e.g. -`-ArgumentList @('-NonInteractive', '-ExecutionPolicy', 'Bypasss'). You are now responsible for passing all PowerShell -arguments via the `ArgumentList` parameter. -* The `Invoke-CPowerShell` function no longer supports running PowerShell 2 under .NET 4. -* Remove the `-Encode` switch. `Invoke-CPowerShell` now always base64 encodes the value of the `Command` parameter. -* The `Invoke-CPowerShell` function only accepts strings to the `-Command` parameter. Check all usages to ensure you're -passing a string. -* The `Invoke-CPowerShell` function now returns output when running PowerShell as a different user. You may see more -output in your scripts. - - -# Changes Since Carbon 2.9.4 - -* Migrated `Invoke-CPowerShell` and `ConvertTo-CBase64` from Carbon. -* `ConvertTo-CBase64` now converts chars, ints (signed and unsigned, 16, 32, and 64-bit sizes), floats, and doubles to -base64. You can now also pipe an array of bytes or chars and it will collect each item in the array and encode them at -as one unit. -* Renamed the `ConvertTo-CBase64` function's `Value` parameter to `InputObject`. -* Created `Test-COperatingSystem` function that can test if the current OS is 32-bit, 62-bit, Windows, Linux, and/or -macOS. This function was adapted from and replaces's Carbon's `Test-COSIs64Bit` and `Test-COSIs32Bit`. -* Created `Test-CPowerShell` function that can test if the current PowerShell instance is 32-bit, 64-bit, Core edition, -or Desktop edition. It treats versions of PowerShell that don't specify a version as "Desktop". This function was -adapted from and replaces Carbon's `Test-CPowerShellIs32Bit` and `Test-CPowerShellIs64Bit` functions. -* `Invoke-CPowerShell` now works on Linux and macOS. On Windows, it will start a new PowerShell process using the same -edition. If you want to use a custom version of PowerShell, pass the path to the PowerShell executable to use to the -new `Path` parameter. - -# Known Issues -* There is a bug in PowerShell Core on Linux/macOS that fails when running `Start-Job` with a custom credential. The -`Invoke-CPowerShell` function will fail when run on Linux/MacOS using a custom credential. See -https://github.com/PowerShell/PowerShell/issues/7172 for more information. -'@ + ReleaseNotes = 'https://github.com/webmd-health-services/Carbon.Core/blob/main/CHANGELOG.md' } # End of PSData hashtable } # End of PrivateData hashtable diff --git a/whiskey.yml b/whiskey.yml index eeb7699..f0f9748 100644 --- a/whiskey.yml +++ b/whiskey.yml @@ -26,6 +26,7 @@ Build: - LICENSE - NOTICE - README.md + - CHANGELOG.md DestinationDirectory: Carbon.Core # Needed to install test users. - GetPowerShellModule: From 9c6eef2f80a16c0dec8f0f7bd67970056d0aeec4 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jul 2022 11:18:52 -0700 Subject: [PATCH 3/5] Use Prism to manage PowerShell dependencies. --- prism.json | 8 ++++++++ prism.lock.json | 9 +++++++++ whiskey.yml | 10 +++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 prism.json create mode 100644 prism.lock.json diff --git a/prism.json b/prism.json new file mode 100644 index 0000000..8de7aed --- /dev/null +++ b/prism.json @@ -0,0 +1,8 @@ +{ + "PSModules": [ + { + "Name": "Carbon", + "Version": "2.*" + } + ] +} \ No newline at end of file diff --git a/prism.lock.json b/prism.lock.json new file mode 100644 index 0000000..aa142bc --- /dev/null +++ b/prism.lock.json @@ -0,0 +1,9 @@ +{ + "PSModules": [ + { + "name": "Carbon", + "version": "2.11.3", + "repositorySourceLocation": "https://www.powershellgallery.com/api/v2" + } + ] +} \ No newline at end of file diff --git a/whiskey.yml b/whiskey.yml index f0f9748..7bbd749 100644 --- a/whiskey.yml +++ b/whiskey.yml @@ -29,9 +29,13 @@ Build: - CHANGELOG.md DestinationDirectory: Carbon.Core # Needed to install test users. -- GetPowerShellModule: - Name: Carbon - Version: 2.* +- PowerShell: + ScriptBlock: | + if( -not (Get-Module -Name 'Prism' -ListAvailable) ) + { + Find-Module -Name 'Prism' | Select-Object -First 1 | Install-Module -Force + } + prism install | Format-Table -Auto - PowerShell: ExceptDuring: Clean Path: init.ps1 From e220496c3b0cce2f814cc03c1b9c60f769820828 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jul 2022 11:20:02 -0700 Subject: [PATCH 4/5] Migrating Add-CTypeData and Test-CTypeDataMember from Carbon. --- CHANGELOG.md | 10 +- Carbon.Core/Carbon.Core.psd1 | 6 +- Carbon.Core/Functions/Add-CTypeData.ps1 | 115 ++++++++++++++++++ .../Functions/Test-CTypeDataMember.ps1 | 44 +++++++ 4 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 Carbon.Core/Functions/Add-CTypeData.ps1 create mode 100644 Carbon.Core/Functions/Test-CTypeDataMember.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9166c3a..04672e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +# 1.1.0 + +Added `Test-CTypeDataMember` and `Add-CTypeData` functions for testing if a type has any defined custom type data and +adding custom type data, respectively. Defining type data with .ps1xml files can result in errors importing the same +module multiple times: PowerShell complains that the type data is already defined. Using `Add-CTypeData` prevents these +this error as it only adds members that don't already exist. + + # 1.0.0 ## Upgrade Instructions @@ -23,7 +31,7 @@ a string, and pass that string to the `Command` parameter. This will base64 enco PowerShell's -EncodedCommand property. * The `Invoke-CPowerShell` function no longer has `FilePath`, `OutputFormat`, `ExecutionPolicy`, `NonInteractive`, or `Runtime` parameters. Instead, pass these as arguments to the `ArgumentList` parameter, e.g. -`-ArgumentList @('-NonInteractive', '-ExecutionPolicy', 'Bypasss'). You are now responsible for passing all PowerShell +`-ArgumentList @('-NonInteractive', '-ExecutionPolicy', 'Bypasss')`. You are now responsible for passing all PowerShell arguments via the `ArgumentList` parameter. * The `Invoke-CPowerShell` function no longer supports running PowerShell 2 under .NET 4. * Remove the `-Encode` switch. `Invoke-CPowerShell` now always base64 encodes the value of the `Command` parameter. diff --git a/Carbon.Core/Carbon.Core.psd1 b/Carbon.Core/Carbon.Core.psd1 index ae907e4..40bc607 100644 --- a/Carbon.Core/Carbon.Core.psd1 +++ b/Carbon.Core/Carbon.Core.psd1 @@ -18,7 +18,7 @@ RootModule = 'Carbon.Core.psm1' # Version number of this module. - ModuleVersion = '1.0.0' + ModuleVersion = '1.1.0' # ID used to uniquely identify this module GUID = '20DA9F42-23C4-4917-8597-DCFD7EE4AD00' @@ -76,12 +76,14 @@ # Functions to export from this module. Only list public function here. FunctionsToExport = @( + 'Add-CTypeData', 'ConvertTo-CBase64', 'Get-CPowerShellPath', 'Invoke-CPowerShell', 'Start-CPowerShellProcess', 'Test-COperatingSystem', - 'Test-CPowerShell' + 'Test-CPowerShell', + 'Test-CTypeDataMember' ) # Cmdlets to export from this module. By default, you get a script module, so there are no cmdlets. diff --git a/Carbon.Core/Functions/Add-CTypeData.ps1 b/Carbon.Core/Functions/Add-CTypeData.ps1 new file mode 100644 index 0000000..55ffdbe --- /dev/null +++ b/Carbon.Core/Functions/Add-CTypeData.ps1 @@ -0,0 +1,115 @@ +function Add-CTypeData +{ + <# + .SYNOPSIS + Adds type data to a type only if the type data doesn't already exist. + + .DESCRIPTION + The `Add-CTypeData` function uses PowerShell's `Update-TypeData` cmdlet to add type data to a type, but only if the + given type data doesn't already exist. Pass the type to the `Type` parameter or the type name to the `TypeName` + parameter, the new type data member type to the `MemberType` parameter (e.g. `AliasProperty`, `NoteProperty`, + `ScriptProperty`, or `ScriptMethod`), the member name to the `MemberName` parameter, and the member's + value/implementation to the `Value` parameter. + + Note that the `Type` parameter should be the bare name of the type, e.g. `Diagnostics.Process`, *without* square + brackets. + + If the type already has an equivalent member with the name given by the `MemberName` parameter, nothing happens, and + the function returns. + + .EXAMPLE + Add-CTypeData -Type Diagnostics.Process -MemberType ScriptProperty -MemberName 'ParentID' -Value $scriptBlock + + Demonstrates how to create a script property on a type. In this example, the `System.Diagnostics.Process` type will + be given a `ParentID` property that runs the code in the script block in the `$scriptBlock` variable. + + .EXAMPLE + Add-CTypeData -Type Diagnostics.Process -MemberType ScriptMethod -MemberName 'GetParentID()' -Value $scriptBlock + + Demonstrates how to create a script method on a type. In this example, the `System.Diagnostics.Process` type will + be given a `GetParentID()` method that runs the code in the script block in the `$scriptBlock` variable. + + .EXAMPLE + Add-CTypeData -Type Diagnostics.Process -MemberType AliasProperty -MemberName 'ProcessId' -Value 'Id' + + Demonstrates how to create an alias script property on a type. In this example, the `System.Diagnostics.Process` + type will be given a `ProcessId` property that is an alias to the 'Id' property. + + .EXAMPLE + Add-CTypeData -Type Diagnostics.Process -MemberType NoteProperty -MemberName 'ParentID' -Value $parentPid + + Demonstrates how to create a ntoe property on a type. In this example, the `System.Diagnostics.Process` type will + be given a `ParentID` property that returns the value in the `$parentPid` variable. + #> + [CmdletBinding()] + param( + # The type on which to add the type data. This should be the bare type name, e.g. Diagnostics.Process, *not* + # the type surrounded by square brackets, e.g. `[Diagnostics.Process]`. + [Parameter(Mandatory, ParameterSetName='ByType')] + [Type] $Type, + + # The name of the type on which to add the type data. + [Parameter(Mandatory, ParameterSetName='ByTypeName')] + [String] $TypeName, + + # The member type of the new type data. Only `AliasProperty`, `NoteProperty`, `ScriptProperty`, `ScriptMethod` + # are supported. + [Parameter(Mandatory)] + [ValidateSet('AliasProperty', 'NoteProperty', 'ScriptProperty', 'ScriptMethod')] + [Management.Automation.PSMemberTypes] $MemberType, + + # The type data's member name. + [Parameter(Mandatory)] + [String] $MemberName, + + # The value for the member. If `MemberName` is: + # + # * `AliasProperty`, this should be the name of the target property. + # * `NoteProperty`, the literal value of the property. + # * `ScriptProperty`, a script block that return's the property value. + # * `ScriptMethod`, a script block that implements the method logic. + [Parameter(Mandatory)] + [Object] $Value + ) + + Set-StrictMode -Version 'Latest' + Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState + + $memberTypeMsg = '{0,-14}' -f $MemberType + + if( -not $TypeName ) + { + $TypeName = $Type.FullName + } + + if( $Type ) + { + if( $MemberType -like '*Property' ) + { + if( ($Type.GetProperties() | Where-Object Name -EQ $MemberName) ) + { + Write-Debug ("Type $($memberTypeMsg) [$($TypeName)] $($MemberName)") + return + } + } + elseif( $MemberType -like '*Method') + { + if( ($Type.GetMethods() | Where-Object Name -EQ $MemberName) ) + { + Write-Debug ("Type $($memberTypeMsg) [$($TypeName)] $($MemberName)") + return + } + } + } + + $typeData = Get-TypeData -TypeName $TypeName + if( $typeData -and $typeData.Members.ContainsKey($MemberName) ) + { + Write-Debug ("TypeData $($memberTypeMsg) [$($TypeName)] $($MemberName)") + return + } + + Write-Debug ("TypeData + $($memberTypeMsg) [$($TypeName)] $($MemberName)") + Update-TypeData -TypeName $TypeName -MemberType $MemberType -MemberName $MemberName -Value $Value +} + diff --git a/Carbon.Core/Functions/Test-CTypeDataMember.ps1 b/Carbon.Core/Functions/Test-CTypeDataMember.ps1 new file mode 100644 index 0000000..0bf6332 --- /dev/null +++ b/Carbon.Core/Functions/Test-CTypeDataMember.ps1 @@ -0,0 +1,44 @@ + +function Test-CTypeDataMember +{ + <# + .SYNOPSIS + Tests if a type has an extended type member defined. + + .DESCRIPTION + `Test-CTypeDataMember` tests if a type has an extended type member defined. If the type isn't found, you'll get an + error. + + Returns `$true` if the type is found and the member is defined. Otherwise, returns `$false`. + + .EXAMPLE + Test-CTypeDataMember -TypeName 'Microsoft.Web.Administration.Site' -MemberName 'PhysicalPath' + + Tests if the `Microsoft.Web.Administration.Site` type has a `PhysicalPath` extended type member defined. + #> + [CmdletBinding()] + [OutputType([bool])] + param( + # The type name to check. + [Parameter(Mandatory)] + [String] $TypeName, + + # The name of the member to check. + [Parameter(Mandatory)] + [String] $MemberName + ) + + Set-StrictMode -Version 'Latest' + Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState + + $typeData = Get-TypeData -TypeName $TypeName + if( -not $typeData ) + { + # The type isn't defined or there is no extended type data on it. + return $false + } + + return $typeData.Members.ContainsKey( $MemberName ) +} + + From 3cba2286613f1f8cf132ecefec4b159f4c65e617 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jul 2022 11:43:06 -0700 Subject: [PATCH 5/5] Password not complex enough. --- init.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.ps1 b/init.ps1 index 32d6742..f2b345a 100644 --- a/init.ps1 +++ b/init.ps1 @@ -22,7 +22,8 @@ if( -not (Test-Path -Path $passwordPath) ) $password = [Convert]::ToBase64String($randomBytes) } # Password needs to contain uppercase letter, lowercase letter, and a number. - while( $password -cnotmatch '[A-Z]' -and $password -cnotmatch '[a-z]' -and $password -notmatch '\d' ) + while( $password -cnotmatch '[A-Z]' -and $password -cnotmatch '[a-z]' -and $password -notmatch '\d' -and ` + $password -notmatch ([regex]::Escape('`~!@#$%^&*()_+-=[]\{}|;'':",./<>?')) ) $password | Set-Content -Path $passwordPath Write-Verbose -Message ('Generating IV for encrypting test account password on Linux.')