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.
- VMware Establish a connection to a VMware vCenter or ESXi host.
- 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
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
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
$MyCreds = Get-Credential
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
.NOTES
```
File Name : Connect-To.ps1
Author : Marco Blessing - marco.blessing@googlemail.com
Requires :
```
.LINK
https://github.com/OCram85/PSCredentialStore
#>
[CmdletBinding(DefaultParameterSetName = "Private")]
param(
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
[String]$RemoteHost,
[string]$RemoteHost,
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
[String]$Identifier,
[string]$Identifier,
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware", "CisServer")]
[String]$Type,
[ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')]
[string]$Type,
[Parameter(Mandatory = $False, ParameterSetName = "Shared")]
[Parameter(Mandatory = $False, ParameterSetName = "Private")]
@ -91,10 +98,10 @@ function Connect-To {
[Parameter(Mandatory = $False, ParameterSetName = "Shared")]
[ValidateNotNullOrEmpty()]
[String]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData,
[string]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData,
[Parameter(Mandatory = $false, ParameterSetNAme = "Shared")]
[Switch]$Shared
[switch]$Shared
)
begin {
@ -225,6 +232,46 @@ function Connect-To {
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 {
# Write a error message to the log.
$MessageParams = @{

View File

@ -20,6 +20,8 @@ function Disconnect-From {
- NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer.
- VMware Terminates the connection from a VMware vCenter or ESXi host.
- 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
Force the disconnect, even if the disconnect would fail.
@ -47,12 +49,16 @@ function Disconnect-From {
.EXAMPLE
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
```
File Name : Disconnect-From.ps1
Author : Marco Blessing - marco.blessing@googlemail.com
Requires :
```
.LINK
https://github.com/OCram85/PSCredentialStore
@ -64,14 +70,14 @@ function Disconnect-From {
[string]$RemoteHost,
[Parameter(Mandatory = $true)]
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware", "CisServer")]
[ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')]
[string]$Type,
[Parameter(Mandatory = $false)]
[switch]$Force
)
switch ($Type) {
switch -Regex ($Type) {
"VMware" {
try {
if ($Force) {
@ -134,6 +140,7 @@ function Disconnect-From {
Write-Verbose @MessageParams
$Global:CurrentNcController = $null
}
catch {
# Write a error message to the log.
$MessageParams = @{
@ -158,6 +165,19 @@ function Disconnect-From {
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 {
# Write a error message to the log.
$MessageParams = @{