Move Module files from psl-monad submodule to super-project

This commit uses master branch 8abffd25ebc33cbc0b4ce224b46e699704b01728
This commit is contained in:
PowerShell Team 2016-04-01 19:00:51 -07:00 committed by Andrew Schwartzmeyer
parent 5c1fb845c4
commit bd599ed62a
20 changed files with 15147 additions and 0 deletions

View File

@ -0,0 +1,16 @@
@{
GUID="CA046F10-CA64-4740-8FF9-2565DBA61A4F"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.0.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
AliasesToExport = @()
FunctionsToExport = @()
CmdletsToExport="Get-WinEvent", "Get-Counter", "Import-Counter", "Export-Counter", "New-WinEvent"
NestedModules="Microsoft.PowerShell.Commands.Diagnostics.dll"
TypesToProcess="GetEvent.types.ps1xml"
FormatsToProcess="Event.format.ps1xml","Diagnostics.format.ps1xml"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390783'
}

View File

@ -0,0 +1,33 @@
@{
GUID="1DA87E53-152B-403E-98DC-74D7B4D63D59"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.1.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
CmdletsToExport= "Format-List", "Format-Custom", "Format-Table", "Format-Wide",
"Out-File", "Out-Printer", "Out-String",
"Out-GridView", "Get-FormatData", "Export-FormatData", "ConvertFrom-Json", "ConvertTo-Json",
"Invoke-RestMethod", "Invoke-WebRequest", "Register-ObjectEvent", "Register-EngineEvent",
"Wait-Event", "Get-Event", "Remove-Event", "Get-EventSubscriber", "Unregister-Event",
"New-Event", "Add-Member", "Add-Type", "Compare-Object", "ConvertTo-Html", "ConvertFrom-StringData",
"Export-Csv", "Import-Csv", "ConvertTo-Csv", "ConvertFrom-Csv", "Export-Alias", "Invoke-Expression",
"Get-Alias", "Get-Culture", "Get-Date", "Get-Host", "Get-Member", "Get-Random", "Get-UICulture",
"Get-Unique", "Export-PSSession", "Import-PSSession", "Import-Alias", "Import-LocalizedData",
"Select-String", "Measure-Object", "New-Alias", "New-TimeSpan", "Read-Host", "Set-Alias", "Set-Date",
"Start-Sleep", "Tee-Object", "Measure-Command", "Update-List", "Update-TypeData", "Update-FormatData",
"Remove-TypeData", "Get-TypeData", "Write-Host", "Write-Progress", "New-Object", "Select-Object",
"Group-Object", "Sort-Object", "Get-Variable", "New-Variable", "Set-Variable", "Remove-Variable",
"Clear-Variable", "Export-Clixml", "Import-Clixml", "ConvertTo-Xml", "Select-Xml", "Write-Debug",
"Write-Verbose", "Write-Warning", "Write-Error", "Write-Information", "Write-Output", "Set-PSBreakpoint", "Get-PSBreakpoint",
"Remove-PSBreakpoint", "Enable-PSBreakpoint", "Disable-PSBreakpoint", "Get-PSCallStack",
"Send-MailMessage", "Get-TraceSource", "Set-TraceSource", "Trace-Command", "Show-Command", "Unblock-File",
"Get-Runspace", "Debug-Runspace", "Enable-RunspaceDebug", "Disable-RunspaceDebug", "Get-RunspaceDebug", "Wait-Debugger",
"ConvertFrom-String", "Convert-String"
FunctionsToExport= "Get-FileHash", "New-TemporaryFile", "New-Guid", "Format-Hex", "Import-PowerShellDataFile",
"ConvertFrom-SddlString"
AliasesToExport= "CFS", "fhx"
NestedModules="Microsoft.PowerShell.Commands.Utility.dll","Microsoft.PowerShell.Utility.psm1"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390787'
}

View File

@ -0,0 +1,13 @@
@{
GUID="CA046F10-CA64-4740-8FF9-2565DBA61A4F"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.0.0.0"
PowerShellVersion="3.0"
CmdletsToExport="Get-WinEvent", "New-WinEvent"
NestedModules="Microsoft.PowerShell.Commands.Diagnostics.dll"
TypesToProcess="..\..\GetEvent.types.ps1xml"
FormatsToProcess="..\..\Event.format.ps1xml"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390783'
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,956 @@
#########################################################################################
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# Appx Provider Module
#
#########################################################################################
$script:ProviderName = "appx"
$script:AppxPackageExtension = ".appx"
$script:AppxManifestFile = "AppxManifest.xml"
$script:Architecture = "Architecture"
$script:ResourceId = "ResourceId"
$script:AppxPackageSources = $null
$script:AppxLocalPath="$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\AppxProvider"
$script:AppxPackageSourcesFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:AppxLocalPath -ChildPath "AppxPackageSources.xml"
$Script:ResponseUri = "ResponseUri"
$Script:StatusCode = "StatusCode"
# Wildcard pattern matching configuration.
$script:wildcardOptions = [System.Management.Automation.WildcardOptions]::CultureInvariant -bor `
[System.Management.Automation.WildcardOptions]::IgnoreCase
#Localized Data
Microsoft.PowerShell.Utility\Import-LocalizedData LocalizedData -filename AppxProvider.Resource.psd1
#region Appx Provider APIs Implementation
function Get-PackageProviderName
{
return $script:ProviderName
}
function Initialize-Provider{
param(
)
}
function Get-DynamicOptions
{
param
(
[Microsoft.PackageManagement.MetaProvider.PowerShell.OptionCategory]
$category
)
Write-Debug ($LocalizedData.ProviderApiDebugMessage -f ('Get-DynamicOptions'))
switch($category)
{
Install {
Write-Output -InputObject (New-DynamicOption -Category $category -Name Architecture -ExpectedType String -IsRequired $false)
Write-Output -InputObject (New-DynamicOption -Category $category -Name ResourceId -ExpectedType String -IsRequired $false)
}
Package {
Write-Output -InputObject (New-DynamicOption -Category $category -Name Architecture -ExpectedType String -IsRequired $false)
Write-Output -InputObject (New-DynamicOption -Category $category -Name ResourceId -ExpectedType String -IsRequired $false)
}
}
}
function Find-Package
{
[CmdletBinding()]
param
(
[string[]]
$names,
[string]
$requiredVersion,
[string]
$minimumVersion,
[string]
$maximumVersion
)
Write-Debug ($LocalizedData.ProviderApiDebugMessage -f ('Find-Package'))
$ResourceId = $null
$Architecture = $null
$Sources = @()
$streamedResults = @()
$namesParameterEmpty = (-not $names) -or (($names.Count -eq 1) -and ($names[0] -eq ''))
Set-PackageSourcesVariable
if($RequiredVersion -and $MinimumVersion)
{
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $LocalizedData.VersionRangeAndRequiredVersionCannotBeSpecifiedTogether `
-ErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}
if($RequiredVersion -or $MinimumVersion)
{
if(-not $names -or $names.Count -ne 1 -or (Test-WildcardPattern -Name $names[0]))
{
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $LocalizedData.VersionParametersAreAllowedOnlyWithSinglePackage `
-ErrorId "VersionParametersAreAllowedOnlyWithSinglePackage" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}
}
$options = $request.Options
if($options)
{
foreach( $o in $options.Keys )
{
Write-Debug ( "OPTION: {0} => {1}" -f ($o, $options[$o]) )
}
if($options.ContainsKey('Source'))
{
$SourceNames = $($options['Source'])
Write-Verbose ($LocalizedData.SpecifiedSourceName -f ($SourceNames))
foreach($sourceName in $SourceNames)
{
if($script:AppxPackageSources.Contains($sourceName))
{
$Sources += $script:AppxPackageSources[$sourceName]
}
else
{
$sourceByLocation = Get-SourceName -Location $sourceName
if ($sourceByLocation -ne $null)
{
$Sources += $script:AppxPackageSources[$sourceByLocation]
}
else
{
$message = $LocalizedData.PackageSourceNotFound -f ($sourceName)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "PackageSourceNotFound" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument `
-ExceptionObject $sourceName
}
}
}
}
else
{
Write-Verbose $LocalizedData.NoSourceNameIsSpecified
$script:AppxPackageSources.Values | Microsoft.PowerShell.Core\ForEach-Object { $Sources += $_ }
}
if($options.ContainsKey($script:Architecture))
{
$Architecture = $options[$script:Architecture]
}
if($options.ContainsKey($script:ResourceId))
{
$ResourceId = $options[$script:ResourceId]
}
}
foreach($source in $Sources)
{
$location = $source.SourceLocation
if($request.IsCanceled)
{
return
}
if(-not(Test-Path $location))
{
$message = $LocalizedData.PathNotFound -f ($Location)
Write-Verbose $message
continue
}
$packages = Get-AppxPackagesFromPath -path $location
foreach($pkg in $packages)
{
if($request.IsCanceled)
{
return
}
$pkgManifest = Get-PackageManfiestData -PackageFullPath $pkg.FullName
if(-not $pkgManifest)
{
continue
}
# $pkgManifest.Name has to match any of the supplied names, using PowerShell wildcards
if(-not($namesParameterEmpty))
{
if(-not(($names | Microsoft.PowerShell.Core\ForEach-Object { if ($pkgManifest.Name -like $_){return $true; break} } -End {return $false})))
{
continue
}
}
# Version
if($RequiredVersion)
{
if($RequiredVersion -ne $pkgManifest.Version)
{
continue
}
}
else
{
if(-not((-not $MinimumVersion -or ($MinimumVersion -le $pkgManifest.Version)) -and
(-not $MaximumVersion -or ($MaximumVersion -ge $pkgManifest.Version))))
{
continue
}
}
if($Architecture)
{
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $Architecture, $script:wildcardOptions
if(-not($wildcardPattern.IsMatch($pkgManifest.Architecture)))
{
continue
}
}
if($ResourceId)
{
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $ResourceId, $script:wildcardOptions
if(-not($wildcardPattern.IsMatch($pkgManifest.ResourceId)))
{
continue
}
}
$sid = New-SoftwareIdentityFromPackage -Package $pkgManifest -Source $source.Name
$fastPackageReference = $sid.fastPackageReference
if($streamedResults -notcontains $fastPackageReference)
{
$streamedResults += $fastPackageReference
Write-Output -InputObject $sid
}
}
}
}
function Get-InstalledPackage
{
[CmdletBinding()]
param
(
[Parameter()]
[string]
$Name,
[Parameter()]
[string]
$RequiredVersion,
[Parameter()]
[string]
$MinimumVersion,
[Parameter()]
[string]
$MaximumVersion
)
Write-Debug -Message ($LocalizedData.ProviderApiDebugMessage -f ('Get-InstalledPackage'))
$Architecture = $null
$ResourceId = $null
$options = $request.Options
if($options)
{
if($options.ContainsKey($script:Architecture))
{
$Architecture = $options[$script:Architecture]
}
if($options.ContainsKey($script:ResourceId))
{
$ResourceId = $options[$script:ResourceId]
}
}
$params = @{}
if($Name)
{
$params.Add("Name", $Name)
}
$packages = Appx\Get-AppxPackage @params
foreach($package in $packages)
{
if($RequiredVersion)
{
if($RequiredVersion -ne $package.Version)
{
continue
}
}
else
{
if(-not((-not $MinimumVersion -or ($MinimumVersion -le $package.Version)) -and
(-not $MaximumVersion -or ($MaximumVersion -ge $package.Version))))
{
continue
}
}
if($Architecture)
{
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $Architecture, $script:wildcardOptions
if(-not($wildcardPattern.IsMatch($package.Architecture)))
{
continue
}
}
if($ResourceId)
{
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $ResourceId,$script:wildcardOptions
if(-not($wildcardPattern.IsMatch($package.ResourceId)))
{
continue
}
}
$sid = New-SoftwareIdentityFromPackage -Package $package
write-Output $sid
}
}
function Install-Package
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$fastPackageReference
)
Write-Debug -Message ($LocalizedData.ProviderApiDebugMessage -f ('Install-Package'))
Write-Debug -Message ($LocalizedData.FastPackageReference -f $fastPackageReference)
Appx\Add-AppxPackage -Path $fastPackageReference
}
function UnInstall-Package
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$fastPackageReference
)
Write-Debug -Message ($LocalizedData.ProviderApiDebugMessage -f ('Uninstall-Package'))
Write-Debug -Message ($LocalizedData.FastPackageReference -f $fastPackageReference)
Appx\Remove-AppxPackage -Package $fastPackageReference
}
function Add-PackageSource
{
[CmdletBinding()]
param
(
[string]
$Name,
[string]
$Location,
[bool]
$Trusted
)
Write-Debug ($LocalizedData.ProviderApiDebugMessage -f ('Add-PackageSource'))
Set-PackageSourcesVariable -Force
if(-not (Microsoft.PowerShell.Management\Test-Path $Location) -and
-not (Test-WebUri -uri $Location))
{
$LocationUri = [Uri]$Location
if($LocationUri.Scheme -eq 'file')
{
$message = $LocalizedData.PathNotFound -f ($Location)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "PathNotFound" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument `
-ExceptionObject $Location
}
else
{
$message = $LocalizedData.InvalidWebUri -f ($Location, "Location")
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "InvalidWebUri" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument `
-ExceptionObject $Location
}
}
if(Test-WildcardPattern $Name)
{
$message = $LocalizedData.PackageSourceNameContainsWildCards -f ($Name)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "PackageSourceNameContainsWildCards" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument `
-ExceptionObject $Name
}
$LocationString = Get-ValidPackageLocation -LocationString $Location -ParameterName "Location"
# Check if Location is already registered with another Name
$existingSourceName = Get-SourceName -Location $LocationString
if($existingSourceName -and
($Name -ne $existingSourceName))
{
$message = $LocalizedData.PackageSourceAlreadyRegistered -f ($existingSourceName, $Location, $Name)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "PackageSourceAlreadyRegistered" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}
# Check if Name is already registered
if($script:AppxPackageSources.Contains($Name))
{
$currentSourceObject = $script:AppxPackageSources[$Name]
$null = $script:AppxPackageSources.Remove($Name)
}
# Add new package source
$packageSource = Microsoft.PowerShell.Utility\New-Object PSCustomObject -Property ([ordered]@{
Name = $Name
SourceLocation = $LocationString
Trusted=$Trusted
Registered= $true
})
$script:AppxPackageSources.Add($Name, $packageSource)
$message = $LocalizedData.SourceRegistered -f ($Name, $LocationString)
Write-Verbose $message
# Persist the package sources
Save-PackageSources
# return the package source object.
Write-Output -InputObject (New-PackageSourceFromSource -Source $packageSource)
}
function Resolve-PackageSource
{
Write-Debug ($LocalizedData.ProviderApiDebugMessage -f ('Resolve-PackageSource'))
Set-PackageSourcesVariable
$SourceName = $request.PackageSources
if(-not $SourceName)
{
$SourceName = "*"
}
foreach($src in $SourceName)
{
if($request.IsCanceled)
{
return
}
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $src,$script:wildcardOptions
$sourceFound = $false
$script:AppxPackageSources.GetEnumerator() |
Microsoft.PowerShell.Core\Where-Object {$wildcardPattern.IsMatch($_.Key)} |
Microsoft.PowerShell.Core\ForEach-Object {
$source = $script:AppxPackageSources[$_.Key]
$packageSource = New-PackageSourceFromSource -Source $source
Write-Output -InputObject $packageSource
$sourceFound = $true
}
if(-not $sourceFound)
{
$sourceName = Get-SourceName -Location $src
if($sourceName)
{
$source = $script:AppxPackageSources[$sourceName]
$packageSource = New-PackageSourceFromSource -Source $source
Write-Output -InputObject $packageSource
}
elseif( -not (Test-WildcardPattern $src))
{
$message = $LocalizedData.PackageSourceNotFound -f ($src)
Write-Error -Message $message -ErrorId "PackageSourceNotFound" -Category InvalidOperation -TargetObject $src
}
}
}
}
function Remove-PackageSource
{
param
(
[string]
$Name
)
Write-Debug ($LocalizedData.ProviderApiDebugMessage -f ('Remove-PackageSource'))
Set-PackageSourcesVariable -Force
$SourcesToBeRemoved = @()
foreach ($sourceName in $Name)
{
if($request.IsCanceled)
{
return
}
# Check if $Name contains any wildcards
if(Test-WildcardPattern $sourceName)
{
$message = $LocalizedData.PackageSourceNameContainsWildCards -f ($sourceName)
Write-Error -Message $message -ErrorId "PackageSourceNameContainsWildCards" -Category InvalidOperation -TargetObject $sourceName
continue
}
# Check if the specified package source name is in the registered package sources
if(-not $script:AppxPackageSources.Contains($sourceName))
{
$message = $LocalizedData.PackageSourceNotFound -f ($sourceName)
Write-Error -Message $message -ErrorId "PackageSourceNotFound" -Category InvalidOperation -TargetObject $sourceName
continue
}
$SourcesToBeRemoved += $sourceName
$message = $LocalizedData.PackageSourceUnregistered -f ($sourceName)
Write-Verbose $message
}
# Remove the SourcesToBeRemoved
$SourcesToBeRemoved | Microsoft.PowerShell.Core\ForEach-Object { $null = $script:AppxPackageSources.Remove($_) }
# Persist the package sources
Save-PackageSources
}
#endregion
#region Common functions
function Get-AppxPackagesFromPath
{
param
(
[Parameter(Mandatory=$true)]
$Path
)
$filterAppxPackages = "*"+$script:AppxPackageExtension
$packages = Get-ChildItem -path $Path -filter $filterAppxPackages
return $packages
}
function Get-PackageManfiestData
{
param
(
[Parameter(Mandatory=$true)]
$PackageFullPath
)
$guid = [System.Guid]::NewGuid().toString()
try
{
[System.IO.Compression.ZipFile]::ExtractToDirectory($PackageFullPath, "$env:TEMP\$guid")
}
catch
{
Write-Verbose( $LocalizedData.MetaDataExtractionFailed -f ($PackageFullPath) )
return $null
}
[xml] $packageManifest = Get-Content "$env:TEMP\$guid\$script:AppxManifestFile" -ErrorAction SilentlyContinue
if($packageManifest)
{
$Identity = $packageManifest.Package.Identity
$manifestData = new-object psObject -Property @{Name=$Identity.Name; Architecture=$Identity.ProcessorArchitecture; Publisher=$Identity.Publisher; Version=$Identity.Version; ResourceId=$Identity.resourceId; PackageFullName=$PackageFullPath}
Remove-Item -Path "$env:TEMP\$guid" -Recurse -Force -ErrorAction SilentlyContinue
return $manifestData
}
else
{
Write-Verbose ($LocalizedData.MetaDataExtractionFailed -f ($PackageFullPath) )
}
return $null
}
function New-FastPackageReference
{
param
(
[Parameter(Mandatory=$true)]
[string]
$PackageFullName
)
return "$PackageFullName"
}
function New-SoftwareIdentityFromPackage
{
param
(
[Parameter(Mandatory=$true)]
$Package,
[string]
$Source
)
$fastPackageReference = New-FastPackageReference -PackageFullName $Package.PackageFullName
if(-not($Source))
{
$Source = $Package.Publisher
}
$details = @{
Publisher = $Package.Publisher
Architecture = $Package.Architecture
ResourceId = $Package.ResourceId
PackageFullName = $Package.PackageFullName
}
$params = @{
FastPackageReference = $fastPackageReference;
Name = $Package.Name;
Version = $Package.Version;
versionScheme = "MultiPartNumeric";
Source = $source;
Details = $details;
}
$sid = New-SoftwareIdentity @params
return $sid
}
function Test-WebUri
{
[CmdletBinding()]
[OutputType([bool])]
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[Uri]
$uri
)
return ($uri.AbsoluteURI -ne $null) -and ($uri.Scheme -match '[http|https]')
}
function Test-WildcardPattern
{
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(Mandatory=$true)]
[ValidateNotNull()]
$Name
)
return [System.Management.Automation.WildcardPattern]::ContainsWildcardCharacters($Name)
}
function DeSerialize-PSObject
{
[CmdletBinding(PositionalBinding=$false)]
Param
(
[Parameter(Mandatory=$true)]
$Path
)
$filecontent = Microsoft.PowerShell.Management\Get-Content -Path $Path
[System.Management.Automation.PSSerializer]::Deserialize($filecontent)
}
function Get-SourceName
{
[CmdletBinding()]
[OutputType("string")]
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$Location
)
Set-PackageSourcesVariable
foreach($source in $script:AppxPackageSources.Values)
{
if($source.SourceLocation -eq $Location)
{
return $source.Name
}
}
}
function WebRequestApisAvailable
{
$webRequestApiAvailable = $false
try
{
[System.Net.WebRequest]
$webRequestApiAvailable = $true
}
catch
{
}
return $webRequestApiAvailable
}
function Ping-Endpoint
{
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]]
$Endpoint
)
$results = @{}
if(WebRequestApisAvailable)
{
$iss = [System.Management.Automation.Runspaces.InitialSessionState]::Create()
$iss.types.clear()
$iss.formats.clear()
$iss.LanguageMode = "FullLanguage"
$WebRequestcmd = @'
try
{{
$request = [System.Net.WebRequest]::Create("{0}")
$request.Method = 'GET'
$request.Timeout = 30000
$response = [System.Net.HttpWebResponse]$request.GetResponse()
$response
$response.Close()
}}
catch [System.Net.WebException]
{{
"Error:System.Net.WebException"
}}
'@ -f $EndPoint
$ps = [powershell]::Create($iss).AddScript($WebRequestcmd)
$response = $ps.Invoke()
$ps.dispose()
if ($response -ne "Error:System.Net.WebException")
{
$results.Add($Script:ResponseUri,$response.ResponseUri.ToString())
$results.Add($Script:StatusCode,$response.StatusCode.value__)
}
}
else
{
$response = $null
try
{
$httpClient = New-Object 'System.Net.Http.HttpClient'
$response = $httpclient.GetAsync($endpoint)
}
catch
{
}
if ($response -ne $null -and $response.result -ne $null)
{
$results.Add($Script:ResponseUri,$response.Result.RequestMessage.RequestUri.AbsoluteUri.ToString())
$results.Add($Script:StatusCode,$response.result.StatusCode.value__)
}
}
return $results
}
function Get-ValidPackageLocation
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$LocationString,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$ParameterName
)
# Get the actual Uri from the Location
if(-not (Microsoft.PowerShell.Management\Test-Path $LocationString))
{
$results = Ping-Endpoint -Endpoint $LocationString
if ($results.ContainsKey("Exception"))
{
$Exception = $results["Exception"]
if($Exception)
{
$message = $LocalizedData.InvalidWebUri -f ($LocationString, $ParameterName)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "InvalidWebUri" `
-ExceptionObject $Exception `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}
}
if ($results.ContainsKey("ResponseUri"))
{
$LocationString = $results["ResponseUri"]
}
}
return $LocationString
}
function Set-PackageSourcesVariable
{
param([switch]$Force)
if(-not $script:AppxPackageSources -or $Force)
{
if(Microsoft.PowerShell.Management\Test-Path $script:AppxPackageSourcesFilePath)
{
$script:AppxPackageSources = DeSerialize-PSObject -Path $script:AppxPackageSourcesFilePath
}
else
{
$script:AppxPackageSources = [ordered]@{}
}
}
}
function Save-PackageSources
{
if($script:AppxPackageSources)
{
if(-not (Microsoft.PowerShell.Management\Test-Path $script:AppxLocalPath))
{
$null = Microsoft.PowerShell.Management\New-Item -Path $script:AppxLocalPath `
-ItemType Directory -Force `
-ErrorAction SilentlyContinue `
-WarningAction SilentlyContinue `
-Confirm:$false -WhatIf:$false
}
Microsoft.PowerShell.Utility\Out-File -FilePath $script:AppxPackageSourcesFilePath -Force -InputObject ([System.Management.Automation.PSSerializer]::Serialize($script:AppxPackageSources))
}
}
function New-PackageSourceFromSource
{
param
(
[Parameter(Mandatory)]
$Source
)
# create a new package source
$src = New-PackageSource -Name $Source.Name `
-Location $Source.SourceLocation `
-Trusted $Source.Trusted `
-Registered $Source.Registered `
Write-Verbose ( $LocalizedData.PackageSourceDetails -f ($src.Name, $src.Location, $src.IsTrusted, $src.IsRegistered) )
# return the package source object.
Write-Output -InputObject $src
}
#endregion
# Utility to throw an errorrecord
function ThrowError
{
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$CallerPSCmdlet,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ExceptionName,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ExceptionMessage,
[System.Object]
$ExceptionObject,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ErrorId,
[parameter(Mandatory = $true)]
[ValidateNotNull()]
[System.Management.Automation.ErrorCategory]
$ErrorCategory
)
$exception = New-Object $ExceptionName $ExceptionMessage;
$errorRecord = New-Object System.Management.Automation.ErrorRecord $exception, $ErrorId, $ErrorCategory, $ExceptionObject
$CallerPSCmdlet.ThrowTerminatingError($errorRecord)
}
#endregion
Export-ModuleMember -Function Find-Package, `
Install-Package, `
Uninstall-Package, `
Get-InstalledPackage, `
Remove-PackageSource, `
Resolve-PackageSource, `
Add-PackageSource, `
Get-DynamicOptions, `
Initialize-Provider, `
Get-PackageProviderName

View File

@ -0,0 +1,12 @@
@{
GUID="eb74e8da-9ae2-482a-a648-e96550fb8733"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="1.0.0.0"
FunctionsToExport = @('Compress-Archive', 'Expand-Archive')
CmdletsToExport = @()
AliasesToExport = @()
NestedModules="Microsoft.PowerShell.Archive.psm1"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?LinkId=393254'
}

View File

@ -0,0 +1,14 @@
@{
GUID="56D66100-99A0-4FFC-A12D-EEE9A6718AEF"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.0.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
AliasesToExport = @()
FunctionsToExport = @()
CmdletsToExport="Start-Transcript", "Stop-Transcript"
NestedModules="Microsoft.PowerShell.ConsoleHost.dll"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390784'
}

View File

@ -0,0 +1,99 @@
@{
GUID="EEFCB906-B326-4E99-9F54-8B4BB6EF3C6D"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.1.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
NestedModules="Microsoft.PowerShell.Commands.Management.dll"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390785'
AliasesToExport = @("gcb", "scb")
FunctionsToExport = @()
CmdletsToExport=@("Add-Content",
"Clear-Content",
"Clear-ItemProperty",
"Join-Path",
"Convert-Path",
"Copy-ItemProperty",
"Get-EventLog",
"Clear-EventLog",
"Write-EventLog",
"Limit-EventLog",
"Show-EventLog",
"New-EventLog",
"Remove-EventLog",
"Get-ChildItem",
"Get-Content",
"Get-ItemProperty",
"Get-ItemPropertyValue",
"Get-WmiObject",
"Invoke-WmiMethod",
"Move-ItemProperty",
"Get-Location",
"Set-Location",
"Push-Location",
"Pop-Location",
"New-PSDrive",
"Remove-PSDrive",
"Get-PSDrive",
"Get-Item",
"New-Item",
"Set-Item",
"Remove-Item",
"Move-Item",
"Rename-Item",
"Copy-Item",
"Clear-Item",
"Invoke-Item",
"Get-PSProvider",
"New-ItemProperty",
"Split-Path",
"Test-Path",
"Get-Process",
"Stop-Process",
"Wait-Process",
"Debug-Process",
"Start-Process",
"Remove-ItemProperty",
"Remove-WmiObject",
"Rename-ItemProperty",
"Register-WmiEvent",
"Resolve-Path",
"Get-Service",
"Stop-Service",
"Start-Service",
"Suspend-Service",
"Resume-Service",
"Restart-Service",
"Set-Service",
"New-Service",
"Set-Content",
"Set-ItemProperty",
"Set-WmiInstance",
"Get-Transaction",
"Start-Transaction",
"Complete-Transaction",
"Undo-Transaction",
"Use-Transaction",
"New-WebServiceProxy",
"Get-HotFix",
"Test-Connection",
"Enable-ComputerRestore",
"Disable-ComputerRestore",
"Checkpoint-Computer",
"Get-ComputerRestorePoint",
"Restart-Computer",
"Stop-Computer",
"Restore-Computer",
"Add-Computer",
"Remove-Computer",
"Test-ComputerSecureChannel",
"Reset-ComputerMachinePassword",
"Rename-Computer",
"Get-ControlPanelItem",
"Show-ControlPanelItem",
"Clear-Recyclebin",
"Get-Clipboard",
"Set-Clipboard")
}

View File

@ -0,0 +1,14 @@
@{
GUID="A94C8C7E-9810-47C0-B8AF-65089C13A35A"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.0.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
AliasesToExport = @()
FunctionsToExport = @()
CmdletsToExport="Get-Acl", "Set-Acl", "Get-PfxCertificate", "Get-Credential", "Get-ExecutionPolicy", "Set-ExecutionPolicy", "Get-AuthenticodeSignature", "Set-AuthenticodeSignature", "ConvertFrom-SecureString", "ConvertTo-SecureString", "Get-CmsMessage", "Unprotect-CmsMessage", "Protect-CmsMessage" , "New-FileCatalog" , "Test-FileCatalog"
NestedModules="Microsoft.PowerShell.Security.dll"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390786'
}

View File

@ -0,0 +1,709 @@
function Get-FileHash
{
[CmdletBinding(DefaultParameterSetName = "Path", HelpURI = "http://go.microsoft.com/fwlink/?LinkId=517145")]
param(
[Parameter(Mandatory, ParameterSetName="Path", Position = 0)]
[System.String[]]
$Path,
[Parameter(Mandatory, ParameterSetName="LiteralPath", ValueFromPipelineByPropertyName = $true)]
[Alias("PSPath")]
[System.String[]]
$LiteralPath,
[Parameter(Mandatory, ParameterSetName="Stream")]
[System.IO.Stream]
$InputStream,
[ValidateSet("SHA1", "SHA256", "SHA384", "SHA512", "MACTripleDES", "MD5", "RIPEMD160")]
[System.String]
$Algorithm="SHA256"
)
begin
{
# Construct the strongly-typed crypto object
# First see if it has a FIPS algorithm
$hasherType = "System.Security.Cryptography.${Algorithm}CryptoServiceProvider" -as [Type]
if ($hasherType)
{
$hasher = $hasherType::New()
}
else
{
# Check if the type is supported in the current system
$algorithmType = "System.Security.Cryptography.${Algorithm}" -as [Type]
if ($algorithmType)
{
if ($Algorithm -eq "MACTripleDES")
{
$hasher = $algorithmType::New()
}
else
{
$hasher = $algorithmType::Create()
}
}
else
{
$errorId = "AlgorithmTypeNotSupported"
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument
$errorMessage = [Microsoft.PowerShell.Commands.UtilityResources]::AlgorithmTypeNotSupported -f $Algorithm
$exception = [System.InvalidOperationException]::New($errorMessage)
$errorRecord = [System.Management.Automation.ErrorRecord]::New($exception, $errorId, $errorCategory, $null)
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
function GetStreamHash
{
param(
[System.IO.Stream]
$InputStream,
[System.String]
$RelatedPath,
[System.Security.Cryptography.HashAlgorithm]
$Hasher)
# Compute file-hash using the crypto object
[Byte[]] $computedHash = $Hasher.ComputeHash($InputStream)
[string] $hash = [BitConverter]::ToString($computedHash) -replace '-',''
if ($RelatedPath -eq $null)
{
$retVal = [PSCustomObject] @{
Algorithm = $Algorithm.ToUpperInvariant()
Hash = $hash
}
}
else
{
$retVal = [PSCustomObject] @{
Algorithm = $Algorithm.ToUpperInvariant()
Hash = $hash
Path = $RelatedPath
}
}
$retVal.psobject.TypeNames.Insert(0, "Microsoft.Powershell.Utility.FileHash")
$retVal
}
}
process
{
if($PSCmdlet.ParameterSetName -eq "Stream")
{
GetStreamHash -InputStream $InputStream -RelatedPath $null -Hasher $hasher
}
else
{
$pathsToProcess = @()
if($PSCmdlet.ParameterSetName -eq "LiteralPath")
{
$pathsToProcess += Resolve-Path -LiteralPath $LiteralPath | Foreach-Object ProviderPath
}
if($PSCmdlet.ParameterSetName -eq "Path")
{
$pathsToProcess += Resolve-Path $Path | Foreach-Object ProviderPath
}
foreach($filePath in $pathsToProcess)
{
if(Test-Path -LiteralPath $filePath -PathType Container)
{
continue
}
try
{
# Read the file specified in $FilePath as a Byte array
[system.io.stream]$stream = [system.io.file]::OpenRead($filePath)
GetStreamHash -InputStream $stream -RelatedPath $filePath -Hasher $hasher
}
catch [Exception]
{
$errorMessage = [Microsoft.PowerShell.Commands.UtilityResources]::FileReadError -f $FilePath, $_
Write-Error -Message $errorMessage -Category ReadError -ErrorId "FileReadError" -TargetObject $FilePath
return
}
finally
{
if($stream)
{
$stream.Dispose()
}
}
}
}
}
}
<# This cmdlet is used to create a new temporary file in $env:temp #>
function New-TemporaryFile
{
[CmdletBinding(
HelpURI='http://go.microsoft.com/fwlink/?LinkId=526726',
SupportsShouldProcess=$true)]
[OutputType([System.IO.FileInfo])]
Param()
Begin
{
try
{
if($PSCmdlet.ShouldProcess($env:TEMP))
{
$tempFilePath = [System.IO.Path]::GetTempFileName()
}
}
catch
{
$errorRecord = [System.Management.Automation.ErrorRecord]::new($_.Exception,"NewTemporaryFileWriteError", "WriteError", $env:TEMP)
Write-Error -ErrorRecord $errorRecord
return
}
if($tempFilePath)
{
Get-Item $tempFilePath
}
}
}
<# This cmdlet is used to generate a new guid #>
function New-Guid
{
[CmdletBinding(HelpURI='http://go.microsoft.com/fwlink/?LinkId=526920')]
[OutputType([System.Guid])]
Param()
Begin
{
[Guid]::NewGuid()
}
}
<############################################################################################
# Format-Hex cmdlet helps in displaying the Hexadecimal equivalent of the input data.
############################################################################################>
function Format-Hex
{
[CmdletBinding(
DefaultParameterSetName="Path",
HelpUri="http://go.microsoft.com/fwlink/?LinkId=526919")]
[Alias("fhx")]
[OutputType("Microsoft.PowerShell.Commands.ByteCollection")]
param
(
[Parameter (Mandatory=$true, Position=0, ParameterSetName="Path")]
[ValidateNotNullOrEmpty()]
[string[]] $Path,
[Parameter (Mandatory=$true, ParameterSetName="LiteralPath")]
[ValidateNotNullOrEmpty()]
[Alias("PSPath")]
[string[]] $LiteralPath,
[Parameter(Mandatory=$true, ParameterSetName="ByInputObject", ValueFromPipeline=$true)]
[Object] $InputObject,
[Parameter (ParameterSetName="ByInputObject")]
[ValidateSet("Ascii", "UTF32", "UTF7", "UTF8", "BigEndianUnicode", "Unicode")]
[string] $Encoding = "Ascii",
[Parameter(ParameterSetName="ByInputObject")]
[switch]$Raw
)
begin
{
$bufferSize = 16
$inputStreamArray = [System.Collections.ArrayList]::New()
<############################################################################################
# The ConvertToHexadecimalHelper is a helper method used to fetch unicode bytes from the
# input data and display the hexadecimial representaion of the of the input data in bytes.
############################################################################################>
function ConvertToHexadecimalHelper
{
param
(
[Byte[]] $inputBytes,
[string] $path,
[Uint32] $offset
)
# This section is used to display the hexadecimal
# representaion of the of the input data in bytes.
if($inputBytes -ne $null)
{
$byteCollectionObject = [Microsoft.PowerShell.Commands.ByteCollection]::new($offset, $inputBytes, $path)
Write-Output -InputObject $byteCollectionObject
}
}
<############################################################################################
# The ProcessFileContent is a helper method used to fetch file contents in blocks and
# process it to support displaying hexadecimal formating of the fetched content.
############################################################################################>
function ProcessFileContent
{
param
(
[string] $filePath,
[boolean] $isLiteralPath
)
if($isLiteralPath)
{
$resolvedPaths = Resolve-Path -LiteralPath $filePath
}
else
{
$resolvedPaths = Resolve-Path -Path $filePath
}
# If Path resolution has failed then a corresponding non-terminating error is
# written to the pipeline. We continue processing any remaining files.
if($resolvedPaths -eq $null)
{
return
}
if($resolvedPaths.Count -gt 1)
{
# write a non-terminating error message indicating that path specified is resolving to multiple file system paths.
$errorMessage = [Microsoft.PowerShell.Commands.UtilityResources]::FormatHexResolvePathError -f $filePath
Write-Error -Message $errorMessage -Category ([System.Management.Automation.ErrorCategory]::InvalidData) -ErrorId "FormatHexResolvePathError"
}
$targetFilePath = $resolvedPaths.ProviderPath
if($targetFilePath -ne $null)
{
$buffer = [byte[]]::new($bufferSize)
try
{
try
{
$currentFileStream = [System.IO.File]::Open($targetFilePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
}
catch
{
# Failed to access the file. Write a non terminating error to the pipeline
# and move on with the remaining files.
$exception = $_.Exception
if($null -ne $_.Exception -and
$null -ne $_.Exception.InnerException)
{
$exception = $_.Exception.InnerException
}
$errorRecord = [System.Management.Automation.ErrorRecord]::new($exception,"FormatHexFileAccessError", ([System.Management.Automation.ErrorCategory]::ReadError), $targetFilePath)
$PSCmdlet.WriteError($errorRecord)
}
if($null -ne $currentFileStream)
{
$srcStream = [System.IO.BinaryReader]::new($currentFileStream)
$displayHeader = $true
$offset = 0
$blockCounter = 0
while($numberOfBytesRead = $srcStream.Read($buffer, 0, $bufferSize))
{
# send only the bytes that have been read
# if we send the whole buffer, we'll have extraneous bytes
# at the end of an incomplete group of 16 bytes
if ( $numberOfBytesRead -eq $bufferSize )
{
# under some circumstances if we don't copy the buffer
# and the results are stored to a variable, the results are not
# correct and one object replicated in all the output objects
ConvertToHexadecimalHelper ($buffer.Clone()) $targetFilePath $offset
}
else
{
# handle the case of the partial (and probably last) buffer
$bytesReadBuffer = [byte[]]::New($numberOfBytesRead)
[Array]::Copy($buffer,0, $bytesReadBuffer,0,$numberOfBytesRead)
ConvertToHexadecimalHelper $bytesReadBuffer $targetFilePath $offset
}
$displayHeader = $false
$blockCounter++;
# Updating the offset value.
$offset = $blockCounter*0x10
}
}
}
finally
{
If($null -ne $currentFileStream)
{
$currentFileStream.Dispose()
}
If($null -ne $srcStream)
{
$srcStream.Dispose()
}
}
}
}
}
process
{
switch($PSCmdlet.ParameterSetName)
{
"Path"
{
ProcessFileContent $Path $false
}
"LiteralPath"
{
ProcessFileContent $LiteralPath $true
}
"ByInputObject"
{
# If it's an actual byte array, then we directly use it for hexadecimal formatting.
if($InputObject -is [Byte[]])
{
ConvertToHexadecimalHelper $InputObject $null
return
}
# if it's a single byte, we'll assume streaming
elseif($InputObject -is [byte])
{
$null = $inputStreamArray.Add($InputObject)
}
# If the input data is of string type then directly get bytes out of it.
elseif($InputObject -is [string])
{
# The ValidateSet arribute on the Encoding paramter makes sure that only
# valid values (supported on all paltforms where Format-Hex is avaliable)
# are allowed through user input.
$inputBytes = [Text.Encoding]::$Encoding.GetBytes($InputObject)
ConvertToHexadecimalHelper $inputBytes $null
return
}
elseif($InputObject -is [System.IO.FileSystemInfo])
{
# If file path is provided as an input, use the file contents to show the hexadecimal format.
$filePath = ([System.IO.FileSystemInfo]$InputObject).FullName
ProcessFileContent $filePath $false
return
}
elseif($InputObject -is [int64])
{
$inputBytes = [BitConverter]::GetBytes($InputObject)
$null = $inputStreamArray.AddRange($inputBytes)
}
elseif($InputObject -is [int64[]])
{
foreach($i64 in $InputObject)
{
$inputBytes = [BitConverter]::GetBytes($i64)
$null = $inputStreamArray.AddRange($inputBytes)
}
}
elseif($InputObject -is [int])
{
# If we get what appears as ints, it may not be what the user really wants.
# for example, if the user types a small set of numbers just to get their
# character representations, as follows:
#
# 170..180 | format-hex
# Path:
# 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
#00000000 AA AB AC AD AE AF B0 B1 B2 B3 B4 ª«¬­®¯°±²³´
#
# any integer padding is likely to be more confusing than this
# fairly compact representation.
#
# However, some might like to see the results with the raw data,
# -Raw exists to provide that behavior:
# PS# 170..180 | format-hex -Raw
#
# Path:
#
# 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
#
# 00000000 AA 00 00 00 AB 00 00 00 AC 00 00 00 AD 00 00 00 ª...«...¬...­...
# 00000010 AE 00 00 00 AF 00 00 00 B0 00 00 00 B1 00 00 00 ®...¯...°...±...
# 00000020 B2 00 00 00 B3 00 00 00 B4 00 00 00 ²...³...´...
#
# this provides a representation of the piped numbers which includes all
# of the bytes which are in an int32
if ( $Raw )
{
$inputBytes = [BitConverter]::GetBytes($InputObject)
$null = $inputStreamArray.AddRange($inputBytes)
}
else
{
# first determine whether we can represent this as a byte
$possibleByte = $InputObject -as [byte]
# first determine whether we can represent this as a int16
$possibleInt16 = $InputObject -as [int16]
if ( $possibleByte -ne $null )
{
$null = $inputStreamArray.Add($possibleByte)
}
elseif ( $possibleint16 -ne $null )
{
$inputBytes = [BitConverter]::GetBytes($possibleInt16)
$null = $inputStreamArray.AddRange($inputBytes)
}
else
{
# now int
$inputBytes = [BitConverter]::GetBytes($InputObject)
$null = $inputStreamArray.AddRange($inputBytes)
}
}
}
else
{
# Otherwise, write a non-terminating error message indicating that input object type is not supported.
$errorMessage = [Microsoft.PowerShell.Commands.UtilityResources]::FormatHexTypeNotSupported -f $InputObject.GetType()
Write-Error -Message $errorMessage -Category ([System.Management.Automation.ErrorCategory]::ParserError) -ErrorId "FormatHexFailureTypeNotSupported"
}
# Handle streaming case here
# during this process we may not have enough characters to create a ByteCollection
# if we do, create as many ByteCollections as necessary, each being 16 bytes in length
if ( $inputStreamArray.Count -ge $bufferSize )
{
$rowCount = [math]::Floor($inputStreamArray.Count/$bufferSize)
$arrayLength = $bufferSize * $rowCount
for($i = 0; $i -lt $rowCount; $i++)
{
$rowOffset = $i * $bufferSize
ConvertToHexadecimalHelper -inputBytes $inputStreamArray.GetRange($rowOffset, $bufferSize) -path ' ' -offset $offset
$offset += $bufferSize
}
# We use RemoveRange because of the pathological case of having
# streamed combination of bytes, int16, int32, int64 which are greater
# than 16 bytes. Consider the case:
# $i = [int16]::MaxValue + 3
# $i64=[int64]::MaxValue -5
# .{ $i;$i;$i;$i64 } | format-hex
# which create an arraylist 20 bytes
# we need to remove only the bytes from the array which we emitted
$inputStreamArray.RemoveRange(0,$arrayLength)
}
}
}
}
end
{
# now manage any left over bytes in the $inputStreamArray
if ( $PSCmdlet.ParameterSetName -eq "ByInputObject" )
{
ConvertToHexadecimalHelper $inputStreamArray $null -path ' ' -offset $offset
}
}
}
## Imports a PowerShell Data File - a PowerShell hashtable defined in
## a file (such as a Module manifest, session configuration file)
function Import-PowerShellDataFile
{
[CmdletBinding(DefaultParameterSetName = "ByPath", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=623621")]
[OutputType("System.Collections.Hashtable")]
param(
[Parameter(ParameterSetName = "ByPath", Position = 0)]
[String[]] $Path,
[Parameter(ParameterSetName = "ByLiteralPath", ValueFromPipelineByPropertyName = $true)]
[Alias("PSPath")]
[String[]] $LiteralPath
)
begin
{
function ThrowInvalidDataFile
{
param($resolvedPath, $extraError)
$errorId = "CouldNotParseAsPowerShellDataFile$extraError"
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidData
$errorMessage = [Microsoft.PowerShell.Commands.UtilityResources]::CouldNotParseAsPowerShellDataFile -f $resolvedPath
$exception = [System.InvalidOperationException]::New($errorMessage)
$errorRecord = [System.Management.Automation.ErrorRecord]::New($exception, $errorId, $errorCategory, $null)
$PSCmdlet.WriteError($errorRecord)
}
}
process
{
foreach($resolvedPath in (Resolve-Path @PSBoundParameters))
{
$parseErrors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile(($resolvedPath.ProviderPath), [ref] $null, [ref] $parseErrors)
if ($parseErrors.Length -gt 0)
{
ThrowInvalidDataFile $resolvedPath
}
else
{
$data = $ast.Find( { $args[0] -is [System.Management.Automation.Language.HashtableAst] }, $false )
if($data)
{
$data.SafeGetValue()
}
else
{
ThrowInvalidDataFile $resolvedPath "NoHashtableRoot"
}
}
}
}
}
## Converts a SDDL string into an object-based representation of a security
## descriptor
function ConvertFrom-SddlString
{
[CmdletBinding(HelpUri = "http://go.microsoft.com/fwlink/?LinkId=623636")]
param(
## The string representing the security descriptor in SDDL syntax
[Parameter(Mandatory, Position = 0)]
[String] $Sddl,
## The type of rights that this SDDL string represents, if any.
[Parameter()]
[ValidateSet(
"FileSystemRights", "RegistryRights", "ActiveDirectoryRights",
"MutexRights", "SemaphoreRights", "CryptoKeyRights",
"EventWaitHandleRights")]
$Type
)
## Translates a SID into a NT Account
function ConvertTo-NtAccount
{
param($Sid)
if($Sid)
{
$securityIdentifier = [System.Security.Principal.SecurityIdentifier] $Sid
try
{
$ntAccount = $securityIdentifier.Translate([System.Security.Principal.NTAccount]).ToString()
}
catch{}
$ntAccount
}
}
## Gets the access rights that apply to an access mask, preferring right types
## of 'Type' if specified.
function Get-AccessRights
{
param($AccessMask, $Type)
## All the types of access rights understood by .NET
$rightTypes = [Ordered] @{
"FileSystemRights" = [System.Security.AccessControl.FileSystemRights]
"RegistryRights" = [System.Security.AccessControl.RegistryRights]
"ActiveDirectoryRights" = [System.DirectoryServices.ActiveDirectoryRights]
"MutexRights" = [System.Security.AccessControl.MutexRights]
"SemaphoreRights" = [System.Security.AccessControl.SemaphoreRights]
"CryptoKeyRights" = [System.Security.AccessControl.CryptoKeyRights]
"EventWaitHandleRights" = [System.Security.AccessControl.EventWaitHandleRights]
}
$typesToExamine = $rightTypes.Values
## If they know the access mask represents a certain type, prefer its names
## (i.e.: CreateLink for the registry over CreateDirectories for the filesystem)
if($Type)
{
$typesToExamine = @($rightTypes[$Type]) + $typesToExamine
}
## Stores the access types we've found that apply
$foundAccess = @()
## Store the access types we've already seen, so that we don't report access
## flags that are essentially duplicate. Many of the access values in the different
## enumerations have the same value but with different names.
$foundValues = @{}
## Go through the entries in the different right types, and see if they apply to the
## provided access mask. If they do, then add that to the result.
foreach($rightType in $typesToExamine)
{
foreach($accessFlag in [Enum]::GetNames($rightType))
{
$longKeyValue = [long] $rightType::$accessFlag
if(-not $foundValues.ContainsKey($longKeyValue))
{
$foundValues[$longKeyValue] = $true
if(($AccessMask -band $longKeyValue) -eq ($longKeyValue))
{
$foundAccess += $accessFlag
}
}
}
}
$foundAccess | Sort-Object
}
## Converts an ACE into a string representation
function ConvertTo-AceString
{
param(
[Parameter(ValueFromPipeline)]
$Ace,
$Type
)
process
{
foreach($aceEntry in $Ace)
{
$AceString = (ConvertTo-NtAccount $aceEntry.SecurityIdentifier) + ": " + $aceEntry.AceQualifier
if($aceEntry.AceFlags -ne "None")
{
$AceString += " " + $aceEntry.AceFlags
}
if($aceEntry.AccessMask)
{
$foundAccess = Get-AccessRights $aceEntry.AccessMask $Type
if($foundAccess)
{
$AceString += " ({0})" -f ($foundAccess -join ", ")
}
}
$AceString
}
}
}
$rawSecurityDescriptor = [Security.AccessControl.CommonSecurityDescriptor]::new($false,$false,$Sddl)
$owner = ConvertTo-NtAccount $rawSecurityDescriptor.Owner
$group = ConvertTo-NtAccount $rawSecurityDescriptor.Group
$discretionaryAcl = ConvertTo-AceString $rawSecurityDescriptor.DiscretionaryAcl $Type
$systemAcl = ConvertTo-AceString $rawSecurityDescriptor.SystemAcl $Type
[PSCustomObject] @{
Owner = $owner
Group = $group
DiscretionaryAcl = @($discretionaryAcl)
SystemAcl = @($systemAcl)
RawDescriptor = $rawSecurityDescriptor
}
}

View File

@ -0,0 +1,15 @@
@{
GUID="766204A6-330E-4263-A7AB-46C87AFC366C"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="3.0.0.0"
PowerShellVersion="3.0"
CLRVersion="4.0"
AliasesToExport = @()
FunctionsToExport = @()
CmdletsToExport="Disable-WSManCredSSP", "Enable-WSManCredSSP", "Get-WSManCredSSP", "Set-WSManQuickConfig", "Test-WSMan", "Invoke-WSManAction", "Connect-WSMan", "Disconnect-WSMan", "Get-WSManInstance", "Set-WSManInstance", "Remove-WSManInstance", "New-WSManInstance", "New-WSManSessionOption"
NestedModules="Microsoft.WSMan.Management.dll"
FormatsToProcess="WSMan.format.ps1xml"
HelpInfoURI = 'http://go.microsoft.com/fwlink/?linkid=390788'
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>PSRepositoryItemInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSRepositoryItemInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Type</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Repository</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Description</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSRepository</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSRepository</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>25</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>25</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>PackageManagementProvider</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>InstallationPolicy</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SourceLocation</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSScriptInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSScriptInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>25</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Author</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Description</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSGetDscResourceInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSGetCommandInfo</TypeName>
<TypeName>Microsoft.PowerShell.Commands.PSGetDscResourceInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ModuleName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Repository</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSGetRoleCapabilityInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSGetRoleCapabilityInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>10</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader/>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ModuleName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Repository</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff