-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-File.ps1
99 lines (71 loc) · 1.92 KB
/
Test-File.ps1
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
#File with different PsScriptAnalyzer violations
#show-ast shows AST objects tree - very visual
# comes with ShowPSAst module
Show-Ast -InputObject .\Test-File.ps1
#strings
$variable = "string"
"string and $variable"
"string and $($variable.Length)"
'As they say, "live and learn."'
#Using alias
gps
#variable not using camelCase
$NowNow = Get-Date
$nowNow = Get-Date
$now = Get-Date
$NOWNOW = Get-Date
$now_date = Get-Date
Get-Process | Where-Object -FilterScript { $_.ProcessName -eq 'svchost' }
$PSItem
$env:Path
[System.Collections.ArrayList]$labels = @()
[string]$variable = 'hello'
$variable = 'hello again'
Write-Output $nowNow
Write-Output $now_date
Write-Output $now
Write-Output $labels
#parameter name not using PascalCase
Get-Date -verbose
#parameter name using PascalCase
Get-Date -Verbose
#using semicolon
$sdsdd_dsds = Get-Date;
Write-Output `
"Some text"
`
`
Write-Output "Output 1"
$date = Get-Date
Write-Output $date
Write-Output $variable
Get-Date `
-Verbose
$string1 = '_'
$string2 = 'some_text'
$regex = '._.'
$regex2 = '^[a-z]+([A-Za-z0-9]+)+'
$string1 -match $regex
$string2 -match $regex
$string1 -cnotmatch $regex2
$string2 -cnotmatch $regex2
((($string1 -cnotmatch $regex2) -and ($string1 -ne '_')) -or ($string1 -match $regex))
# for _ True -or False
(($string1 -cnotmatch '^[a-z]+([A-Za-z0-9]+)+') -and ($string1 -ne '_')) -or ($string1 -match '._.')
((($string -cnotmatch $regex2) -and ($string2 -ne '_')) -or ($string2 -match $regex))
$VariableAst.VariablePath = '_'
(($VariableAst.VariablePath -cnotmatch '^[a-z]+([A-Za-z0-9]+)+') -and ($VariableAst.VariablePath -ne '_')) -or ($VariableAst.VariablePath -match '._.')
$ErrorActionPreference = 'Break'
$script:foo = 'bar'
$ENV:APPDATA
$Env:AppDate
$True
$Using:exclude
function SameplFunction {
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty]
$SampleParameterName
)
Write-Output $SampleParameterName
}