-
Notifications
You must be signed in to change notification settings - Fork 19
/
some stuff.ps1
51 lines (29 loc) · 1021 Bytes
/
some stuff.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
Get-Service
# However a better way is to se thte results to a variable
$A = Get-Service -ComputerName sql0
$A | Gm
# This way the variable is held in memory
$a
## Now we can access the properties
$a.ServiceName
# Using a foreach the $_ refers to "This"
$a.Foreach{$_.ServiceName }
## Use a loop
foreach($beard in $a)
{
$beard.ServiceName
}
## use the pipe
$A | ForEach-Object {$_.ServiceName }
## Use select
$A | Select-Object ServiceName
## NEVER forget that PowerShell Loves Objects and You should too
$a | Out-file C:\temp\Services.txt
notepad C:\temp\Services.txt
$A | Out-GridView -PassThru | Out-file C:\temp\ServiceOGV.txt
notepad C:\temp\ServiceOGV.txt
$a | ConvertTo-Csv | Out-File c:\temp\servicesCSV.csv
notepad c:\temp\servicesCSV.csv
Send-MailMessage -Body $a -From mrrobsewell@outlook.com -SmtpServer SMPT.Beard.Local -To Servicedesk@Beard.local -Subject "Oh no. It all failed" -Priority High
$a | ConvertTo-Html | Out-File c:\temp\services.html
Start-Process c:\temp\services.html