-
-
Save ChrisGibson1982/bfe4228d53ae77eab760bb1bceecfa99 to your computer and use it in GitHub Desktop.
ConvertFrom-Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ModuleManifestName = 'Convert-FromDocker.psd1' | |
| $ModuleManifestPath = "$PSScriptRoot\..\$ModuleManifestName" | |
| Describe 'Module Manifest Tests' { | |
| It 'Passes Test-ModuleManifest' { | |
| Test-ModuleManifest -Path $ModuleManifestPath | |
| $? | Should Be $true | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Module manifest for module 'ConvertFrom-Docker' | |
| # | |
| # Generated by: Chris Gibson | |
| # | |
| # Generated on: 07/09/2017 | |
| # | |
| @{ | |
| # Script module or binary module file associated with this manifest. | |
| RootModule = 'ConvertFrom-Docker' | |
| # Version number of this module. | |
| ModuleVersion = '0.1.0' | |
| # Supported PSEditions | |
| CompatiblePSEditions = 'Desktop', 'Core' | |
| # ID used to uniquely identify this module | |
| GUID = '15829c69-a90d-42d8-8b57-2b58094074eb' | |
| # Author of this module | |
| Author = 'Chris Gibson' | |
| # Company or vendor of this module | |
| CompanyName = 'Unknown' | |
| # Copyright statement for this module | |
| Copyright = '(c) 2017 Stuart Leeks. All rights reserved.' | |
| # Description of the functionality provided by this module | |
| Description = 'Forked from Stuart Leeks Excellent Script https://github.com/stuartleeks/ConvertFrom-Docker' | |
| # Minimum version of the Windows PowerShell engine required by this module | |
| # PowerShellVersion = '' | |
| # Name of the Windows PowerShell host required by this module | |
| # PowerShellHostName = '' | |
| # Minimum version of the Windows PowerShell host required by this module | |
| # PowerShellHostVersion = '' | |
| # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | |
| # DotNetFrameworkVersion = '' | |
| # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | |
| # CLRVersion = '' | |
| # Processor architecture (None, X86, Amd64) required by this module | |
| # ProcessorArchitecture = '' | |
| # Modules that must be imported into the global environment prior to importing this module | |
| # RequiredModules = @() | |
| # Assemblies that must be loaded prior to importing this module | |
| # RequiredAssemblies = @() | |
| # Script files (.ps1) that are run in the caller's environment prior to importing this module. | |
| # ScriptsToProcess = @() | |
| # Type files (.ps1xml) to be loaded when importing this module | |
| # TypesToProcess = @() | |
| # Format files (.ps1xml) to be loaded when importing this module | |
| # FormatsToProcess = @() | |
| # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | |
| # NestedModules = @() | |
| # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. | |
| FunctionsToExport = 'ConvertFrom-Docker' | |
| # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. | |
| CmdletsToExport = 'ConvertFrom-Docker' | |
| # Variables to export from this module | |
| VariablesToExport = '*' | |
| # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. | |
| AliasesToExport = '*' | |
| # DSC resources to export from this module | |
| # DscResourcesToExport = @() | |
| # List of all modules packaged with this module | |
| # ModuleList = @() | |
| # List of all files packaged with this module | |
| # FileList = @() | |
| # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | |
| PrivateData = @{ | |
| PSData = @{ | |
| # Tags applied to this module. These help with module discovery in online galleries. | |
| Tags = @('docker','core') | |
| # A URL to the license for this module. | |
| LicenseUri = 'https://github.com/stuartleeks/ConvertFrom-Docker/blob/master/LICENSE.md' | |
| # A URL to the main website for this project. | |
| ProjectUri = 'https://github.com/stuartleeks/ConvertFrom-Docker' | |
| # A URL to an icon representing this module. | |
| # IconUri = '' | |
| # ReleaseNotes of this module | |
| # ReleaseNotes = '' | |
| } # End of PSData hashtable | |
| } # End of PrivateData hashtable | |
| # HelpInfo URI of this module | |
| # HelpInfoURI = '' | |
| # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | |
| # DefaultCommandPrefix = '' | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .Synopsis | |
| Wrapper for the ConvertFrom-Docker script by Stuart Leeks | |
| .DESCRIPTION | |
| Wrapper for Stuart Leeks ConvertFrom-Docker script https://gist.github.com/stuartleeks/4661c3c05678eec822bc | |
| .EXAMPLE | |
| docker images | ConvertFrom-Docker | |
| Created : 2 days ago | |
| ImageId : 9e5c23b783d5 | |
| Size : 10.7GB | |
| Tag : core | |
| Repository : cgfootman/heroes | |
| Created : 4 weeks ago | |
| ImageId : be84290c2315 | |
| Size : 10.3GB | |
| Tag : latest | |
| Repository : microsoft/windowsservercore | |
| Created : 4 weeks ago | |
| ImageId : 28dad12ef0bc | |
| Size : 1.07GB | |
| Tag : latest | |
| Repository : microsoft/nanoserver | |
| .EXAMPLE | |
| docker ps -a | ConvertFrom-Docker | Where-object {$_.status -like "Exited*"} | |
| Image : cgfootman/heroes:core | |
| Ports : | |
| Names : heroescore | |
| Command : "C:\\ServiceMonitor..." | |
| Created : About an hour ago | |
| ContainerId : 7a63a3d6d281 | |
| Status : Exited (3221225786) 20 seconds ago | |
| .INPUTS | |
| Pipeline input from docker command | |
| .OUTPUTS | |
| PSObject | |
| .NOTES | |
| Wrapper for Stuart Leeks ConvertFrom-Docker script https://gist.github.com/stuartleeks/4661c3c05678eec822bc | |
| .COMPONENT | |
| .ROLE | |
| .FUNCTIONALITY | |
| Converts output from the docker command to a PowerShell Object | |
| #> | |
| function ConvertFrom-Docker | |
| { | |
| [CmdletBinding(ConfirmImpact='Low')] | |
| [OutputType([String])] | |
| Param | |
| ( | |
| # Docker output via the pipeline | |
| [Parameter(Mandatory = $true, | |
| ValueFromPipeline=$true)] | |
| $dockerInput | |
| ) | |
| begin{ | |
| $positions = $null; | |
| } | |
| process { | |
| if($positions -eq $null) { | |
| # header row => determine column positions | |
| $positions = GetColumnInfo -headerRow $dockerInput #-propertyNames $propertyNames | |
| } else { | |
| # data row => output! | |
| ParseRow -row $dockerInput -columnInfo $positions | |
| } | |
| } | |
| end { | |
| } | |
| } | |
| function PascalName($name){ | |
| $parts = $name.Split(" ") | |
| for($i = 0 ; $i -lt $parts.Length ; $i++){ | |
| $parts[$i] = [char]::ToUpper($parts[$i][0]) + $parts[$i].SubString(1).ToLower(); | |
| } | |
| $parts -join "" | |
| } | |
| function GetHeaderBreak($headerRow, $startPoint=0){ | |
| $i = $startPoint | |
| while( $i + 1 -lt $headerRow.Length) | |
| { | |
| if ($headerRow[$i] -eq ' ' -and $headerRow[$i+1] -eq ' '){ | |
| return $i | |
| break | |
| } | |
| $i += 1 | |
| } | |
| return -1 | |
| } | |
| function GetHeaderNonBreak($headerRow, $startPoint=0){ | |
| $i = $startPoint | |
| while( $i + 1 -lt $headerRow.Length) | |
| { | |
| if ($headerRow[$i] -ne ' '){ | |
| return $i | |
| break | |
| } | |
| $i += 1 | |
| } | |
| return -1 | |
| } | |
| function GetColumnInfo($headerRow){ | |
| $lastIndex = 0 | |
| $i = 0 | |
| while ($i -lt $headerRow.Length){ | |
| $i = GetHeaderBreak $headerRow $lastIndex | |
| if ($i -lt 0){ | |
| $name = $headerRow.Substring($lastIndex) | |
| New-Object PSObject -Property @{ HeaderName = $name; Name = PascalName $name; Start=$lastIndex; End=-1} | |
| break | |
| } else { | |
| $name = $headerRow.Substring($lastIndex, $i-$lastIndex) | |
| $temp = $lastIndex | |
| $lastIndex = GetHeaderNonBreak $headerRow $i | |
| New-Object PSObject -Property @{ HeaderName = $name; Name = PascalName $name; Start=$temp; End=$lastIndex} | |
| } | |
| } | |
| } | |
| function ParseRow($row, $columnInfo) { | |
| $values = @{} | |
| $columnInfo | ForEach-Object { | |
| if ($_.End -lt 0) { | |
| $len = $row.Length - $_.Start | |
| } else { | |
| $len = $_.End - $_.Start | |
| } | |
| $values[$_.Name] = $row.SubString($_.Start, $len).Trim() | |
| } | |
| New-Object PSObject -Property $values | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function PascalName($name){ | |
| $parts = $name.Split(" ") | |
| for($i = 0 ; $i -lt $parts.Length ; $i++){ | |
| $parts[$i] = [char]::ToUpper($parts[$i][0]) + $parts[$i].SubString(1).ToLower(); | |
| } | |
| $parts -join "" | |
| } | |
| function GetHeaderBreak($headerRow, $startPoint=0){ | |
| $i = $startPoint | |
| while( $i + 1 -lt $headerRow.Length) | |
| { | |
| if ($headerRow[$i] -eq ' ' -and $headerRow[$i+1] -eq ' '){ | |
| return $i | |
| break | |
| } | |
| $i += 1 | |
| } | |
| return -1 | |
| } | |
| function GetHeaderNonBreak($headerRow, $startPoint=0){ | |
| $i = $startPoint | |
| while( $i + 1 -lt $headerRow.Length) | |
| { | |
| if ($headerRow[$i] -ne ' '){ | |
| return $i | |
| break | |
| } | |
| $i += 1 | |
| } | |
| return -1 | |
| } | |
| function GetColumnInfo($headerRow){ | |
| $lastIndex = 0 | |
| $i = 0 | |
| while ($i -lt $headerRow.Length){ | |
| $i = GetHeaderBreak $headerRow $lastIndex | |
| if ($i -lt 0){ | |
| $name = $headerRow.Substring($lastIndex) | |
| New-Object PSObject -Property @{ HeaderName = $name; Name = PascalName $name; Start=$lastIndex; End=-1} | |
| break | |
| } else { | |
| $name = $headerRow.Substring($lastIndex, $i-$lastIndex) | |
| $temp = $lastIndex | |
| $lastIndex = GetHeaderNonBreak $headerRow $i | |
| New-Object PSObject -Property @{ HeaderName = $name; Name = PascalName $name; Start=$temp; End=$lastIndex} | |
| } | |
| } | |
| } | |
| function ParseRow($row, $columnInfo) { | |
| $values = @{} | |
| $columnInfo | ForEach-Object { | |
| if ($_.End -lt 0) { | |
| $len = $row.Length - $_.Start | |
| } else { | |
| $len = $_.End - $_.Start | |
| } | |
| $values[$_.Name] = $row.SubString($_.Start, $len).Trim() | |
| } | |
| New-Object PSObject -Property $values | |
| } | |
| function ConvertFrom-Docker(){ | |
| begin{ | |
| $positions = $null; | |
| } | |
| process { | |
| if($positions -eq $null) { | |
| # header row => determine column positions | |
| $positions = GetColumnInfo -headerRow $_ #-propertyNames $propertyNames | |
| } else { | |
| # data row => output! | |
| ParseRow -row $_ -columnInfo $positions | |
| } | |
| } | |
| end { | |
| } | |
| } | |
| # e.g. : | |
| # docker --tls ps -a --no-trunc | ConvertFrom-Docker | ft |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "CurrentProjectSetting": null | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // When enabled, will trim trailing whitespace when you save a file. | |
| "files.trimTrailingWhitespace": true | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Available variables which can be used inside of strings. | |
| // ${workspaceRoot}: the root folder of the team | |
| // ${file}: the current opened file | |
| // ${relativeFile}: the current opened file relative to workspaceRoot | |
| // ${fileBasename}: the current opened file's basename | |
| // ${fileDirname}: the current opened file's dirname | |
| // ${fileExtname}: the current opened file's extension | |
| // ${cwd}: the current working directory of the spawned process | |
| { | |
| // See https://go.microsoft.com/fwlink/?LinkId=733558 | |
| // for the documentation about the tasks.json format | |
| "version": "0.1.0", | |
| // Start PowerShell | |
| "windows": { | |
| "command": "${env.windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe" | |
| }, | |
| "linux": { | |
| "command": "/usr/bin/powershell" | |
| }, | |
| "osx": { | |
| "command": "/usr/local/bin/powershell" | |
| }, | |
| // The command is a shell script | |
| "isShellCommand": true, | |
| // Show the output window always | |
| "showOutput": "always", | |
| "args": [ | |
| "-NoProfile", "-ExecutionPolicy", "Bypass" | |
| ], | |
| // Associate with test task runner | |
| "tasks": [ | |
| { | |
| "taskName": "Test", | |
| "suppressTaskName": true, | |
| "isTestCommand": true, | |
| "showOutput": "always", | |
| "args": [ | |
| "Write-Host 'Invoking Pester'; Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true};", | |
| "Invoke-Command { Write-Host 'Completed Test task in task runner.' }" | |
| ], | |
| "problemMatcher": [ | |
| { | |
| "owner": "powershell", | |
| "fileLocation": ["absolute"], | |
| "severity": "error", | |
| "pattern": [ | |
| { | |
| "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$", | |
| "message": 1 | |
| }, | |
| { | |
| "regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$", | |
| "file": 1, | |
| "line": 2 | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "ExpandedNodes": [ | |
| "" | |
| ], | |
| "PreviewInSolutionExplorer": false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment