-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagingPSSessions.ps1
56 lines (34 loc) · 1.21 KB
/
ManagingPSSessions.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
# Managing PowerShell Sessions
# All commands available for -PSSession
get-command -Name *-PSSession
#Create a PSSession
$ComputerName = "DC01"
$credential = Get-Credential
# Create a new Session
New-PSSession -ComputerName $ComputerName -Credential $credential -Name DC01-Session
# View Avaialbel Sessions
Get-PSSession
# Enter a Session
Enter-PSSession -Name DC01-Session
Disconnect-PSSession -Name DC01-Session
Connect-PSSession -Name DC01-session
Enter-PSSession -Name DC01-Session
# Remove A Session
Get-PSSession
Remove-PSSession -id 17
# View Sessions
Get-PSSession
#Import commands from a remote system
$ComputerName = "DC01"
$credential = Get-Credential
$NewSession = New-PSSession -ComputerName $ComputerName -Credential $credential -Name DC01-Import
Get-PSSession
# Use Import-Session to access scripts, cmdlets, and functions on a remote system
Import-PSSession -Session $NewSession -CommandName Get-ADUSer -FormatTypeName *
Get-Command -Name Get-ADUSer
Get-ADUser -Identity psuser | format-list
# Import Module
Invoke-Command -Session $NewSession {Import-Module -Name ActiveDirectory}
Import-PSSession -Session $NewSession -Module ActiveDirectory
# Note Temporary Name of module
Get-command -Name Get-