-
Notifications
You must be signed in to change notification settings - Fork 2
/
chapter_19.ps1
58 lines (37 loc) · 1.02 KB
/
chapter_19.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
#region Write for Cross-Platform
ls -Path 'C:\SomeFolder' | ForEach-Object { $_.Encrypt() }
#endregion
#region Don’t Query the Win32_Product CIM Class
Get-CimInstance -Class Win32_Product
#endregion
#region Store “Formattable” Strings for Later Use
'Hi, I am {0} {1}' -f 'Adam','Bertram'
$FString = "SELECT * FROM some.dbo WHERE Hostname = '{0}'"
"comp1","comp2" | ForEach-Object {
Invoke-SQLcmd -Query ($FString -f $_)
}
#endregion
#region Use Out-GridView for GUI-Based Sorting and Filtering
Get-Service | Out-GridView
#endregion
#region Don’t Make Automation Scripts Interactive
function Do-Thing {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Foo
)
}
Do-Thing
function Do-Thing {
[CmdletBinding()]
param(
[Parameter()]
[string]$Foo
)
$thing = Read-Host -Prompt 'I need some input!'
## Do stuff with $thing
}
Do-Thing
$credential = Get-Credential -Message 'Needs some love here'
#endregion