Publish 0.2.0 #12

Merged
OCram85 merged 7 commits from dev into master 2017-12-22 08:10:37 +01:00
2 changed files with 79 additions and 12 deletions
Showing only changes of commit f831b1365d - Show all commits

View File

@ -20,6 +20,8 @@ function Connect-To {
- NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer.
- VMware Establish a connection to a VMware vCenter or ESXi host. - VMware Establish a connection to a VMware vCenter or ESXi host.
- CisServer Establish a connection to a Vmware CisServer. - CisServer Establish a connection to a Vmware CisServer.
- ExchangeHTTP Start a new remote session to the given Exchange server via unsecure http.
- Exchange HTTPS Start a new remote session to the given exchange server with the secure https endpoint.
.PARAMETER Credentials .PARAMETER Credentials
Use this parameter to bypass the stored credentials. Without this parameter Connect-To tries to read the Use this parameter to bypass the stored credentials. Without this parameter Connect-To tries to read the
@ -54,6 +56,12 @@ function Connect-To {
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost "vCenter.myside.local" -Type CisServer Connect-To -RemoteHost "vCenter.myside.local" -Type CisServer
.EXAMPLE
Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP
.EXAMPLE
Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
.EXAMPLE .EXAMPLE
$MyCreds = Get-Credential $MyCreds = Get-Credential
Connect-To -RemoteHost "vcr01.myside.local" -Type VMware -Credentials $MyCreds Connect-To -RemoteHost "vcr01.myside.local" -Type VMware -Credentials $MyCreds
@ -61,29 +69,28 @@ function Connect-To {
Disconnect-From -RemoteHost "vcr01.myside.local" -Type VMware Disconnect-From -RemoteHost "vcr01.myside.local" -Type VMware
.NOTES .NOTES
```
File Name : Connect-To.ps1 File Name : Connect-To.ps1
Author : Marco Blessing - marco.blessing@googlemail.com Author : Marco Blessing - marco.blessing@googlemail.com
Requires : Requires :
```
.LINK .LINK
https://github.com/OCram85/PSCredentialStore https://github.com/OCram85/PSCredentialStore
#> #>
[CmdletBinding(DefaultParameterSetName = "Private")] [CmdletBinding(DefaultParameterSetName = "Private")]
param( param(
[Parameter(Mandatory = $true, ParameterSetName = "Shared")] [Parameter(Mandatory = $true, ParameterSetName = "Shared")]
[Parameter(Mandatory = $true, ParameterSetName = "Private")] [Parameter(Mandatory = $true, ParameterSetName = "Private")]
[String]$RemoteHost, [string]$RemoteHost,
[Parameter(Mandatory = $false, ParameterSetName = "Shared")] [Parameter(Mandatory = $false, ParameterSetName = "Shared")]
[Parameter(Mandatory = $false, ParameterSetName = "Private")] [Parameter(Mandatory = $false, ParameterSetName = "Private")]
[String]$Identifier, [string]$Identifier,
[Parameter(Mandatory = $true, ParameterSetName = "Shared")] [Parameter(Mandatory = $true, ParameterSetName = "Shared")]
[Parameter(Mandatory = $true, ParameterSetName = "Private")] [Parameter(Mandatory = $true, ParameterSetName = "Private")]
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware", "CisServer")] [ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')]
[String]$Type, [string]$Type,
[Parameter(Mandatory = $False, ParameterSetName = "Shared")] [Parameter(Mandatory = $False, ParameterSetName = "Shared")]
[Parameter(Mandatory = $False, ParameterSetName = "Private")] [Parameter(Mandatory = $False, ParameterSetName = "Private")]
@ -91,10 +98,10 @@ function Connect-To {
[Parameter(Mandatory = $False, ParameterSetName = "Shared")] [Parameter(Mandatory = $False, ParameterSetName = "Shared")]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[String]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData, [string]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData,
[Parameter(Mandatory = $false, ParameterSetNAme = "Shared")] [Parameter(Mandatory = $false, ParameterSetNAme = "Shared")]
[Switch]$Shared [switch]$Shared
) )
begin { begin {
@ -225,6 +232,46 @@ function Connect-To {
Write-Error @MessageParams Write-Error @MessageParams
} }
} }
"ExchangeHTTP" {
try {
$ConnectionParams = @{
ConnectionURI = "http://{0}/powershell" -f $RemoteHost
ConfigurationName = 'Microsoft.Exchange'
Credential = $creds
ErrorAction = 'Stop'
}
$Global:PSExchangeRemote = New-PSSession @ConnectionParams
$Global:PSExchangeRemote
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = "Stop"
}
Write-Error @MessageParams
}
}
"ExchangeHTTPS" {
try {
$ConnectionParams = @{
ConnectionURI = "https://{0}/powershell" -f $RemoteHost
ConfigurationName = 'Microsoft.Exchange'
Credential = $creds
ErrorAction = 'Stop'
}
$Global:PSExchangeRemote = New-PSSession @ConnectionParams
$Global:PSExchangeRemote
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = "Stop"
}
Write-Error @MessageParams
}
}
default { default {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{

View File

@ -20,6 +20,8 @@ function Disconnect-From {
- NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer. - NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer.
- VMware Terminates the connection from a VMware vCenter or ESXi host. - VMware Terminates the connection from a VMware vCenter or ESXi host.
- CisServer Terminates the connection from a Vmware CisServer. - CisServer Terminates the connection from a Vmware CisServer.
- ExchangeHTTP Remove the existing remote session to the given Exchange server
- ExchangeHTTPS Remove the existing remote session to the given Exchange server
.PARAMETER Force .PARAMETER Force
Force the disconnect, even if the disconnect would fail. Force the disconnect, even if the disconnect would fail.
@ -47,12 +49,16 @@ function Disconnect-From {
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "vcenter.myside.local" -Type CisServer Disconnect-From -RemoteHost "vcenter.myside.local" -Type CisServer
.EXAMPLE
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP
.EXAMPLE
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
.NOTES .NOTES
```
File Name : Disconnect-From.ps1 File Name : Disconnect-From.ps1
Author : Marco Blessing - marco.blessing@googlemail.com Author : Marco Blessing - marco.blessing@googlemail.com
Requires : Requires :
```
.LINK .LINK
https://github.com/OCram85/PSCredentialStore https://github.com/OCram85/PSCredentialStore
@ -64,14 +70,14 @@ function Disconnect-From {
[string]$RemoteHost, [string]$RemoteHost,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware", "CisServer")] [ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')]
[string]$Type, [string]$Type,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[switch]$Force [switch]$Force
) )
switch ($Type) { switch -Regex ($Type) {
"VMware" { "VMware" {
try { try {
if ($Force) { if ($Force) {
@ -134,6 +140,7 @@ function Disconnect-From {
Write-Verbose @MessageParams Write-Verbose @MessageParams
$Global:CurrentNcController = $null $Global:CurrentNcController = $null
} }
catch { catch {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{
@ -158,6 +165,19 @@ function Disconnect-From {
Write-Error @MessageParams Write-Error @MessageParams
} }
} }
"ExchangeHTTP*" {
try {
Get-Variable -Name 'PSExchangeRemote' -Scope Global -ErrorAction Stop
Remove-PSSession -Session $Global:PSExchangeRemote -ErrorAction Stop
}
catch {
$MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = "Stop"
}
Write-Error @MessageParams
}
}
default { default {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{