![]() |
|
Spaces home Roman's spaceProfileFriendsBlog | ![]() |
Roman's spaceRoman's PowerShelf
|
May 07 V2: Debugger for Graphical PowerShell V2 CTP2
What's new in V2
Download: Utility_GPowerShellDebugger2.zip May 05 Debugger for Graphical PowerShell V2 CTP2
Download: Utility_GPowerShellDebugger.zip (EDIT: the next version is here...) October 11 PowerShell.hrc for Colorer, version 1.3.4PowerShell.hrc for Colorer, version 1.3.4EDIT: updated link: PowerShell.hrc for V2 CTP2What's new: REGEX and SQL schemes are supported in PowerShell literal strings. Flexibility and power of COLORER is amazing - it not only supports tons of file formats, but also allows combining schemes together (e.g. HTML scheme supports embedded JScript, VBScript and etc. reusing their schemes). As for the PowerShell, in new version of PowerShell.hrc I tried to use REGEX and SQL schemes in literal strings.
Examples of highlighting in PowerShell strings### Regex in operands "ab11* 'foo\'" -notmatch '^ab[0-2](\d+)\*\s+''(\w+)\\''' 'ab11* "foo\"' -match "^ab[0-2]$(2 - 1)\*\s+$($null)$null`"foo\\`"" '2007-9-23' -replace '\b(\d{2,4})-([01]?\d)-([012]?\d)\b', '$3/$2/$1' ### Regex in here strings $re = @' #REGEX Id and Name \#(?<Id>\d+) # #number \s+ # spaces (?<Name>[_a-zA-Z]\w*) # name '@ # how to use such a pattern: New-Object Regex $re, 'IgnorePatternWhitespace' ### SQL in here strings @' --SQL single quoted SELECT Data1, COUNT(1) FROM Table1 WHERE Data1 = '$literal' GROUP BY Data1 '@ @" --SQL double quoted SELECT Data1, COUNT(1) FROM $Table WHERE $x = '$variable' GROUP BY Data1 "@ March 16 Example of a PowerShell script converted to HTML with syntax highlightingThis is not a real script, it is a script used for testing of syntax description PowerShell.hrc for Colorer and covering related issues. Perhaps this HTML looks like a Christmas Tree, no problem, it is just a demo. One can configure Colorer according to his preferences. Take a look at how it handles and distinguishes expandable and not expandable string content and escaping rules, is not it a beauty? Demo-PowerShell.hrc.ps1## ## Demo script for testing PowerShell.hrc with Colorer ## The content is weird but compilable PowerShell code ## { # block begin (test 'Match pair' in Far editor) ### Numbers .88, .88L, .88Mb, .88Lmb, .88e-88, .88kb, .88lmb # floats with start dot 88., 88.L, 88.gb, 88.lmb # floats with end dot 8e-8, 8e-8L, 8e-8lmb # floats with no dot 8.8, 8.8e-8L, 8.8e-8mb, # other floats 0xF, 0xfl, 0xFmb, 0xFlmb # hex numbers 8, 8l, 8mb, 8lmb # dec numbers 1..111 # range ### Variables $ERROR, $true, $false # system variables $var, ${2b`} | `{!2b} # variable with normal and complex name @($global:var, $env:var) # array with scoped/provider variables $e=3.14;$e='1234';$e="1234";$e=@(1..9) # variable=value ### Escaped, Expanded, Strings `Get-`Item * $x = $(if (Get-Item) {"xx"} else {"yy"}) & {'8;$x;,Get-Item|-eq x $($env:X; `"ps`" -eq 12kb | kb; mb, Get-Item) '' `` `" `n`t ${2b|!2b} gb}}{{ ', $e} & {"8;$x;,Get-Item|-eq x $($env:X; `"ps`" -eq 12kb | kb; mb, Get-Item) '' `` `" `n`t ${2b|!2b} gb}}{{ ", $e} $x = @' $($env:var; "xxx" -like 1; x, Get-Item # not expandable here-string ) ' `" $var }} '' `' `" this is a text in both strings `n ${2b | !2b} {{ `n " '@ + (Get-Item L, 1L) + $var $x = @" $($env:var; "xxx" -like 1; x, Get-Item # expandable here-string ) ' `" $var }} '' `' `" this is a text in both strings `n ${2b | !2b} {{ `n " "@ + (Get-Item L, 1L) + $var ### Types and Indices: mind case, dot, {}, [] [int]; [INT[]]; [system.datetime]; [SYSTEM.DATETIME[]] & { $a = [int[]] 0 $a[$a[$a[0]]] } ### Filters and Functions FILTER f1([string]$s, [int[]]$ai) {} filter f2() {} $(filter f3() {}); filter f4 {filter f5() {}} FUNCTION fn1 { function fn2 {} ; function fn3($x) {} } ### Operators and Parameters: parameters must not be treated as keywords 1 -eq 1; 1 -and 1 fi1 -param -else -filter -function -if fn1 -Prm1(123) -Prm2'123' -Prm3:123 -Prm4:'123' ### Redirection Operators # uncomment the end of line to see 2 errors 1 > $null; 1 >> $null; 1 2> $null; 1 2>> $null; 1 2>&1 # 1 < $null; 1 1>&2 $null # hashes @{key1 = 11; key2 = 22} @{ key1 = 11 key2 = 22 } ### Block with some resolved issues { $e, '', $e $e, "", $e $e, '''', $e $e, " `` `a `n `Night ", $e } ### Foreach foreach ($x in $x) {} # is keyword 1 | foreach {} ### TODO foreach is not keyword here ### Cmdlets and not cmdlets $x=Get-Item; $x|Get-Item # are keywords $x=Get-Item-; $x|Get-Item- # are not keywords ### FIXED ISSUES (DON'T CHANGE!) $x.Prop/2 "$($_.Name)=$($_.Value)" } # block end (test 'Match pair' in Far editor) December 14 Get-Drive.ps1 and Get-File.ps1 - Get all local filesSynopsisThe task of iterating through all local files may be not straightforward if there are several drives including removable, network or substituted drives and NTFS reparse points directories. Get-Drive.ps1 and Get-File.ps1 used together may help: Get-Drive.ps1 returns only local physical drives, Get-File.ps1 excludes reparse points. Examples# calculate total available free space in GB (Get-Drive | Measure-Object AvailableFreeSpace -Sum).Sum/1GB # get paths of all local .bak files Get-File \\ *.bak -Name Get-Drive.ps1## ## Author : Roman Kuzmin ## Synopsis : Get physical drives ## ## Returns System.IO.DriveInfo objects ## ## *) removable, network and subst drives are excluded. ## $subst = [string](subst) foreach($d in [System.IO.DriveInfo]::GetDrives()) { if ($d.DriveType -eq 'Fixed' -and $subst -notlike "*$($d.Name):*") { $d } } Get-File.ps1## ## Author : Roman Kuzmin ## Synopsis : Get all files ## ## Returns System.IO.FileInfo objects or full names. ## -Root: root directory(s); single \\ or // denotes all physical drives. ## -Filter: simple file system filter. ## -Name: return full names as strings. ## ## *) requires Get-Drive.ps1. ## *) access errors are silently ignored. ## *) hidden and system files are included. ## *) reparse points directories are excluded. ## param ( [string[]]$Root = '.', [string]$Filter = '*', [switch]$Name ) function DirectoryFiles([System.IO.DirectoryInfo]$di) { # ignore errors trap {continue} # skip a reparse point if ($di.Attributes -band [System.IO.FileAttributes]::ReparsePoint) { return } # files if ($Name) { foreach($f in $di.GetFiles($Filter)) { $f.FullName } } else { $di.GetFiles($Filter) } # directories foreach($d in $di.GetDirectories()) { DirectoryFiles $d } } if ($Root.Count -eq 1 -and ($Root[0] -eq '\\' -or $Root[0] -eq '//')) { foreach($d in Get-Drive) { DirectoryFiles $d.RootDirectory } } else { foreach($d in $Root) { DirectoryFiles $d } }
|
||||
|
|