1 | Get-ChildItem -Path $env:APPDATA\Code\Backups\*\untitled -Recurse |
1 2 3 | Get-ChildItem -Path $env:APPDATA\Code\Backups\*\untitled -Recurse | Select-String -SimpleMatch 'mikefrobbins' | Format-Table |
Scripting | Automation | Efficiency
1 | Get-ChildItem -Path $env:APPDATA\Code\Backups\*\untitled -Recurse |
1 2 3 | Get-ChildItem -Path $env:APPDATA\Code\Backups\*\untitled -Recurse | Select-String -SimpleMatch 'mikefrobbins' | Format-Table |
1 2 3 4 5 6 7 8 9 10 | $PSDefaultParameterValues = @{ 'Out-Default:OutVariable' = 'LastResult' 'Out-File:Encoding' = 'utf8' 'Export-Csv:NoTypeInformation' = $true 'ConvertTo-Csv:NoTypeInformation' = $true 'Receive-Job:Keep' = $true 'Install-Module:AllowClobber' = $true 'Install-Module:Force' = $true 'Install-Module:SkipPublisherCheck' = $true } |
1 | Get-WindowsOptionalFeature -FeatureName *hyper*powershell -Online |
1 | Get-WindowsFeature -Name *hyper*powershell |
1 | Get-VM | Select-Object -Property Name, Generation |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #Requires -Version 3.0 function Get-MrAst { <# .SYNOPSIS Explores the Abstract Syntax Tree (AST). .DESCRIPTION Get-MrAST is an advanced function that provides a mechanism for exploring the Abstract Syntax Tree (AST). .PARAMETER Path Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory. .PARAMETER Code The code to view the AST for. If Get-Content is being used to obtain the code, use its -Raw parameter otherwise the formating of the code will be lost. .PARAMETER ScriptBlock An instance of System.Management.Automation.ScriptBlock Microsoft .NET Framework type to view the AST for. .PARAMETER AstType The type of object to view the AST for. If this parameter is ommited, only the top level ScriptBlockAst is returned. .EXAMPLE Get-MrAST -Path 'C:\Scripts' -AstType FunctionDefinition .EXAMPLE Get-MrAST -Code 'function Get-PowerShellProcess {Get-Process -Name PowerShell}' .EXAMPLE Get-MrAST -ScriptBlock ([scriptblock]::Create('function Get-PowerShellProcess {Get-Process -Name PowerShell}')) .NOTES Author: Mike F Robbins Website: http://mikefrobbins.com Twitter: @mikefrobbins #> [CmdletBinding(DefaultParameterSetName='Path')] param( [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, ValueFromRemainingArguments, ParameterSetName = 'Path', Position = 1)] [ValidateNotNull()] [Alias('FilePath')] [string[]]$Path = ('.\*.ps1', '.\*.psm1'), [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromRemainingArguments, ParameterSetName = 'Code')] [string[]]$Code, [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromRemainingArguments, ParameterSetName = 'ScriptBlock')] [scriptblock[]]$ScriptBlock ) DynamicParam { $ParameterAttribute = New-Object -TypeName System.Management.Automation.ParameterAttribute $ParameterAttribute.Position = 0 $ValidationValues = Get-MrAstType $ValidateSetAttribute = New-Object -TypeName System.Management.Automation.ValidateSetAttribute($ValidationValues) $AttributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] $AttributeCollection.Add($ParameterAttribute) $AttributeCollection.Add($ValidateSetAttribute) $ParameterName = 'AstType' $RuntimeParameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection) $RuntimeParameterDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter) $RuntimeParameterDictionary } BEGIN { $AstType = $PsBoundParameters[$ParameterName] } PROCESS { switch ($PSCmdlet.ParameterSetName) { 'Path' { Write-Verbose -Message 'Path Parameter Set Selected' Write-Verbose "Path contains $Path" $Files = Get-ChildItem -Path $Path -Exclude *tests.ps1, *profile.ps1 | Select-Object -ExpandProperty FullName if (-not ($Files)) { Write-Warning -Message 'No valid files found.' Return } $AST = foreach ($File in $Files) { [System.Management.Automation.Language.Parser]::ParseFile($File, [ref]$null, [ref]$null) } break } 'Code' { Write-Verbose -Message 'Code Parameter Set Selected' $AST = foreach ($c in $Code) { [System.Management.Automation.Language.Parser]::ParseInput($c, [ref]$null, [ref]$null) } break } 'ScriptBlock' { Write-Verbose -Message 'ScriptBlock Parameter Set Selected' $AST = $ScriptBlock.Ast break } default { Write-Warning -Message 'An unexpected error has occurred' } } if ($PsBoundParameters.AstType) { Write-Verbose -Message 'AstType Parameter Entered' $AST = $AST.FindAll({$args[0].GetType().Name -like "$($ASTType)Ast"}, $true) } Write-Output $AST } } |
1 | Get-MrAst -Path .\Hyper-V\MrHyperV\public\ |
1 2 3 4 5 6 7 8 | Get-Service -Name Win* | Sort-Object -Property @{ expression = 'Status' descending = $true }, @{ expression = 'DisplayName' descending = $false } |
1 | Get-Service -Name Win* | Sort-Object -Property @{expression = 'Status';descending = $true}, @{expression = 'DisplayName';descending = $false} |
1 | Get-Command -Module Microsoft.PowerShell.LocalAccounts |