@@ -26,7 +26,13 @@ function Copy-AWS
26
26
[string ]$Address ,
27
27
28
28
[Parameter (Mandatory = $False )]
29
- [switch ]$Recurse
29
+ [switch ]$Recurse ,
30
+
31
+ [Parameter (Mandatory = $False )]
32
+ [switch ]$Persist ,
33
+
34
+ [Parameter (Mandatory = $False )]
35
+ [switch ]$WhatIf
30
36
31
37
)
32
38
@@ -46,32 +52,33 @@ function Copy-AWS
46
52
$KeyFile = (Resolve-Path $KeyFile ).Path
47
53
}
48
54
49
- $KeyFile = if ($KeyFile ){" -i `" $KeyFile `" " }
50
55
51
56
$Username = if (! $Username ){$info.username }else {$Username }
52
57
53
58
$Password = if (! $Password ){$info.password }else {$Password }
54
- $Password = if ($Password ){" -pw $ ( $Password ) " }
55
59
56
60
$Address = if (! $Address ){$info.address }else {$Address }
57
-
58
-
59
61
}
60
62
63
+ $KeyFile = if ($KeyFile ){" -i `" $KeyFile `" " }
64
+ $Password = if ($Password ){" -pw $ ( $Password ) " }
65
+
66
+
61
67
Write-Verbose " pscp: $pscp "
62
68
Write-Verbose " root: $root "
63
- Write-Verbose " keyfile: $keyfile "
64
69
Write-Verbose " username: $Username "
65
- Write-Verbose " password: $Password "
66
70
Write-Verbose " address: $Address "
67
-
71
+ Write-Verbose " keyfile: $KeyFile "
72
+ Write-Verbose " password: $Password "
73
+
74
+ $CanRun = $source -and $destination -and $Username -and $Address
68
75
if ($Recurse ){$r = " -r" }
69
76
}
70
77
71
78
process {
72
- if ($info )
79
+ if ($CanRun )
73
80
{
74
- foreach ($path in $source )
81
+ foreach ($path in $Source )
75
82
{
76
83
$name = $path -split " [\\/]" | Select-Object - Last 1
77
84
@@ -85,16 +92,51 @@ function Copy-AWS
85
92
Write-Verbose " local destination"
86
93
$command = " & `" $pscp `" $r $keyfile $password $username @$ ( $address ) :$path $destination "
87
94
}
88
-
89
- Write-Verbose $command
90
- Invoke-Expression $command
95
+
96
+ if ($WhatIf )
97
+ {
98
+ Write-Host " Executes: $command "
99
+ }
100
+ else
101
+ {
102
+ Write-Verbose $command
103
+ Invoke-Expression $command
104
+ }
91
105
}
92
106
}
107
+ else
108
+ {
109
+ Write-Host " Missing Variable(s):"
110
+ Write-Host " username: $Username "
111
+ Write-Host " address: $Address "
112
+ }
93
113
94
114
}
95
115
96
116
end {
97
-
117
+ if ($CanRun -and $Persist )
118
+ {
119
+ # implement logic to write out variables to .pscp file
120
+ New-Item - Path .pscp - ItemType dir - Force
121
+
122
+ if ($Password ){$Password = $Password.Replace (" -pw " , " " )}
123
+
124
+ if ($KeyFile )
125
+ {
126
+ $KeyFile = $KeyFile.Replace (" -i " , " " )
127
+ Copy-Item - Path $KeyFile - Destination .pscp
128
+ $KeyFile = (Get-ChildItem $KeyFile ).Name
129
+ }
130
+
131
+ $file = @"
132
+ username=$Username
133
+ address=$Address
134
+ keyfile=$KeyFile
135
+ password=$Password
136
+ "@
137
+
138
+ New-Item - Path .pscp\pscp_info.txt - ItemType file - Value $file - Force
139
+ }
98
140
}
99
141
100
142
<#
@@ -164,8 +206,8 @@ function Get-Root
164
206
$driveRoot = [System.IO.Directory ]::GetDirectoryRoot($CurrentPath )
165
207
if ($CurrentPath -eq $driveRoot )
166
208
{
167
- Write-Host " Path: $CurrentPath is the drive root: $driveRoot "
168
- Write-Host " root path $FolderName not found."
209
+ Write-Verbose " Path: $CurrentPath is the drive root: $driveRoot "
210
+ Write-Verbose " root path $FolderName not found."
169
211
return
170
212
}
171
213
0 commit comments