-
Notifications
You must be signed in to change notification settings - Fork 17
/
Lesson4.ps1
116 lines (72 loc) · 2.99 KB
/
Lesson4.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Enter-PSSession -ComputerName MF1500D
Invoke-Command -ComputerName MF1500D -ScriptBlock {$cn = $env:COMPUTERNAME; write-host "Your ComputerName is $cn" -ForegroundColor Red}
Invoke-Command -ComputerName MF1500D, MF1498D -ScriptBlock {$cn = $env:COMPUTERNAME; write-host "Your ComputerName is $cn" -ForegroundColor Red}
Get-Help Invoke-Command
Invoke-Command -ComputerName MF1500D, MF1498D -ScriptBlock {$env:COMPUTERNAME}
Invoke-Command -ComputerName MF1500D -ScriptBlock{
Get-ChildItem C:\remoting
gci C:\
Get-Service Spooler
}
Invoke-Command -ComputerName MF1500D,MF1498D -ScriptBlock {
Get-Service | Select-Object -First 5
Get-Service BITS
}
$myservers = Get-ADComputer -Filter {name -like MF}
Invoke-Command -ComputerName <NetworkNameofPC> -FilePath <FilePathofPowerShellScripttoRun>
$cred = Get-Credential
$session1 = New-PSSession -ComputerName MF1500D -Credential $cred
Get-PSSession
Enter-PSSession -Session $session1
Get-PSSession | Remove-PSSession
Invoke-Command -Session $session1 -ScriptBlock {
Get-Service bits
}
Function Test-IsAdmin
{
<#
.Synopsis
Tests if the user is an administrator
.Description
Returns true if a user is an administrator, false if the user is not an administrator
.Example
Test-IsAdmin
#>
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
Invoke-Command -ComputerName MF1500D -ScriptBlock {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
Invoke-Command -ComputerName MF1500D -ScriptBlock {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
Invoke-Command -ComputerName MFHC1309L -ScriptBlock{
function Get-testpcinfo{
# ComputerSystem info
$CompInfo = Get-CimInstance Win32_ComputerSystem
# OS info
$OSInfo = Get-CimInstance Win32_OperatingSystem
# Serial No
$BiosInfo = Get-CimInstance Win32_BIOS
$diskfreespace = get-volume -DriveLetter c | Select-Object -ExpandProperty SizeRemaining
[pscustomobject]@{
ComputerName = $CompInfo.Name
Domain = $CompInfo.Domain
OperatingSystem = $OSInfo.Caption
Model = $CompInfo.Model
MachineSN = $BiosInfo.SerialNumber
Version = $OSInfo.caption
BuildNumber = $OSInfo.version
OSArchitecture = $OSinfo.OSArchitecture
PowerShellVersion = $PSVersionTable.psversion
DiskFreeSpace = "" +[math]::Round($diskfreespace /1GB,2) + " GB"
}
}
Get-testpcinfo
}