├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── Module.PSDeploy.ps1 ├── README.md ├── appveyor.yml ├── build.ps1 ├── build.psm1 ├── psake.ps1 └── src └── PSCoreWindowsCompat ├── PSCoreWindowsCompat.csproj ├── PSCoreWindowsCompat.psd1 └── global.json /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | project.lock.json 4 | *-tests.xml 5 | /debug/ 6 | /staging/ 7 | /Packages/ 8 | *.nuget.props 9 | 10 | # dotnet cli install/uninstall scripts 11 | dotnet-install.ps1 12 | dotnet-install.sh 13 | dotnet-uninstall-pkgs.sh 14 | dotnet-uninstall-debian-packages.sh 15 | 16 | # VS auto-generated solution files for project.json solutions 17 | *.xproj 18 | *.xproj.user 19 | *.suo 20 | 21 | # VS auto-generated files for csproj files 22 | *.csproj.user 23 | 24 | # Visual Studio IDE directory 25 | .vs/ 26 | 27 | # Project Rider IDE files 28 | .idea.powershell/ 29 | 30 | # Ignore executables 31 | *.exe 32 | *.msi 33 | *.appx 34 | 35 | # Ignore binaries and symbols 36 | *.pdb 37 | *.dll 38 | 39 | # Ignore packages 40 | *.deb 41 | *.tar.gz 42 | *.zip 43 | *.rpm 44 | *.pkg 45 | *.nupkg 46 | *.AppImage 47 | 48 | # ignore the telemetry semaphore file 49 | DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY 50 | 51 | # default location for produced nuget packages 52 | /nuget-artifacts 53 | 54 | # resgen output 55 | gen 56 | 57 | # Per repo profile 58 | .profile.ps1 59 | 60 | # macOS 61 | .DS_Store 62 | 63 | # TestsResults 64 | TestsResults*.xml 65 | 66 | # Resharper settings 67 | PowerShell.sln.DotSettings.user 68 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "cSpell.words": [ 4 | "Compat", 5 | "HOMEDRIVE", 6 | "HOMEPATH", 7 | "Interop", 8 | "Odbc", 9 | "Veyor", 10 | "centos", 11 | "nuget", 12 | "opensuse" 13 | ], 14 | 15 | "editor.tabSize": 4, 16 | "editor.insertSpaces": true, 17 | 18 | "files.insertFinalNewline": true, 19 | 20 | // Based on current .markdownlist.json settings: 21 | // https://github.com/PowerShell/PowerShell/blob/master/.markdownlint.json 22 | "markdownlint.config": { 23 | "MD004": false, 24 | "MD024": false, 25 | "MD033": false, 26 | "MD034": false, 27 | "MD038": false, 28 | "MD042": false 29 | }, 30 | 31 | "[powershell]": { 32 | "files.trimTrailingWhitespace": true 33 | }, 34 | 35 | // Sets the codeformatting options to follow the given indent style in a way that is compatible with PowerShell syntax. For more information about the brace styles please refer to https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81. 36 | "powershell.codeFormatting.preset": "Stroustrup", 37 | 38 | // Adds a space between a keyword and its associated scriptblock expression. 39 | "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, 40 | 41 | // Adds a space between a keyword (if, elseif, while, switch, etc) and its associated conditional expression. 42 | "powershell.codeFormatting.whitespaceBeforeOpenParen": true, 43 | 44 | // Adds spaces before and after an operator ('=', '+', '-', etc.). 45 | "powershell.codeFormatting.whitespaceAroundOperator": true, 46 | 47 | // Adds a space after a separator (',' and ';'). 48 | "powershell.codeFormatting.whitespaceAfterSeparator": true 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Mark Kraus 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Module.PSDeploy.ps1: -------------------------------------------------------------------------------- 1 | Deploy Module { 2 | <# 3 | By AppVeyorModule { 4 | FromSource "bin/$ENV:ModuleName" 5 | To AppVeyor 6 | WithOptions @{ 7 | Version = $env:APPVEYOR_BUILD_VERSION 8 | } 9 | } 10 | #> 11 | By PSGalleryModule { 12 | FromSource "bin/$ENV:ModuleName" 13 | To PSGallery 14 | WithOptions @{ 15 | ApiKey = $ENV:NugetApiKey 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PSCoreWindowsCompat 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/9u20232sqxq95t4b/branch/master?svg=true)](https://ci.appveyor.com/project/markekraus/pscorewindowscompat/branch/master) 4 | 5 | Provides the Microsoft.Windows.Compatibility Pack to PowerShell Core on Windows. This module does not provide any functions but serves as a convenient way to add the [Microsoft.Windows.Compatibility Pack](https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/) to PowerShell Core. This will only work on windows systems in 64-bit [PowerShell Core](https://github.com/PowerShell/PowerShell). 6 | 7 | ## Installation 8 | 9 | The PSCoreWindowsCompat Module is available on the [PowerShell Gallery](https://www.powershellgallery.com/packages/PSCoreWindowsCompat) 10 | 11 | ```powershell 12 | Install-Module PSCoreWindowsCompat -Scope CurrentUser 13 | ``` 14 | 15 | ## Quick Start 16 | 17 | ```powershell 18 | Install-Module PSCoreWindowsCompat -Scope CurrentUser 19 | Import-Module PSCoreWindowsCompat 20 | 21 | # Search AD for the logged in user 22 | $DirectorySearcher = [System.DirectoryServices.DirectorySearcher]"(sAMAccountName=$env:USERNAME)" 23 | $Me = $DirectorySearcher.FindOne() 24 | $Me.Properties['DisplayName'] 25 | ``` 26 | 27 | Result: 28 | 29 | ```none 30 | Mark Kraus 31 | ``` 32 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2017 2 | 3 | cache: 4 | - '%LocalAppData%\Microsoft\dotnet -> appveyor.yml' 5 | - '%HOMEDRIVE%%HOMEPATH%\.nuget\packages -> appveyor.yml' 6 | 7 | version: 0.0.1.{build} 8 | skip_tags: true 9 | environment: 10 | APPVEYOR_SAVE_CACHE_ON_ERROR: true 11 | NugetApiKey: 12 | secure: 3sC7bUSY534F4WnpYXlP7XyikulxbSpfLZgC3y37gA2OAeMp35la0zplVjiliOFn 13 | access_token: 14 | secure: eBkkiWtTuwTfnTN2G4n0RegBV+MImV3BoKYm2pGmi/0Lu3VGb4m07m5FJWq+29sD 15 | ModuleName: PSCoreWindowsCompat 16 | 17 | skip_commits: 18 | message: /updated readme.*|update readme.*s/ 19 | 20 | build: false 21 | 22 | test_script: 23 | - ps: . .\build.ps1 24 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | param ($Task = 'Default') 2 | 3 | Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null 4 | 5 | $ModuleInstallScope = 'CurrentUser' 6 | if (-not [String]::IsNullOrEmpty($ENV:APPVEYOR_BUILD_FOLDER)) { 7 | $ModuleInstallScope = 'AllUsers' 8 | } 9 | 10 | Install-Module -Scope $ModuleInstallScope Psake, PSDeploy, BuildHelpers -force 11 | Import-Module Psake, PSDeploy, BuildHelpers 12 | 13 | Import-Module .\build.psm1 14 | 15 | Set-BuildEnvironment -ErrorAction SilentlyContinue 16 | 17 | Invoke-psake -buildFile .\psake.ps1 -taskList $Task -nologo 18 | 19 | exit ([int](-not $psake.build_success)) 20 | -------------------------------------------------------------------------------- /build.psm1: -------------------------------------------------------------------------------- 1 | function Get-EnvironmentInformation { 2 | $environment = @{} 3 | try { 4 | $Runtime = [System.Runtime.InteropServices.RuntimeInformation] 5 | $OSPlatform = [System.Runtime.InteropServices.OSPlatform] 6 | 7 | $environment += @{'IsCoreCLR' = 'Core' -eq $PSVersionTable.PSEdition} 8 | $environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)} 9 | $environment += @{'IsOSX' = $Runtime::IsOSPlatform($OSPlatform::OSX)} 10 | $environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)} 11 | } 12 | catch { 13 | $environment += @{'IsCoreCLR' = $false} 14 | $environment += @{'IsLinux' = $false} 15 | $environment += @{'IsOSX' = $false} 16 | $environment += @{'IsWindows' = $true} 17 | } 18 | 19 | if ($Environment.IsWindows) { 20 | $environment += @{'IsAdmin' = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)} 21 | # Can't use $env:HOME - not available on older systems (e.g. in AppVeyor) 22 | $environment += @{'nugetPackagesRoot' = "${env:HOMEDRIVE}${env:HOMEPATH}\.nuget\packages"} 23 | } 24 | else { 25 | $environment += @{'nugetPackagesRoot' = "${env:HOME}/.nuget/packages"} 26 | } 27 | 28 | if ($Environment.IsLinux) { 29 | $LinuxInfo = Get-Content /etc/os-release -Raw | ConvertFrom-StringData 30 | 31 | $environment += @{'LinuxInfo' = $LinuxInfo} 32 | $environment += @{'IsUbuntu' = $LinuxInfo.ID -match 'ubuntu'} 33 | $environment += @{'IsUbuntu14' = $Environment.IsUbuntu -and $LinuxInfo.VERSION_ID -match '14.04'} 34 | $environment += @{'IsUbuntu16' = $Environment.IsUbuntu -and $LinuxInfo.VERSION_ID -match '16.04'} 35 | $environment += @{'IsCentOS' = $LinuxInfo.ID -match 'centos' -and $LinuxInfo.VERSION_ID -match '7'} 36 | $environment += @{'IsFedora' = $LinuxInfo.ID -match 'fedora' -and $LinuxInfo.VERSION_ID -ge 24} 37 | $environment += @{'IsOpenSUSE' = $LinuxInfo.ID -match 'opensuse'} 38 | $environment += @{'IsOpenSUSE13' = $Environment.IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '13'} 39 | $environment += @{'IsOpenSUSE42.1' = $Environment.IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '42.1'} 40 | $environment += @{'IsRedHatFamily' = $Environment.IsCentOS -or $Environment.IsFedora -or $Environment.IsOpenSUSE} 41 | 42 | # Workaround for temporary LD_LIBRARY_PATH hack for Fedora 24 43 | # https://github.com/PowerShell/PowerShell/issues/2511 44 | if ($environment.IsFedora -and (Test-Path ENV:\LD_LIBRARY_PATH)) { 45 | Remove-Item -Force ENV:\LD_LIBRARY_PATH 46 | Get-ChildItem ENV: 47 | } 48 | } 49 | 50 | return [PSCustomObject] $environment 51 | } 52 | 53 | function Find-Dotnet { 54 | $OriginalPath = $env:PATH 55 | $Environment = Get-EnvironmentInformation 56 | 57 | $DotnetPath = if ($Environment.IsWindows) { 58 | "$env:LocalAppData\Microsoft\dotnet" 59 | } 60 | else { 61 | "$env:HOME/.dotnet" 62 | } 63 | 64 | if (-not (Test-DotnetExists)) { 65 | "Could not find 'dotnet', appending $DotnetPath to PATH." 66 | $env:PATH += [IO.Path]::PathSeparator + $dotnetPath 67 | } 68 | 69 | if (-not (Test-DotnetExists)) { 70 | "Still could not find 'dotnet', restoring PATH." 71 | $env:PATH = $originalPath 72 | } 73 | } 74 | 75 | Function Test-DotnetExists { 76 | if (Get-Command dotnet -ErrorAction SilentlyContinue) { 77 | $True 78 | } 79 | else { 80 | $False 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /psake.ps1: -------------------------------------------------------------------------------- 1 | Properties { 2 | # Find the build folder based on build system 3 | $ProjectRoot = $ENV:BHProjectPath 4 | if (-not $ProjectRoot) { 5 | $ProjectRoot = (Resolve-Path .).Path 6 | } 7 | 8 | # Configured in appveyor.yml 9 | $ModuleName = $ENV:ModuleName 10 | If (-not $ModuleName) { 11 | $ModuleName = Split-Path -Path $ProjectRoot -Leaf 12 | } 13 | 14 | $SrcRoot = Join-Path $ProjectRoot 'src' 15 | $SrcPath = Join-Path $SrcRoot $ModuleName 16 | $SrcManifest = Join-Path $SrcPath "$ModuleName.psd1" 17 | $SrcCsproj = Join-Path $SrcPath "$ModuleName.csproj" 18 | $BinPath = Join-Path $ProjectRoot 'bin' 19 | $ModuleFolder = Join-Path $BinPath $ModuleName 20 | $BinManifest = Join-Path $ModuleFolder "$ModuleName.psd1" 21 | 22 | 23 | $PSVersion = $PSVersionTable.PSVersion.Major 24 | $lines = '----------------------------------------------------------------------' 25 | 26 | $CurrentVersion = [version](Get-Metadata -Path $SrcManifest) 27 | $BuildVersion = [version]::New($CurrentVersion.Major, $CurrentVersion.Minor, $CurrentVersion.Build, ($CurrentVersion.Revision + 1)) 28 | if ($ENV:BHBranchName -eq "master") { 29 | $BuildVersion = [version]::New($CurrentVersion.Major, $CurrentVersion.Minor, ($CurrentVersion.Build + 1), 0) 30 | } 31 | If ($ENV:BHBranchName -eq "master" -and $ENV:BHCommitMessage -match '!deploy') { 32 | $GalleryVersion = Get-NextPSGalleryVersion -Name $ModuleName 33 | $BuildVersion = [version]::New($CurrentVersion.Major, ($CurrentVersion.Minor + 1), 0, 0) 34 | if ( 35 | $CurrentVersion.Minor -eq 0 -and 36 | $CurrentVersion.Build -eq 0 -and 37 | $CurrentVersion.Revision -eq 0 38 | ) { 39 | #This is a major version release, don't molest the the version 40 | $BuildVersion = $CurrentVersion 41 | } 42 | If ($GalleryVersion -gt $BuildVersion) { 43 | $BuildVersion = $GalleryVersion 44 | } 45 | } 46 | $BuildDate = Get-Date -uFormat '%Y-%m-%d' 47 | $DotnetConfiguration = "release" 48 | $DotnetCLIRequiredVersion = "2.0.0" 49 | $DotnetRuntime = 'win-x64' 50 | 51 | $PSCoreMSI = "https://github.com/PowerShell/PowerShell/releases/download/v6.0.0/PowerShell-6.0.0-win-x64.msi" 52 | $PSCoreInstallPath = "C:\Program Files\PowerShell\6.0.0" 53 | } 54 | 55 | Task Default -Depends Init, Build, Test, Deploy 56 | 57 | Task Init { 58 | $lines 59 | Set-Location $ProjectRoot 60 | "Build System Details:" 61 | Get-Item ENV:BH* | Format-List 62 | "`n" 63 | "Current Version: $CurrentVersion`n" 64 | "Build Version: $BuildVersion`n" 65 | "Module Path: $ModuleFolder" 66 | Find-Dotnet 67 | "`n" 68 | } 69 | 70 | Task Build -Depends Init { 71 | $lines 72 | try { 73 | Push-Location $SrcPath 74 | New-Item -Path $ModuleFolder -ItemType Directory -ErrorAction SilentlyContinue 75 | dotnet restore 76 | dotnet publish --configuration $DotnetConfiguration --runtime $DotnetRuntime --output $ModuleFolder 77 | Update-Metadata -Path $BinManifest -PropertyName 'ModuleVersion' -Value $BuildVersion 78 | } 79 | catch { 80 | Write-Error "Build Failed: $_" 81 | } 82 | finally { 83 | Pop-Location 84 | "`n" 85 | } 86 | } 87 | 88 | Task Test -Depends Init { 89 | $lines 90 | "`n" 91 | } 92 | 93 | Task Deploy -Depends Init, InstallPSCore { 94 | $lines 95 | $HasApiKey = -not [String]::IsNullOrEmpty($ENV:NugetApiKey) 96 | if ( 97 | $ENV:BHBuildSystem -ne 'Unknown' -and 98 | $ENV:BHBranchName -eq "master" -and 99 | $ENV:BHCommitMessage -match '!deploy' -and 100 | $HasApiKey 101 | ) { 102 | $Env:ProjectRoot = $ProjectRoot 103 | { 104 | Import-Module -Force -MinimumVersion 1.6.0 PowerShellGet 105 | Install-Module -Force -Scope CurrentUser -Name PSDeploy 106 | Invoke-PSDeploy $Env:ProjectRoot -Force 107 | } | pwsh.exe -nol 108 | } 109 | else { 110 | "Skipping deployment: To deploy, ensure that...`n" + 111 | "`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" + 112 | "`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" + 113 | "`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)" 114 | "`t* NugetApiKey Environment variable is set (Currently: $HasApiKey)" 115 | } 116 | "`n" 117 | } 118 | 119 | Task InstallPSCore { 120 | $lines 121 | $command = Get-Command pwsh -ErrorAction SilentlyContinue 122 | if (-not $command) { 123 | 'Installing PowerShell Core from {0}' -f $PSCoreMSI 124 | try { 125 | $oldPref = $ProgressPreference 126 | $ProgressPreference = 'SilentlyContinue' 127 | Invoke-WebRequest -Uri $PSCoreMSI -UseBasicParsing -OutFile "C:\PowerShell-win10-x64.msi" 128 | Start-Process -FilePath msiexec.exe -ArgumentList '-qn', '-i C:\PowerShell-win10-x64.msi', '-norestart' -wait 129 | $env:Path = "{0}{1}{2}" -f $env:Path, ([System.IO.Path]::PathSeparator), $PSCoreInstallPath 130 | 131 | pwsh.exe -nol -c 'Register-PSRepository -Default -ErrorAction SilentlyContinue' 132 | pwsh.exe -nol -c 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted' 133 | pwsh.exe -nol -c 'Get-PSRepository' 134 | pwsh.exe -nol -c 'Install-Module -Force PowerShellGet -MinimumVersion 1.6.0 -Scope CurrentUser -AllowClobber' 135 | } 136 | finally { 137 | $ProgressPreference = $oldPref 138 | } 139 | } 140 | "`n" 141 | } 142 | -------------------------------------------------------------------------------- /src/PSCoreWindowsCompat/PSCoreWindowsCompat.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/PSCoreWindowsCompat/PSCoreWindowsCompat.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | RootModule = 'PSCoreWindowsCompat.dll' 3 | ModuleVersion = '0.0.1' 4 | GUID = 'e428e6fa-4a7e-4531-84b2-aa9452b6b56f' 5 | Author = 'Mark Kraus' 6 | Copyright = '(c) Mark Kraus. All rights reserved.' 7 | Description = 'Provides the Microsoft.Windows.Compatibility Pack to PowerShell Core on 64-bit Windows Only. This module is not supported on non-Windows platforms nor on 32-bit Windows.' 8 | ProcessorArchitecture = 'Amd64' 9 | PowerShellVersion = '6.0.0' 10 | CompatiblePSEditions = 'Core' 11 | RequiredAssemblies = @( 12 | 'System.CodeDom.dll' 13 | 'System.Configuration.ConfigurationManager.dll' 14 | 'System.Data.Odbc.dll' 15 | 'System.Diagnostics.EventLog.dll' 16 | 'System.Diagnostics.PerformanceCounter.dll' 17 | 'System.DirectoryServices.AccountManagement.dll' 18 | 'System.DirectoryServices.dll' 19 | 'System.DirectoryServices.Protocols.dll' 20 | 'System.Drawing.Common.dll' 21 | 'System.IO.Pipes.AccessControl.dll' 22 | 'System.IO.Ports.dll' 23 | 'System.Management.dll' 24 | 'System.Runtime.Caching.dll' 25 | 'System.Security.Cryptography.ProtectedData.dll' 26 | 'System.Security.Cryptography.Xml.dll' 27 | 'System.ServiceModel.Syndication.dll' 28 | ) 29 | FunctionsToExport = '*' 30 | CmdletsToExport = '*' 31 | VariablesToExport = '*' 32 | AliasesToExport = '*' 33 | PrivateData = @{ 34 | PSData = @{ 35 | Tags = @('PSEdition_Core', 'Core', 'PSCore', 'Windows') 36 | LicenseUri = 'https://github.com/markekraus/PSCoreWindowsCompat/blob/master/LICENSE' 37 | ProjectUri = 'https://github.com/markekraus/PSCoreWindowsCompat' 38 | ReleaseNotes = ' 39 | # 2017-01-13 40 | 41 | * Add PSEdition_Core Tag and PSEDition Core requirement 42 | ' 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PSCoreWindowsCompat/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "2.0.0" 4 | } 5 | } 6 | --------------------------------------------------------------------------------