[wip] add dynparam
This commit is contained in:
parent
b6e791f709
commit
ef64e087c5
@ -108,6 +108,21 @@ function Connect-To {
|
|||||||
[switch]$PassThru
|
[switch]$PassThru
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DynamicParam {
|
||||||
|
if ($Type -eq 'FTP') {
|
||||||
|
$Attributes = [System.Management.Automation.ParameterAttribute]@{ }
|
||||||
|
$AttributeCollection = [System.Collections.ObjectModel.Collection[System.Attribute]]@{ }
|
||||||
|
$AttributeCollection.Add($Attributes)
|
||||||
|
$SessionDynParam = [System.Management.Automation.RuntimeDefinedParameter]@{
|
||||||
|
Name = 'SessionOptions'
|
||||||
|
ParameterType = [WinSCP.SessionOptions]
|
||||||
|
$Attributes = $AttributeCollection
|
||||||
|
}
|
||||||
|
$ParamDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]@{ }
|
||||||
|
$ParamDictionary.Add('SessionOptions', $SessionDynParam)
|
||||||
|
return $ParamDictionary
|
||||||
|
}
|
||||||
|
}
|
||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
@ -188,16 +203,21 @@ function Connect-To {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"FTP" {
|
"FTP" {
|
||||||
# First establish the FTP session
|
|
||||||
$WinSCPConParams = @{
|
|
||||||
Credential = $creds
|
|
||||||
Hostname = $RemoteHost
|
|
||||||
Protocol = 'Ftp'
|
|
||||||
FtpMode = 'Passive'
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
$FTPSessionOption = New-WinSCPSessionOption @WinSCPConParams
|
# First establish the FTP session
|
||||||
$Global:WinSCPSession = New-WinSCPSession -SessionOption $FTPSessionOption
|
if ($null -ne $PSBoundParameters.SessionOptions) {
|
||||||
|
$Global:WinSCPSession = New-WinSCPSession -SessionOption $PSBoundParameters.SessionOptions
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$WinSCPConParams = @{
|
||||||
|
Credential = $creds
|
||||||
|
Hostname = $RemoteHost
|
||||||
|
Protocol = 'Ftp'
|
||||||
|
FtpMode = 'Passive'
|
||||||
|
}
|
||||||
|
$FTPSessionOption = New-WinSCPSessionOption @WinSCPConParams
|
||||||
|
$Global:WinSCPSession = New-WinSCPSession -SessionOption $FTPSessionOption
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
throw "Could not connect to {0} using {1} protocol!" -f $RemoteHost, $Type
|
throw "Could not connect to {0} using {1} protocol!" -f $RemoteHost, $Type
|
||||||
|
Loading…
Reference in New Issue
Block a user