-
Notifications
You must be signed in to change notification settings - Fork 14
/
New-RDPFile.ps1
61 lines (50 loc) · 2.97 KB
/
New-RDPFile.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
function New-RDPFile
{
<#
.Synopsis
Creates a new Remote Desktop file
.Description
Creates a new Remote Desktop file that can connect with a credential
.Example
New-RDPFile -ComputerName MyComputer
.Link
ConvertFrom-SecureString
#>
[OutputType([string])]
param(
# The computername
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[Alias('CN')]
[string]
$ComputerName,
# The credential. RDP files created with this credential will only work on this machine
[Management.Automation.PSCredential]
$Credential
)
process {
#region Connection and Screen Settings
$RdpFileContent = "
full address:s:" + $ComputerName
$RdpFileContent += "
screen mode id:i:2
promptcredentialonce:i:1"
#endregion Connection and Screen Settings
#region Embed Credential
if ($psboundParameters.Credential) {
$RdpFileContent += "
username:s:" + $credential.Username
$RdpFileContent += "
password 51:b:" + ($credential.password | ConvertFrom-SecureString)
}
#endregion Embed Credential
if ($RunCommand) {
$RdpFileContent += "
shell working directory:s:
alternate shell:s:" + $RunCommand
}
$RdpFileContent
}
}