Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.11.3 (master) -> 2.12.0 (develop) #122

Merged
merged 14 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/Carbon/bin/coreclr
/Carbon/bin/fullclr
/Carbon/*.md
**/obj/**
**/.vs/**
Source/**/bin/**
Expand Down Expand Up @@ -27,4 +28,5 @@ Carbon/LICENSE.txt
Carbon/NOTICE.txt
*.orig
/.vscode/**
/.dotnet*
/.dotnet*
/global.json
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
# 2.12.0

* Fixed: Importing Carbon fails under PowerShell 4.
* The `Install-CMsi`, `Get-CMsi`, and `Get-CProgramInstallInfo` functions have moved to a new `Carbon.Windows.Installer`
module, now available on the PowerShell Gallery. Please switch to the new module and update usages. If you use these
functions from Carbon, a warning message will be written. These function will be removed in the next major version of
Carbon.


# 2.11.3

* Fixed: Carbon doesn't load Microsoft.Web.Administration assembly on PowerShell 7+.


# 2.11.2

* Fixed: `Carbon.Firewall.Rule` type missing the `LocalIP` and `RemoteIP` properties (which are aliases for the
`LocalIpAddress` and `RemoteIPAddress` properties, respectively).


# 2.11.1

* Fixed: Carbon fails to import multiple times in the same session.
* Fixed: Carbon fails when used as a nested module and Carbon is loaded globally or by nested in another module.
* Fixed: Importing Carbon fails under PowerShell 4.


# 2.11.0

* Fixed: Resolve-CPathCase fails on PowerShell Core.
Expand Down
9 changes: 7 additions & 2 deletions Carbon.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@

All functions are idempotent: when run multiple times with the same arguments, your system will be in the same state without failing or producing errors.</description>
<language>en-us</language>
<releaseNotes>$ReleaseNotes$</releaseNotes>
<releaseNotes>https://github.com/webmd-health-services/Carbon/blob/master/CHANGELOG.md</releaseNotes>
<copyright>Aaron Jensen and WebMD Health Services</copyright>
<tags>$Tags$</tags>
<tags>.net, acl, active-directory, certificates, com, compression, computer, credential, cryptography, directory,
dsc, dsc-resources, encryption, environment, file-system, firewall, groups, hosts-file, http, identity, iis, ini,
installers, internet-explorer, ip, junctions, msi, msmq, netsh, networking, ntfs, operating-system, os, path,
performance-counters, powershell, principal, privileges, programs, registry, rsa, scheduled-tasks, security,
service, shares, sid, smb, ssl, text, trusted-host, users, wcf, windows, windows-features, xml, zip, PSModule,
DscResources, setup, automation, admin</tags>
</metadata>
<files>
<file src=".\Carbon\**\*" target="Carbon" exclude="**\*.pdb" />
Expand Down
10 changes: 3 additions & 7 deletions Carbon/Carbon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,9 @@ All functions are idempotent: when run multiple times with the same arguments, y
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @(
'Carbon.types.ps1xml',
'Types\Scheduled.Service.RegisteredTask.types.ps1xml',
'Types\System.IO.DirectoryInfo.types.ps1xml'
'Types\System.IO.FileInfo.types.ps1xml'
'Types\System.ServiceProcess.ServiceController.types.ps1xml'
)
# DO NOT USE! If you import a module twice that has the same type data, you get errors. :( Use Update-TypeData to
# dynamically add extended type data.
# TypesToProcess = @( )

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @(
Expand Down
130 changes: 120 additions & 10 deletions Carbon/Carbon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,43 @@ if( $IsPSCore )
$carbonAssemblyDir = Join-Path -Path $CarbonBinDir -ChildPath 'coreclr' -Resolve
}

function Add-CAssembly
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[String] $Path,

[switch] $PassThru
)

$numErrors = $Global:Error.Count
try
{
Add-Type -Path $Path
if( $PassThru )
{
return $true
}
}
catch
{
$numErrorsToRemove = $Global:Error.Count - $numErrors
for( $idx = 0; $idx -lt $numErrorsToRemove; ++$idx )
{
$Global:Error.RemoveAt(0)
}
if( $PassThru )
{
return $false
}
}
}

Write-Timing ('Loading Carbon assemblies from "{0}".' -f $carbonAssemblyDir)
Get-ChildItem -Path (Join-Path -Path $carbonAssemblyDir -ChildPath '*') -Filter 'Carbon*.dll' -Exclude 'Carbon.Iis.dll' |
ForEach-Object { Add-Type -Path $_.FullName }
$carbonAssembliesPath = Join-Path -Path $carbonAssemblyDir -ChildPath '*'
Get-ChildItem -Path $carbonAssembliesPath -Filter 'Carbon*.dll' -Exclude 'Carbon.Iis.dll' |
ForEach-Object { Add-CAssembly -Path $_.FullName }

# Active Directory

Expand All @@ -67,14 +101,12 @@ if( (Test-Path -Path 'env:SystemRoot') )
if( -not (Test-Path -Path 'env:CARBON_SKIP_IIS_IMPORT') -and `
(Test-Path -Path $microsoftWebAdministrationPath -PathType Leaf) )
{
$exportIisFunctions = $true
if( -not $IsPSCore )
{
Write-Timing ('Adding Microsoft.Web.Administration assembly.')
Add-Type -Path $microsoftWebAdministrationPath
Write-Timing ('Adding Carbon.Iis assembly.')
Add-Type -Path (Join-Path -Path $carbonAssemblyDir -ChildPath 'Carbon.Iis.dll' -Resolve)
}
Write-Timing ('Adding Microsoft.Web.Administration assembly.')
$webAdministrationLoaded = Add-CAssembly -Path $microsoftWebAdministrationPath -PassThru
Write-Timing ('Adding Carbon.Iis assembly.')
$carbonIisAssemblyPath = Join-Path -Path $carbonAssemblyDir -ChildPath 'Carbon.Iis.dll' -Resolve
$carbonIisLoaded = Add-CAssembly -Path $carbonIisAssemblyPath -PassThru
$exportIisFunctions = ($webAdministrationLoaded -and $carbonIisLoaded)
}
}

Expand All @@ -94,6 +126,84 @@ $TrustedHostsPath = 'WSMan:\localhost\Client\TrustedHosts'
Write-Timing ('Adding System.DirectoryServices.AccountManagement assembly.')
Add-Type -AssemblyName 'System.DirectoryServices.AccountManagement'

function Add-CTypeData
{
[CmdletBinding()]
param(
[Parameter(Mandatory, ParameterSetName='ByType')]
[Type] $Type,

[Parameter(Mandatory, ParameterSetName='ByTypeName')]
[String] $TypeName,

[Parameter(Mandatory)]
[ValidateSet('AliasProperty', 'NoteProperty', 'ScriptProperty', 'ScriptMethod')]
[Management.Automation.PSMemberTypes] $MemberType,

[Parameter(Mandatory)]
[String] $MemberName,

[Parameter(Mandatory)]
[Object] $Value
)

Set-StrictMode -Version 'Latest'

$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
}

# Move to Carbon.Core?
Add-CTypeData -Type Diagnostics.Process `
-MemberName 'ParentProcessID' `
-MemberType ScriptProperty `
-Value {
$filter = "ProcessID='{0}'" -f $this.Id
if( (Get-Command -Name 'Get-CimInstance' -ErrorAction Ignore) )
{
$process = Get-CimInstance -ClassName 'Win32_Process' -Filter $filter
}
else
{
$process = Get-WmiObject -Class 'Win32_Process' -Filter $filter
}
return $process.ParentProcessID
}

Write-Timing ('Dot-sourcing functions.')
$functionRoot = Join-Path -Path $PSScriptRoot -ChildPath 'Functions' -Resolve

Expand Down
Loading