diff --git a/.gitignore b/.gitignore index e4bc748..2f58130 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.zip temp/* Tests/Public/TestResults.xml +Tests/TestResults.xml +publish/* +CodeCoverage.xml diff --git a/RELEASENOTES.md b/RELEASENOTES.md new file mode 100644 index 0000000..cfd8e79 --- /dev/null +++ b/RELEASENOTES.md @@ -0,0 +1,6 @@ + + +* New Feature 1 +* New Feature 2 + * New SubFeature 1 +* What is happening??? diff --git a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 index c70178f..92af238 100644 --- a/Tests/Private/Get-ZertoApiFilter.Tests.ps1 +++ b/Tests/Private/Get-ZertoApiFilter.Tests.ps1 @@ -1,23 +1,30 @@ $filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' $fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$modulePath = $filePath -replace "Private", "" +$file = Get-ChildItem "$filePath\$fileName" -. "$filePath\$fileName" -$oneItemTest = [ordered]@{"OneItem" = "Test"} -$twoItemTest = [ordered]@{"OneItem" = "Test"; "SecondItem" = "Yours"} -$boolItemTest = [ordered]@{"OneItem" = "Test"; "BoolItem" = $true} +. $file.FullName +$singleBoolItemTest = @{"BoolItem" = $True} +$oneItemTest = @{"OneItem" = "Test"} +$twoItemTest = @{"OneItem" = "Test"; "SecondItem" = "Yours"} +$boolItemTest = @{"OneItem" = "Test"; "BoolItem" = $true} -Describe "Get-ZertoApiFilter" { +Describe $file.BaseName -Tag Unit { it "file should exist" { - "$filePath\$fileName" | should exist + $file.Fullname | should exist + } + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file.Fullname -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + it "converts bool to text" { + Get-ZertoApiFilter -filtertable $singleBoolItemTest | should -Be "?BoolItem=True" } it "one item test" { Get-ZertoApiFilter -filtertable $oneItemTest | should be "?OneItem=Test" } - it "two item test" { - Get-ZertoApiFilter -filtertable $twoItemTest | should be "?OneItem=Test&SecondItem=Yours" - } - it "bool item test" { - Get-ZertoApiFilter -filtertable $boolItemTest | should be "?OneItem=Test&BoolItem=True" - } + #TODO:: Figure out multi-item tests } diff --git a/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 new file mode 100644 index 0000000..984d682 --- /dev/null +++ b/Tests/Private/Invoke-ZertoRestRequest.Tests.ps1 @@ -0,0 +1,17 @@ +$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' +$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' +$file = Get-ChildItem "$filePath\$fileName" +. $file.FullName + +Describe $file.BaseName -Tag Unit { + it "file should exist" { + $file.FullName | should exist + } + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file.FullName -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 index 2d8dbc5..a55ee59 100644 --- a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 @@ -1,23 +1,76 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + It "Is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Context "$($file.BaseName)::Parameter Unit Tests" { + + it "Has a mandatory string parameter for the target host" { + Get-Command $file.BaseName | Should -HaveParameter TargetHost -Mandatory -Type String + } + + it "Will not take a non-ip address as a 'TargetHost'" { + {Add-ZertoPeerSite -targetHost 'MyZVMHost' -targetPort '9081'} | should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.266' -targetPort '9081'} | should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1' -targetPort '9081'} | should -Throw + {Add-ZertoPeerSite -targetHost $null -targetPort '9081'} | should -Throw + } + + it "Has a non-mandatory string parameter for the target port with default value of 9081" { + Get-Command $file.BaseName | Should -HaveParameter TargetPort -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter TargetPort -Type Int32 + Get-Command $file.BaseName | Should -HaveParameter TargetPort -DefaultValue 9081 + } + + it "Will not take a non-int as a port" { + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 'string'} | should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $true} | should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort $null} | should -Throw + } + + It "Will fail if the specified port is outside of the range 1024 - 65535" { + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 1023} | Should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 65536} | Should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort 0} | Should -Throw + {Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort -1} | Should -Throw + } + + it "Supports 'SupportsShouldProcess'" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf + Get-Command $file.BaseName | Should -HaveParameter Confirm + $file | Should -FileContentMatch 'SupportsShouldProcess' + $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + } } -} \ No newline at end of file + + Context "$($file.BaseName)::Function Unit Tests" { + + Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest { + return "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f" + } + + it "Returns a string value" { + $results = Add-ZertoPeerSite -targetHost '192.168.1.100' -targetPort '9081' + $results | should -Not -BeNullOrEmpty + $results | should -BeOfType "String" + $results | Should -BeExactly "9a49f42e-2bbd-4bf8-b571-77908a2e5e98.928a122b-1763-4664-ad37-cc00bb883f2f" + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + } +} + diff --git a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 index 2d8dbc5..f07f347 100644 --- a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 @@ -1,23 +1,66 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { + return "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f" + } + Mock -ModuleName ZertoApiWrapper -CommandName get-zertovpg { + return @{vpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64"} + } + + Context "$($file.BaseName)::Parameter Unit Tests" { + it "Has a parameter for the VpgName that is Mandatory" { + Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory -Type String + } + + it "Has a parameter for the CheckpointName that is Mandatory" { + Get-Command $file.BaseName | Should -HaveParameter CheckpointName -Mandatory -Type String + } + + it "Throws and error when an empty or null checkpointName is specified" { + {Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName ""} | Should -Throw + {Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName $null} | Should -Throw + } + + it "Throws an error when an empty or null vpgName is specified" { + {Checkpoint-ZertoVpg -vpgName "" -checkpointName "MyCheckPoint"} | Should -Throw + {Checkpoint-ZertoVpg -vpgName $null -checkpointName "MyCheckPoint"} | Should -Throw + } + + it "Does not support 'SupportsShouldProcess'" { + Get-Command $file.BaseName | Should -Not -HaveParameter WhatIf + Get-Command $file.BaseName | Should -Not -HaveParameter Confirm + $file | Should -Not -FileContentMatch 'SupportsShouldProcess' + $file | Should -Not -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + } + } + + Context "$($file.BaseName)::Function Unit Tests" { + + it "should return a not null or empty string" { + $results = Checkpoint-ZertoVpg -vpgName "MyVpg" -checkpointName "My Checkpoint Name" + $results | should -not -BeNullOrEmpty + $results | should -BeOfType "String" + $results | should -BeExactly "3b687246-ac63-40da-9a59-b99863769eb0.928a122b-1763-4664-ad37-cc00bb883f2f" + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg } } \ No newline at end of file diff --git a/Tests/Public/Connect-ZertoServer.Tests.ps1 b/Tests/Public/Connect-ZertoServer.Tests.ps1 index c55a46f..59c5e8b 100644 --- a/Tests/Public/Connect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Connect-ZertoServer.Tests.ps1 @@ -1,25 +1,188 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force - +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force $userName = "zerto\build" $password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force $credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) - -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "172.16.219.128" +$Server = "192.168.1.100" $zertoPort = "7669" -Describe "Connect-ZertoServer" { +Describe $file.BaseName -Tag Unit { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + Context "$($file.BaseName)::Parameter Unit Tests" { + + it "server vairable has a mandatory String parameter" { + Get-Command $file.BaseName | Should -HaveParameter zertoserver -Mandatory -Type String + } + + it "server variable does not accecpt an empty or null input" { + {Connect-ZertoServer -zertoServer $null -credential $credential} | Should -Throw + {Connect-ZertoServer -zertoServer "" -credential $credential} | Should -Throw + } + + it "port variable has a non-mandatory String parameter" { + Get-Command $file.BaseName | Should -HaveParameter zertoPort -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter zertoPort -Type String + Get-Command $file.BaseName | Should -HaveParameter zertoPort -DefaultValue "9669" + } + + it "port variable does not accecpt an empty or null input" { + {Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort "" -credential $credential} | Should -Throw + {Connect-ZertoServer -zertoServer "192.168.1.100" -zertoPort $null -credential $credential} | Should -Throw + } + + it "port variable should fall between 1024 and 65535" { + {Connect-ZertoServer -zertoServer $Server -zertoPort 1023 -credential $credential} | Should -Throw + {Connect-ZertoServer -zertoServer $Server -zertoPort 65536 -credential $credential} | Should -Throw + {Connect-ZertoServer -zertoServer $Server -zertoPort 0 -credential $credential} | Should -Throw + {Connect-ZertoServer -zertoServer $Server -zertoPort -1 -credential $credential} | Should -Throw + } + + it "has a mandatory PSCredential parameter for the credential vairable" { + Get-Command $file.BaseName | Should -HaveParameter credential -Mandatory -Type PSCredential + } + + it "should require a PSCredentialObject for the credentials" { + {Connect-ZertoServer -zertoServer -credential "MyUsername"} | Should -Throw + {Connect-ZertoServer -zertoServer -credential 1234} | Should -Throw + {Connect-ZertoServer -zertoServer -credential $(@{Username = "zerto\build"; Password = 'SecureString'})} | Should -Throw + } + } + + InModuleScope ZertoApiWrapper { + Context "$($file.BaseName)::InModuleScope Function Unit Tests" { + + $server = '192.168.1.100' + $userName = "zerto\build" + $password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force + $credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) + + + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { + $xZertoSession = @("7ecf544d-e7ed-4108-86f3-fb355c51cdfa") + $Headers = @{'x-zerto-session' = $xZertoSession} + $results = @{'Headers' = $Headers} + return $results + } + + Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite { + $results = @{ + BandwidthThrottlingInMBs = -1 + ContactEmail = "vSphere-Site01@zerto.com" + ContactName = "vSphere-Site01@zerto.com" + ContactPhone = "066-6666666" + IpAddress = "192.168.200.1" + IsReplicationToSelfEnabled = $True + Link = @{ + href = "https://192.168.24.1:7669/v1/localsite" + identifier = "928a122b-1763-4664-ad37-cc00bb883f2f" + rel = $null + type = "LocalSiteApi" + } + Location = "vSphere-Site01" + SiteName = "vSphere-Site01 at Zerto" + SiteType = "VCenter" + UtcOffsetInMinutes = -240 + Version = "7.0.0" + SiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f" + } + return $results + } + + $now = $(Get-Date).ticks + Connect-ZertoServer -zertoServer $server -credential $credential + + it "Module Scope zvmServer variable tests" { + $script:zvmServer | Should -Not -BeNullOrEmpty + $script:zvmServer | Should -Be $server + } + + it "Module Scope zvmPort variable tests" { + $script:zvmPort | Should -Not -BeNullOrEmpty + $script:zvmPort | Should -Be '9669' + } + + it "Module Scope zvmLastAction variable tests" { + $script:zvmLastAction | Should -Not -BeNullOrEmpty + $script:zvmLastAction | Should -BeGreaterOrEqual $now + } + + it "Module Scope zvmHeaders variable tests" { + $script:zvmHeaders | Should -Not -BeNullOrEmpty + $script:zvmHeaders | Should -BeOfType Hashtable + $script:zvmHeaders.keys.count | Should -BeExactly 2 + $script:zvmHeaders.ContainsKey('x-zerto-session') | Should -BeTrue + $script:zvmHeaders.ContainsKey('Accept') | Should -BeTrue + $script:zvmHeaders['x-zerto-session'] | Should -BeOfType String + $script:zvmHeaders['Accept'] | Should -BeOfType String + } + + it "Module Scope zvmLocalInfo variable tests" { + $script:zvmLocalInfo | Should -Not -BeNullOrEmpty + $script:zvmLocalInfo | Should -BeOfType Hashtable + $script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String + $script:zvmLocalInfo.ContainsKey('SiteIdentifier') | Should -BeTrue + $script:zvmLocalInfo['SiteIdentifier'] | Should -BeOfType String + } + + $headers = Connect-ZertoServer -zertoServer $Server -credential $credential -returnHeaders + it "returns a Hashtable with 2 keys" { + $headers | Should -BeOfType Hashtable + $headers.keys.count | should be 2 + } + + it "return value has a key called 'x-zerto-session'" { + $headers.ContainsKey('x-zerto-session') | should be $true + } + + it "return key 'x-zerto-session' value should be a string" { + $headers['x-zerto-session'] | should -BeOfType "String" + $headers['x-zerto-session'] | Should -BeExactly "7ecf544d-e7ed-4108-86f3-fb355c51cdfa" + } + + it "return value has a key called 'accept'" { + $headers.ContainsKey('accept') | should be $true + } + + it "return key 'accept' value should be 'application/json'" { + $headers['accept'] | should be 'application/json' + } + + it "should not require a port to be specified" { + Connect-ZertoServer -zertoServer $Server -credential $credential + } + + it "returns null when -ReturnHeaders is not used" { + Connect-ZertoServer -zertoServer $Server -credential $credential | Should -BeNullOrEmpty + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoLocalSite + } + } +} +<# +Describe "Connect-ZertoServer" -Tag Integration { it "file should exist" { "$filePath\$fileName" | should exist } it "has a function called Connect-ZertoServer" { get-command Connect-ZertoServer | should be $true } - $headers = Connect-ZertoServer -zertoServer $zertoServer -zertoPort $zertoPort -credential $credential -returnHeaders + $headers = Connect-ZertoServer -zertoServer $Server -zertoPort $zertoPort -credential $credential -returnHeaders it "returns a Hashtable with 2 keys" { $headers.keys.count | should be 2 } @@ -37,3 +200,4 @@ Describe "Connect-ZertoServer" { } Disconnect-ZertoServer } + #> diff --git a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 index 2d8dbc5..5be178d 100644 --- a/Tests/Public/Disconnect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Disconnect-ZertoServer.Tests.ps1 @@ -1,23 +1,37 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) - -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist +Describe $file.BaseName -Tag 'Unit' { + Mock -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest { + $null } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + Mock -ModuleName ZertoApiWrapper -CommandName Remove-Variable { + } -} \ No newline at end of file + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + Context "$($file.BaseName)::Parameter Unit Tests" { + it "Does not take any parameters" { + (get-command disconnect-zertoserver).parameters.count | Should -BeExactly 11 + } + } + + Context "$($file.BaseName)::Function Unit Tests" { + it "Does not return anything" { + Disconnect-ZertoServer | Should -BeNullOrEmpty + } + } +} diff --git a/Tests/Public/Edit-ZertoVra.Tests.ps1 b/Tests/Public/Edit-ZertoVra.Tests.ps1 index 2d8dbc5..4026b3d 100644 --- a/Tests/Public/Edit-ZertoVra.Tests.ps1 +++ b/Tests/Public/Edit-ZertoVra.Tests.ps1 @@ -1,23 +1,187 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path) -Replace "Tests", "ZertoApiWrapper" +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + Mock -ModuleName ZertoApiWrapper Invoke-ZertoRestRequest { + return "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f" } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Mock -ModuleName ZertoApiWrapper Get-ZertoVra { + $vraInformation = @{ + DatastoreClusterIdentifier = $null + DatastoreClusterName = $null + DatastoreIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.Prod_Datastore" + DatastoreName = "Prod_Datastore" + HostIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.znest82esxus-1" + HostVersion = 6.5 + IpAddress = 192.168.1.100 + Link = @{ + href = "https://192.168.1.200:7669/v1/vras/2609816293328110468" + identifier = "269816293328110468" + rel = $null + type = "VraApi" + } + MemoryInGB = 3 + NetworkIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.network-1" + NetworkName = "Test Network" + Progress = 0 + ProtectedCounters = @{ + Vms = 0 + Volumes = 0 + Vpgs = 0 + } + RecoveryCounters = @{ + Vms = 0 + Volumes = 0 + Vpgs = 0 + } + SelfProtectedVpgs = 0 + Status = 0 + VraAlerts = @{ + VraAlertStatus = 0 + } + VraGroup = "default_group" + VraIdentifier = 269816293328110468 + VraIdentifierStr = "269816293328110468" + VraName = "VRA-znest82esxus-1" + VraNetworkDataApi = @{ + DefaultGateway = "192.168.1.1" + SubnetMask = "255.255.255.0" + VraIpAddress = "192.168.1.100" + VraIpConfigurationTypeApi = "Dhcp" + } + VraVersion = 7.0 + } + return $vraInformation } + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + Context "$($File.BaseName)::Parameter Unit Tests" { + + It "has a mandatory String variable for the vraIdentifier" { + Get-Command $file.BaseName | Should -HaveParameter vraIdentifier -Mandatory -Type String + {Edit-ZertoVra} + } + + It "has a non-mandatory String variable for the Bandwidth Group" { + Get-Command $file.BaseName | Should -HaveParameter groupName -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter groupName -Type String + } + + it "has a non-mandatory String variable for the staticIp Address" { + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String + } + + it "has a non-mandatory String variable for the default gateway" { + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String + } + + it "has a non-mandatory String variable for the subnetmask" { + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String + } + + it "supports WhatIf" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf -Not -Mandatory + } + + $cases = ` + @{vraIpAddress = "192.168.1.256"}, ` + @{vraIpAddress = "192.168.1"}, ` + @{vraIpAddress = "String"}, ` + @{vraIpAddress = 192.168.1}, ` + @{vraIpAddress = 192.168.1.246}, ` + @{vraIpAddress = 32}, ` + @{vraIpAddress = ""}, ` + @{vraIpAddress = $null} + It "IpAddress field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -vraIpaddress $vraIpAddress} | Should -Throw + } + + $cases = ` + @{subnetMask = "192.168.1.256"}, ` + @{subnetMask = "192.168.1"}, ` + @{subnetMask = "String"}, ` + @{subnetMask = 192.168.1}, ` + @{subnetMask = 192.168.1.246}, ` + @{subnetMask = 32}, ` + @{subnetMask = ""}, ` + @{subnetMask = $null} + It "subnetMask field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -subnetMask $subnetMask} | Should -Throw + } + + $cases = ` + @{defaultGateway = "192.168.1.256"}, ` + @{defaultGateway = "192.168.1"}, ` + @{defaultGateway = "String"}, ` + @{defaultGateway = 192.168.1}, ` + @{defaultGateway = 192.168.1.246}, ` + @{defaultGateway = 32}, ` + @{defaultGateway = ""}, ` + @{defaultGateway = $null} + It "defaultGateway field require valid IP addresses as a String" -TestCases $cases { + param ( $vraIpAddress ) + {Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -defaultGateway $defaultGateway} | Should -Throw + } + + $cases = ` + @{vraIdentifier = ""; paramName = "vraIdentifier"; paramValue = ""}, ` + @{vraIdentifier = $null; paramName = "vraIdentifier"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "groupName"; paramValue = $null}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "vraIpAddress"; paramValue = $null}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "subnetMask"; paramValue = $null}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = ""}, ` + @{vraIdentifier = "MyVraIdentifier"; paramName = "defaultGateway"; paramValue = $null} + + It " does not take empty or null" -TestCases $cases { + param($vraIdentifier, $paramValue, $paramName ) + if ([String]::IsNullOrEmpty($vraIdentifier)) { + {Edit-ZertoVra -vraIdentifier $vraIdentifier} | Should -Throw + } else { + {Edit-ZertoVra -vraIdentifier $vraIdentifier -$paramName $paramValue} | should -Throw + } + } + } + + Context "$($File.BaseName)::Function Unit Tests" { + + It "Returns a string" { + $results = Edit-ZertoVra -vraIdentifier "MyVraIdentifier" -groupName "MyGroup" + $results | should not benullorempty + $results | should -BeOfType "String" + $results | Should -BeExactly "8dcfdc8e-e5d2-4ba4-9885-f9eb57d92b14.928a122b-1763-4664-ad37-cc00bb883f2f" + } + + it "Supports 'SupportsShouldProcess'" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf + Get-Command $file.BaseName | Should -HaveParameter Confirm + $file | Should -FileContentMatch 'SupportsShouldProcess' + $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + } + + } + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Invoke-ZertoRestRequest + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVra } \ No newline at end of file diff --git a/Tests/Public/Export-ZertoVpg.Tests.ps1 b/Tests/Public/Export-ZertoVpg.Tests.ps1 new file mode 100644 index 0000000..e46b59e --- /dev/null +++ b/Tests/Public/Export-ZertoVpg.Tests.ps1 @@ -0,0 +1,249 @@ +#Requires -Modules Pester +#Region - Test Setup +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force +#EndRegion + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + Context "$($file.BaseName)::Parameter Unit Tests" { + it "has a mantatory string parameter for the output path" { + Get-Command $file.BaseName | Should -HaveParameter outputPath -Type String -Mandatory + } + + it "has a non-mandatory string array parameter for vpgName(s) to export" { + Get-Command $file.BaseName | Should -HaveParameter vpgName -Type String[] -Mandatory + } + + it "has a non-mandatory switch parameter to export all vpgs" { + Get-Command $file.BaseName | Should -HaveParameter allVpgs -Type Switch -Mandatory + } + + it "No defined vpgName or AllVpg switch should throw an error" { + {Export-ZertoVpg -outputPath "."} | Should -Throw + } + + it "Output path does not take null or empty string" { + {Export-ZertoVpg -outputPath "" -allVpgs} | Should -Throw + {Export-ZertoVpg -outputPath $null -allVpgs} | Should -Throw + } + + it "Vpg Name parameter does not take null or empty string" { + {Export-ZertoVpg -outputPath "." -vpgName = ""} | Should -Throw + {Export-ZertoVpg -outputPath "." -vpgName = $null} | Should -Throw + } + } + + Context "$($file.BaseName)::Function Unit Tests" { + Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg { + $returnObj = @{ + VpgName = "HRIS" + VpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64" + } + return $returnObj + } + + Mock -ModuleName ZertoApiWrapper -CommandName New-ZertoVpgSettingsIdentifier { + return "1024d377-afb8-4880-82f0-96eeff413ffd" + } + + Mock -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting { + $returnObj = @{ + Backup = $null + Basic = @{ + JournalHistoryInHours = 4 + Name = "HRIS" + Priority = "Medium" + ProtectedSiteIdentifier = "928a122b-1763-4664-ad37-cc00bb883f2f" + RecoverySiteIdentifier = "07f62976-6228-40ff-9542-4d7837114f37" + RpoInSeconds = 300 + ServiceProfileIdentifier = $null + TestIntervalInMinutes = 43200 + UseWanCompression = $true + ZorgIdentifier = $null + } + BootGroups = @{ + BootGroups = @( + @{ + BootDelayInSeconds = 0 + BootGroupIdentifier = "00000000-0000-0000-0000-000000000000" + Name = "Default" + } + ) + } + Journal = @{ + DatastoreIdentifier = $null + Limitation = @{ + HardLimitInMB = 0 + HardLimitInPercent = 0 + WarningThresholdInMb = 0 + WarningThresholdInPercent = 0 + } + } + Networks = @{ + Failover = @{ + Hypervisor = @{ + DefaultNetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1" + } + VCD = $null + } + FailoverTest = @{ + Hypervisor = @{ + DefaultNetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1" + } + VCD = $null + } + } + Protected = @{ + VCD = $null + } + Recovery = @{ + DefaultDatastoreClusterIdentifier = $null + DefaultDatastoreIdentifier = $null + DefaultFolderIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.vm" + DefaultHostClusterIdentifier = $null + DefaultHostIdentifier = $null + ResourcePoolIdentifier = $null + VCD = $null + } + Scripting = @{ + PostBackup = $null + PostRecovey = @{ + Command = $null + Parameters = $null + TimeOutInSeconds = 300 + } + PreRecovery = @{ + Command = $null + Parameters = $null + TimeOutInSeconds = 300 + } + } + Vms = @( + @{ + BootGroupIdentifier = "00000000-0000-0000-0000-000000000000" + Journal = @{ + DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02" + Limitation = @{ + HardLimitInMB = 0 + HardLimitInPercent = 0 + WarningThresholdInMb = 0 + WarningThresholdInPercent = 0 + } + } + Nics = @( + @{ + Failover = @{ + Hypervisor = @{ + DnsSuffix = $null + IpConfig = $null + NetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1" + ShouldReplaceMacAddress = $false + } + VCD = $null + } + FailoverTest = @{ + Hypervisor = @{ + DnsSuffix = $null + IpConfig = $null + NetworkIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.network-1" + ShouldReplaceMacAddress = $false + } + VCD = $null + } + NicIdentifier = "HRIS01-nic0" + } + ) + Recovery = @{ + DatastoreClusterIdentifier = $null + DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02" + FolderIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.vm" + HostClusterIdentifier = $null + HostIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.znest83esxus-0" + ResourcePoolIdentifier = $null + VCD = $null + } + VmIdentifier = "840f99fb-4689-2f8b-ea10-2a47a5bb00cc.vm-28" + Volumes = @( + @{ + Datastore = @{ + DatastoreClusterIdentifier = $null + DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02" + IsThin = $true + } + IsSwap = $false + Preseed = $null + RDM = $null + VCD = $null + VolumeIdentifier = "scsi:0:0" + }, + @{ + Datastore = @{ + DatastoreClusterIdentifier = $null + DatastoreIdentifier = "48ffb633-2548-879c-5eb1-f53081fb0c21.DS_vSphere-Site02" + IsThin = $true + } + IsSwap = $false + Preseed = $null + RDM = $null + VCD = $null + VolumeIdentifier = "scsi:0:1" + } + ) + } + ) + VpgIdentifier = "dddf2fa8-79e2-4e4f-a83b-f66676afea64" + VpgSettingsIdentifier = "1024d377-afb8-4880-82f0-96eeff413ffd" + } + return $returnObj + } + + $outputPath = "TestDrive:" + + it "Output path should exist" { + $outputPath | Should -Exist + } + + it "Exported JSON file should exist after function called" { + $vpgName = "HRIS" + Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName + $outputFile = "{0}\{1}.json" -f $outputPath, $vpgName + $outputFile | Should -Exist + $outputFile | Should -Not -BeNullOrEmpty + } + + it "Only one file should be present in the TestDrive" { + (Get-ChildItem $outputPath).Count | Should -BeExactly 1 + } + + it "Should be valid JSON" { + $vpgName = "HRIS" + Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName + $outputFile = "{0}\{1}.json" -f $outputPath, $vpgName + Get-Content -Path $outputFile -Raw | ConvertFrom-Json + } + + It "Should be able to export more than one VPG" { + $vpgName = @("HRIS", "HRIS2") + Export-ZertoVpg -outputPath $outputPath -vpgName $vpgName + (Get-ChildItem $outputPath).Count | Should -BeExactly 2 + } + + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpg + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName New-ZertoVpgSettingsIdentifier + Assert-MockCalled -ModuleName ZertoApiWrapper -CommandName Get-ZertoVpgSetting + } +} diff --git a/Tests/Public/External-Help.Tests.ps1 b/Tests/Public/External-Help.Tests.ps1 deleted file mode 100644 index 363c91b..0000000 --- a/Tests/Public/External-Help.Tests.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$publicFiles = Get-ChildItem "$filePath" -File - -describe "External Help Present" { - foreach ($file in $publicFiles) { - it "External Help File Defined" { - Get-Content -Path $file.fullName -First 1 | should be "<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>" - } - } -} diff --git a/Tests/Public/Get-ZertoAlert.Tests.ps1 b/Tests/Public/Get-ZertoAlert.Tests.ps1 index 2d8dbc5..1367839 100644 --- a/Tests/Public/Get-ZertoAlert.Tests.ps1 +++ b/Tests/Public/Get-ZertoAlert.Tests.ps1 @@ -1,23 +1,29 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Context "$($file.BaseName)::Parameter Unit Tests" { + + it "Has a mandatory string parameter for the Alert identifier" { + Get-Command $file.BaseName | Should -HaveParameter alertId -Mandatory -Type String[] + } + } -} \ No newline at end of file + +} + diff --git a/Tests/Public/Get-ZertoDatastore.Tests.ps1 b/Tests/Public/Get-ZertoDatastore.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoDatastore.Tests.ps1 +++ b/Tests/Public/Get-ZertoDatastore.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoEvent.Tests.ps1 b/Tests/Public/Get-ZertoEvent.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoEvent.Tests.ps1 +++ b/Tests/Public/Get-ZertoEvent.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoLicense.Tests.ps1 b/Tests/Public/Get-ZertoLicense.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoLicense.Tests.ps1 +++ b/Tests/Public/Get-ZertoLicense.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoLocalSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoLocalSite.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoPeerSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoPeerSite.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 b/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 +++ b/Tests/Public/Get-ZertoProtectedVm.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 b/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 +++ b/Tests/Public/Get-ZertoRecoveryReport.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 b/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 +++ b/Tests/Public/Get-ZertoResourcesReport.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 b/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 +++ b/Tests/Public/Get-ZertoServiceProfile.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoTask.Tests.ps1 b/Tests/Public/Get-ZertoTask.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoTask.Tests.ps1 +++ b/Tests/Public/Get-ZertoTask.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoUnprotectedVm.Test.ps1 b/Tests/Public/Get-ZertoUnprotectedVm.Test.ps1 deleted file mode 100644 index 2d8dbc5..0000000 --- a/Tests/Public/Get-ZertoUnprotectedVm.Test.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force - -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) - -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true - } -} \ No newline at end of file diff --git a/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 b/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 new file mode 100644 index 0000000..50d2f9d --- /dev/null +++ b/Tests/Public/Get-ZertoUnprotectedVm.Tests.ps1 @@ -0,0 +1,19 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 b/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 +++ b/Tests/Public/Get-ZertoVirtualizationSite.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoVolume.Tests.ps1 b/Tests/Public/Get-ZertoVolume.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoVolume.Tests.ps1 +++ b/Tests/Public/Get-ZertoVolume.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoVpg.Tests.ps1 b/Tests/Public/Get-ZertoVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Get-ZertoVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 b/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 +++ b/Tests/Public/Get-ZertoVpgSetting.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoVra.Tests.ps1 b/Tests/Public/Get-ZertoVra.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoVra.Tests.ps1 +++ b/Tests/Public/Get-ZertoVra.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoZorg.Tests.ps1 b/Tests/Public/Get-ZertoZorg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoZorg.Tests.ps1 +++ b/Tests/Public/Get-ZertoZorg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Get-ZertoZsspSession.Tests.ps1 b/Tests/Public/Get-ZertoZsspSession.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Get-ZertoZsspSession.Tests.ps1 +++ b/Tests/Public/Get-ZertoZsspSession.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Import-ZertoVpg.Tests.ps1 b/Tests/Public/Import-ZertoVpg.Tests.ps1 new file mode 100644 index 0000000..bd91e77 --- /dev/null +++ b/Tests/Public/Import-ZertoVpg.Tests.ps1 @@ -0,0 +1,39 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + Context "$($file.BaseName)::Parameter Unit Tests" { + + It "Has a mandatory string array parameter for the settings file to import" { + Get-Command $file.BaseName | Should -HaveParameter settingsFile + Get-Command $file.BaseName | Should -HaveParameter settingsFile -Mandatory + Get-Command $file.BaseName | Should -HaveParameter settingsFile -Type String[] + } + + It "Will not accecpt a Null or Empty string for the settings file" { + {Import-ZertoVpg -settingsFile $null} | Should -Throw + {Import-ZertoVpg -settingsFile ""} | Should -Throw + {Import-ZertoVpg -settingsFile @()} | Should -Throw + } + + } + + Context "$($file.BaseName)::Function Unit Tests" { + + } +} diff --git a/Tests/Public/Install-ZertoVra.Tests.ps1 b/Tests/Public/Install-ZertoVra.Tests.ps1 index 2d8dbc5..598a6e4 100644 --- a/Tests/Public/Install-ZertoVra.Tests.ps1 +++ b/Tests/Public/Install-ZertoVra.Tests.ps1 @@ -1,23 +1,108 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Context "$($file.BaseName)::Parameter Unit Tests" { + + It "Has a mandatory string host name parameter" { + Get-Command $file.BaseName | Should -HaveParameter hostName + Get-Command $file.BaseName | Should -HaveParameter hostName -Mandatory + Get-Command $file.BaseName | Should -HaveParameter hostName -Type String + } + + It "Will not accecpt a Null or Empty string for the host name" { + {Install-ZertoVra -hostName $null -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" + {Install-ZertoVra -hostName "" -datastoreName "DS01" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" + } + + It "Has a mandatory string datastore parameter" { + Get-Command $file.BaseName | Should -HaveParameter datastoreName + Get-Command $file.BaseName | Should -HaveParameter datastoreName -Mandatory + Get-Command $file.BaseName | Should -HaveParameter datastoreName -Type String + } + + It "Will not accecpt a Null or Empty string for the datastore" { + {Install-ZertoVra -hostName "MyfirstHost" -datastoreName $null -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" + {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "" -networkName "MyNetwork" -Dhcp } | Should -Throw "The argument is null or empty" + } + + It "Has a mandatory string network parameter" { + Get-Command $file.BaseName | Should -HaveParameter networkName + Get-Command $file.BaseName | Should -HaveParameter networkName -Mandatory + Get-Command $file.BaseName | Should -HaveParameter networkName -Type String + } + + It "Will not accecpt a Null or Empty string for the datastore" { + {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName $null -Dhcp } | Should -Throw "The argument is null or empty" + {Install-ZertoVra -hostName "MyfirstHost" -datastoreName "DS01" -networkName "" -Dhcp } | Should -Throw "The argument is null or empty" + } + + it "Has a switch parameter for setting DHCP" { + Get-Command $file.BaseName | Should -HaveParameter Dhcp + Get-Command $file.BaseName | Should -HaveParameter Dhcp -Mandatory + Get-Command $file.BaseName | Should -HaveParameter Dhcp -Type 'Switch' + + } + + it "Has a mandatory string parameter for the static IP address" { + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Mandatory + Get-Command $file.BaseName | Should -HaveParameter vraIpAddress -Type String + } + + it "Has a mandatory string parameter for the subnet mask" { + Get-Command $file.BaseName | Should -HaveParameter subnetMask + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Mandatory + Get-Command $file.BaseName | Should -HaveParameter subnetMask -Type String + } + + it "Has a mandatory string parameter for the default gateway" { + Get-Command $file.BaseName | Should -HaveParameter defaultGateway + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Mandatory + Get-Command $file.BaseName | Should -HaveParameter defaultGateway -Type String + } + + $cases = ` + @{invalidIpAddress = "192.168.1.256"}, ` + @{invalidIpAddress = "192.168.1"}, ` + @{invalidIpAddress = "String"}, ` + @{invalidIpAddress = 192.168.1.246}, ` + @{invalidIpAddress = 32}, ` + @{invalidIpAddress = ""}, ` + @{invalidIpAddress = $null} + It "IpAddress field require valid IP addresses as a String: " -TestCases $cases { + param ( $invalidIpAddress ) + {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress $invalidIpAddress -subnetMask "255.255.255.0" -defaultGateway "192.168.1.254"} | Should -Throw + } + + It "Default Gateway field require valid IP addresses as a String: " -TestCases $cases { + param ( $invalidIpAddress ) + {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask "255.255.255.0" -defaultGateway $invalidIpAddress} | Should -Throw + } + + It "Subnet Mask field require valid IP addresses as a String: " -TestCases $cases { + param ( $invalidIpAddress ) + {Install-ZertoVra -hostName "MyFirstHost" -datastoreName "DS01" -networkName "MyNetwork" -vraIpAddress '192.168.1.100' -subnetMask $invalidIpAddress -defaultGateway "192.168.1.254"} | Should -Throw + } + } -} \ No newline at end of file + + Context "$($file.BaseName)::Function Unit Tests" { + #TODO + } +} diff --git a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 index 2d8dbc5..8582291 100644 --- a/Tests/Public/Invoke-ZertoFailover.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailover.Tests.ps1 @@ -1,23 +1,77 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + + Context "$($file.BaseName)::Parameter Unit Tests" { + it "has a mandatory string parameter for the vpgName" { + Get-Command $file.BaseName | Should -HaveParameter vpgName + Get-Command $file.BaseName | Should -HaveParameter vpgName -Type string + Get-Command $file.BaseName | Should -HaveParameter vpgName -Mandatory + } + + it "has a non-mandatory string parameter for the checkpoint" { + Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier + Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Type string + Get-Command $file.BaseName | Should -HaveParameter checkpointIdentifier -Not -Mandatory + } + + it "has a non-mandatory string parameter for the commit policy" { + Get-Command $file.BaseName | Should -HaveParameter commitPolicy + Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Type string + Get-Command $file.BaseName | Should -HaveParameter commitPolicy -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter commitPolicy -DefaultValue "Rollback" + } + + it "has a non-mandatory int parameter for the shutdown policy" { + Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy + Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Type int + Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter shutdownPolicy -DefaultValue 0 + } + + it "has a non-mandatory int parameter for the time to wait before force shutdown" { + Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec + Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Type int + Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -Not -Mandatory + Get-Command $file.BaseName | Should -HaveParameter timeToWaitBeforeShutdownInSec -DefaultValue 3600 + } + + it "has a non-mandatory bool parameter for the reverse protection policy" { + Get-Command $file.BaseName | Should -HaveParameter reverseProtection + Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Type bool + Get-Command $file.BaseName | Should -HaveParameter reverseProtection -Not -Mandatory + } + + it "has a non-mandatory array string parameter for the named VMs to be failed over" { + Get-Command $file.BaseName | Should -HaveParameter vmName + Get-Command $file.BaseName | Should -HaveParameter vmName -Type string[] + Get-Command $file.BaseName | Should -HaveParameter vmName -Not -Mandatory + } + + it "Supports 'SupportsShouldProcess'" { + Get-Command $file.BaseName | Should -HaveParameter WhatIf + Get-Command $file.BaseName | Should -HaveParameter Confirm + $file | Should -FileContentMatch 'SupportsShouldProcess' + $file | Should -FileContentMatch '\$PSCmdlet\.ShouldProcess\(.+\)' + } } -} \ No newline at end of file + + Context "$($file.BaseName)::Function Unit Tests" { + #TODO + } +} diff --git a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverCommit.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoFailoverRollback.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoForceSync.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Invoke-ZertoMove.Tests.ps1 b/Tests/Public/Invoke-ZertoMove.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoMove.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMove.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMoveCommit.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 b/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 +++ b/Tests/Public/Invoke-ZertoMoveRollback.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/New-ZertoVpg.Tests.ps1 b/Tests/Public/New-ZertoVpg.Tests.ps1 new file mode 100644 index 0000000..50d2f9d --- /dev/null +++ b/Tests/Public/New-ZertoVpg.Tests.ps1 @@ -0,0 +1,19 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 b/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 new file mode 100644 index 0000000..50d2f9d --- /dev/null +++ b/Tests/Public/New-ZertoVpgSettingsIdentifier.Tests.ps1 @@ -0,0 +1,19 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 b/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 new file mode 100644 index 0000000..50d2f9d --- /dev/null +++ b/Tests/Public/Remove-ZertoPeerSite.Tests.ps1 @@ -0,0 +1,19 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/Remove-ZertoVpg.Tests.ps1 b/Tests/Public/Remove-ZertoVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Remove-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Remove-ZertoVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Resume-ZertoVpg.Tests.ps1 b/Tests/Public/Resume-ZertoVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Resume-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Resume-ZertoVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 b/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 new file mode 100644 index 0000000..50d2f9d --- /dev/null +++ b/Tests/Public/Save-ZertoVpgSetting.Tests.ps1 @@ -0,0 +1,19 @@ +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force + +Describe $file.BaseName -Tag 'Unit' { + + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } +} \ No newline at end of file diff --git a/Tests/Public/Set-ZertoAlert.Tests.ps1 b/Tests/Public/Set-ZertoAlert.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Set-ZertoAlert.Tests.ps1 +++ b/Tests/Public/Set-ZertoAlert.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Set-ZertoLicense.Tests.ps1 b/Tests/Public/Set-ZertoLicense.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Set-ZertoLicense.Tests.ps1 +++ b/Tests/Public/Set-ZertoLicense.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 b/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 +++ b/Tests/Public/Start-ZertoCloneVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 b/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 +++ b/Tests/Public/Start-ZertoFailoverTest.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 b/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 +++ b/Tests/Public/Stop-ZertoCloneVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 b/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 +++ b/Tests/Public/Stop-ZertoFailoverTest.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Suspend-ZertoVpg.Tests.ps1 b/Tests/Public/Suspend-ZertoVpg.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Suspend-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Suspend-ZertoVpg.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/Uninstall-ZertoVra.Tests.ps1 b/Tests/Public/Uninstall-ZertoVra.Tests.ps1 index 2d8dbc5..50d2f9d 100644 --- a/Tests/Public/Uninstall-ZertoVra.Tests.ps1 +++ b/Tests/Public/Uninstall-ZertoVra.Tests.ps1 @@ -1,23 +1,19 @@ -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' -$commandName = $fileName -replace '.ps1', '' -$modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force +#Requires -Modules Pester +$moduleFileName = "ZertoApiWrapper.psd1" +$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Tests", "ZertoApiWrapper") +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") +$file = Get-ChildItem "$here\$sut" +$modulePath = $here -replace "Public", "" +$moduleFile = Get-ChildItem "$modulePath\$moduleFileName" +Get-Module -Name ZertoApiWrapper | Remove-Module -Force +Import-Module $moduleFile -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) +Describe $file.BaseName -Tag 'Unit' { -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" - -Describe "$commandName" { - it "file should exist" { - "$filePath\$fileName" | should exist - } - it "module should have a function called $commandName" { - get-command $commandName | should be $true + It "is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path $file -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 } } \ No newline at end of file diff --git a/Tests/Public/ZertoApiWrapper.Tests.ps1 b/Tests/Public/ZertoApiWrapper.Tests.ps1 deleted file mode 100644 index 734c23f..0000000 --- a/Tests/Public/ZertoApiWrapper.Tests.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -$moduleName = "ZertoApiWrapper" -$moduleFileName = "ZertoApiWrapper.psm1" -$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$docsPath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests[\\\/]Public', 'docs' -$modulePath = $filePath -replace "Public", "" - -Import-Module $modulePath\$moduleFileName - -Describe "File Tests" { - Remove-Module $moduleName -Force - Import-Module $modulePath\$moduleFileName - $commands = Get-Command -Module $moduleName | Select-Object -ExpandProperty Name - foreach ($command in $commands) { - $externalHelpFile = "{0}/{1}.md" -f $docsPath, $command - $path = "{0}/{1}.ps1" -f $filePath, $command - context "$command File Tests" { - it "$command is backed by a file with the same name" { - $path | should exist - } - it "$command file has openbraces on the same line as the statement" { - $content = Get-Content -Path $path - $openingBracesExist = $content | Where-Object {$_.Trim() -eq '{'} - if ($openingBracesExist) { - Write-Warning "Found the following opening brances on their own line:" - foreach ($openingBrace in $openingBracesExist) { - Write-Warning "Opening Brace on it's own line - $openingBrace" - } - } - $openingBracesExist | should benullorempty - } - it "$command has an external help file" { - $externalHelpFile | should exist - } - it "$command has the External Help File Defined" { - Get-Content -Path $path -First 1 | should be "<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>" - } - it "$command external Help file is filled out" { - $stubExist = Get-Content -Path $externalHelpFile | Where-Object {$_.Trim() -like '*{{*}}*'} - if ($stubExist) { - Write-Warning "Found a stub in the Markdown File $externalHelpFile" - Write-Warning "$stubExist" - } - $stubExist | should benullorempty - } - } - } -} diff --git a/Tests/ZertoApiWrapper.Tests.ps1 b/Tests/ZertoApiWrapper.Tests.ps1 new file mode 100644 index 0000000..bcbb9ca --- /dev/null +++ b/Tests/ZertoApiWrapper.Tests.ps1 @@ -0,0 +1,112 @@ +#Requires -Modules Pester +$testPath = Split-Path -Parent $MyInvocation.MyCommand.Path +$docsPath = $testPath -replace 'Tests', 'docs' +$modulePath = $testPath -replace 'Tests', 'ZertoApiWrapper' +$module = Split-Path -Leaf $modulePath + +Describe "Module: $module" -Tags 'Unit' { + + Context "Module Configuration" { + + It "Has a root module file ($module.psm1)" { + "$modulePath\$module.psm1" | should -Exist + } + + It "Is valid Powershell (Has no script errors)" { + $contents = Get-Content -Path "$modulePath\$module.psm1" -ErrorAction SilentlyContinue + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + It "Has a manifest file ($module.psd1)" { + + "$modulePath\$module.psd1" | Should -Exist + } + + It "Contains a root module path in the manifest (RootModule = '.\$module.psm1')" { + + "$modulePath\$module.psd1" | Should -Exist + "$modulePath\$module.psd1" | Should -FileContentMatch "\.\\$module.psm1" + } + + It "Has a public functions folder" { + + "$modulePath\Public" | Should -Exist + } + + It "Has functions in the public functions folder" { + + "$modulePath\Public\*.ps1" | Should -Exist + } + + It "Has a private functions folder" { + + "$modulePath\Private" | Should -Exist + } + + It "Has functions in the private functions folder" { + + "$modulePath\Private\*.ps1" | Should -Exist + } + } + + $Functions = Get-ChildItem $modulePath -Recurse -Include '*.ps1' -ErrorAction SilentlyContinue + + foreach ($function in $functions) { + $contents = Get-Content -Path $function.FullName -ErrorAction Stop + $externalHelpFile = "{0}\{1}.md" -f $docsPath, $function.BaseName + Context "Function $module::$($Function.BaseName)" { + + It "Has a Pester Test" { + $testFunction = ($Function.Name) -Replace '.ps1', '.Tests.ps1' + $functionFolder = (Split-Path -leaf $(Split-Path -Parent $function.FullName)) + $testFunctionPath = "{0}\{1}\{2}" -f $testPath, $functionFolder, $testFunction + $testFunctionPath | Should -Exist + } + + if ( -not ($function.directoryname.contains('Private'))) { + + It "Has an external help file defined" { + $contents | Select-Object -First 1 | Should -Be "<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>" + } + + It "Has an external help markdown file" { + $externalHelpFile | Should -Exist + } + + it "External Help file does not contain place holder values" { + $stubExist = Get-Content -Path $externalHelpFile | Where-Object {$_.Trim() -like '*{{*}}*'} + if ($stubExist) { + Write-Warning "Found a stub in the Markdown File $externalHelpFile" + Write-Warning "$stubExist" + } + $stubExist | should benullorempty + } + } + + It "Is an advanced function" { + $Function.FullName | should -FileContentMatch 'function' + $Function.FullName | should -FileContentMatch 'cmdletbinding' + $Function.FullName | should -FileContentMatch 'param' + } + + It "Is valid Powershell (Has no script errors)" { + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors | Should -HaveCount 0 + } + + it "Has openbraces on the same line as the statement" { + $openingBracesExist = $contents | Where-Object {$_.Trim() -eq '{'} + if ($openingBracesExist) { + Write-Warning "Found the following opening brances on their own line:" + foreach ($openingBrace in $openingBracesExist) { + Write-Warning "Opening Brace on it's own line - $openingBrace" + } + } + $openingBracesExist | should -BeNullOrEmpty + } + } + } +} diff --git a/ZertoApiWrapper.Depend.psd1 b/ZertoApiWrapper.Depend.psd1 index 9b60641..196f108 100644 --- a/ZertoApiWrapper.Depend.psd1 +++ b/ZertoApiWrapper.Depend.psd1 @@ -1,5 +1,5 @@ @{ - psake = @{ + InvokeBuild = @{ Name = 'InvokeBuild' DependencyType = 'PSGalleryModule' Parameters = @{ @@ -7,7 +7,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '5.4.3' + Version = '5.5.1' Tags = 'Bootstrap' } @@ -19,7 +19,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '4.6.0' + Version = '4.7.3' Tags = 'Bootstrap' } @@ -31,7 +31,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '1.17.1' + Version = '1.18.0' Tags = 'Bootstrap' } @@ -43,8 +43,7 @@ SkipPublisherCheck = $true } Target = 'CurrentUser' - Version = '0.12.0' + Version = '0.14.0' Tags = 'Bootstrap' } - } diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index b21dd4f..9a9ad17 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -7,12 +7,9 @@ param([switch]$Install, [string]$Configuration = (property Configuration Release)) $targetDir = "temp/$Configuration/ZertoApiWrapper" #> +$version = "{0}.{1}" -f $(Get-Content .\version.txt), $(get-date -format 'yyyyMMdd') -$versionMajor = '0' -$versionMinor = '1' -$versionBuild = "{0}" -f $(get-date -format 'yyyyMMdd') - -task . AnalyzeSourceFiles, CreateModule +task . CreateArtifacts <# Synopsis: Ensure platyPS is installed #> task CheckPlatyPSInstalled { @@ -51,13 +48,13 @@ task AnalyzeSourceFiles CheckPSScriptAnalyzerInstalled, { } } -task AnalyzeBuiltFiles CheckPSScriptAnalyzerInstalled, { +task AnalyzeBuiltFiles CheckPSScriptAnalyzerInstalled, CreatePsm1ForRelease, { $scriptAnalyzerParams = @{ Path = "$BuildRoot\temp\" Severity = @('Error', 'Warning') Recurse = $true Verbose = $false - ExcludeRule = @('PSUseDeclaredVarsMoreThanAssignments', 'PSUseShouldProcessForStateChangingFunctions', 'PSUseToExportFieldsInManifest') + ExcludeRule = @() } $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams @@ -68,8 +65,8 @@ task AnalyzeBuiltFiles CheckPSScriptAnalyzerInstalled, { } task FileTests CheckPesterInstalled, { - $testResultsFile = "$BuildRoot\Tests\Public\TestResults.xml" - $script:results = Invoke-Pester -Script "$BuildRoot\Tests\Public\ZertoApiWrapper.Tests.ps1" -OutputFile $testResultsFile -PassThru + $testResultsFile = "$BuildRoot\Tests\TestResults.xml" + $script:results = Invoke-Pester -Script "$BuildRoot" -Tag Unit -OutputFile $testResultsFile -PassThru $FailureMessage = '{0} Unit test(s) failed. Aborting build' -f $results.FailedCount assert ($results.FailedCount -eq 0) $FailureMessage } @@ -94,10 +91,12 @@ task UpdateMarkdownHelp CheckPlatyPSInstalled, { task CreatePsd1ForRelease CleanTemp, { $functionsToExport = Get-ChildItem -Path 'ZertoApiWrapper\Public\*.ps1' | ForEach-Object { $_.BaseName } + $releaseNotes = "# {0}{1}" -f $version, $(Get-Content .\RELEASENOTES.md -Raw) + $ManifestParams = @{ Path = "$BuildRoot\temp\ZertoApiWrapper.psd1" RootModule = 'ZertoApiWrapper.psm1' - ModuleVersion = '{0}.{1}.{2}' -f $versionMajor, $versionMinor, $versionBuild + ModuleVersion = $version GUID = '4c0b9e17-141b-4dd5-8549-fb21cccaa325' Author = 'Wes Carroll' CompanyName = 'Zerto' @@ -111,6 +110,7 @@ task CreatePsd1ForRelease CleanTemp, { CmdletsToExport = @() VariablesToExport = @() AliasesToExport = @() + ReleaseNotes = $releaseNotes } New-ModuleManifest @ManifestParams } @@ -126,8 +126,19 @@ task CreatePsm1ForRelease CreatePsd1ForRelease, { $emptyLine = "" $psm1Path = "$BuildRoot\temp\ZertoApiWrapper.psm1" $lines = '#------------------------------------------------------------#' - $Public = @( Get-ChildItem -Path $PSScriptRoot\ZertoApiWrapper\Public\*.ps1 -ErrorAction SilentlyContinue ) - $Private = @( Get-ChildItem -Path $PSScriptRoot\ZertoApiWrapper\Private\*.ps1 -ErrorAction SilentlyContinue ) + $Public = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Public\*.ps1 -ErrorAction SilentlyContinue ) + $functionCount = 0 + $exportString = "" + foreach ($file in $Public) { + if ($functionCount -eq 0) { + $functionCount++ + $exportString = "{0}" -f $file.BaseName + } else { + $functionCount++ + $exportString = "{0}, {1}" -f $exportString, $file.BaseName + } + } + $Private = @( Get-ChildItem -Path $BuildRoot\ZertoApiWrapper\Private\*.ps1 -ErrorAction SilentlyContinue ) Add-Content -Path $psm1Path -Value $lines Add-Content -Path $psm1Path -Value "#---------------------Private Functions----------------------#" Add-Content -Path $psm1Path -Value $lines @@ -144,9 +155,27 @@ task CreatePsm1ForRelease CreatePsd1ForRelease, { Add-Content -Path $psm1Path -Value $(Get-Content -Path $file.Fullname -Raw) Add-Content -Path $psm1Path -Value $emptyLine } + Add-Content -Path $psm1Path -Value $emptyLine + Add-Content -Path $psm1Path -Value "Export-ModuleMember -Function $exportString" } -task CreateModule CleanTemp, FileTests, CreatePsd1ForRelease, CreatePsm1ForRelease, AnalyzeBuiltFiles, BuildMamlHelp, { - +task CreateArtifacts CleanPublish, CreateModule, { + if (-not $(Test-Path "$BuildRoot\publish")) { + New-Item -Path $BuildRoot -Name "publish" -ItemType Directory + } + Compress-Archive -Path .\temp\* -DestinationPath .\publish\ZertoApiWrapper.zip + Get-Module -Name ZertoApiWrapper | Remove-Module -Force + Import-Module .\temp\ZertoApiWrapper.psd1 -Force + (Get-Module ZertoApiWrapper).ReleaseNotes | Add-Content .\publish\release-notes.txt + (Get-Module ZertoApiWrapper).Version.ToString() | Add-Content .\publish\release-version.txt } +task CleanPublish { + if ($(Test-Path "$BuildRoot\publish")) { + Remove-Item -Recurse -Path "$BuildRoot\publish\*" + } +} + +task CreateModule CleanTemp, FileTests, AnalyzeBuiltFiles, BuildMamlHelp, { + +} diff --git a/ZertoApiWrapper.settings.ps1 b/ZertoApiWrapper.settings.ps1 index e69de29..2d56eae 100644 --- a/ZertoApiWrapper.settings.ps1 +++ b/ZertoApiWrapper.settings.ps1 @@ -0,0 +1,73 @@ +# This file stores variables which are used by the build script + +# Storing all values in a single $Settings variable to make it obvious that the values are coming from this BuildSettings file when accessing them. +$Settings = @{ + + BuildOutput = "$PSScriptRoot\BuildOutput" + Dependency = @('Pester', 'PsScriptAnalyzer', 'platyPS') + SourceFolder = "$PSScriptRoot\ZertoApiWrapper" + #SourceFolder = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)" + #TestUploadUrl = "https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)" + #CoverallsKey = $env:Coveralls_Key + #Branch = $env:APPVEYOR_REPO_BRANCH + + UnitTestParams = @{ + Script = '.\Tests\Unit' + #CodeCoverage = (Get-ChildItem -Path '.\PSCodeHealth\' -File -Filter "*.ps1" -Recurse).FullName | Where-Object { $_ -Match "Public|Private" } + OutputFile = "$PSScriptRoot\BuildOutput\UnitTestsResult.xml" + PassThru = $True + } + + IntegrationTestParams = @{ + Script = '.\Tests\Integration' + OutputFile = "$PSScriptRoot\BuildOutput\IntegrationTestsResult.xml" + PassThru = $True + } + + AnalyzeParams = @{ + Path = "$PSScriptRoot\$($env:APPVEYOR_PROJECT_NAME)" + Severity = 'Error' + Recurse = $True + } + + IsPullRequest = ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0) + Version = $env:APPVEYOR_BUILD_VERSION + ManifestPath = '{0}\{1}\{1}.psd1' -f $PSScriptRoot, $env:APPVEYOR_PROJECT_NAME + VersionRegex = "ModuleVersion\s=\s'(?\S+)'" -as [regex] + + ModuleName = $env:APPVEYOR_PROJECT_NAME + HeaderPath = "$PSScriptRoot\header-mkdocs.yml" + MkdocsPath = "$PSScriptRoot\mkdocs.yml" + PublicFunctionDocsPath = "$PSScriptRoot\docs\PublicFunctions" + PlatyPSParams = @{ + Module = $env:APPVEYOR_PROJECT_NAME + OutputFolder = "$PSScriptRoot\docs\PublicFunctions" + NoMetadata = $True + Force = $True + } + PrivateFunctionDocsPath = "$PSScriptRoot\docs\InternalFunctions" + InternalDocsPlatyPSParams = @{ + OutputFolder = "$PSScriptRoot\docs\InternalFunctions" + WarningAction = 'SilentlyContinue' + NoMetadata = $True + Force = $True + } + FunctionsToExclude = @('Write-VerboseOutput', 'Get-SwitchCombination') + + GitHubKey = $env:GitHub_Key + Email = 'MathieuBuisson@users.noreply.github.com' + Name = 'Mathieu Buisson' + ScreenshotPath = "$($env:TEMP)\*Screenshot.png" + PSGalleryKey = $env:PSGallery_Key + OutputModulePath = "$PSScriptRoot\BuildOutput\$($env:APPVEYOR_PROJECT_NAME)" +} + +$ModuleManifestParams = @{ + RootModule = "ZertoApiWrapper" + GUID = '4c0b9e17-141b-4dd5-8549-fb21cccaa325' + Author = 'Wes Carroll' + CompanyName = 'Zerto' + Copyright = "(c) $(Get-Date -Format "yyyy") Wes Carroll. All rights reserved." + Description = 'PowerShell Core Wrapper Module for Zerto Virtual Manager API' + PowerShellVersion = '6.0.0' +} diff --git a/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 b/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 index 272fb2a..ecf104e 100644 --- a/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 +++ b/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 @@ -6,10 +6,12 @@ function Add-ZertoPeerSite { Mandatory = $true, HelpMessage = "Target Hostname or IP address to pair the localsite to." )] + [ValidateScript( {$_ -match [IPAddress]$_ } )] [string]$targetHost, [Parameter( HelpMessage = "Target communication port. Default is 9081" )] + [ValidateRange(1024, 65535)] [int]$targetPort = 9081 ) @@ -27,4 +29,4 @@ function Add-ZertoPeerSite { end { # Nothing to do } -} \ No newline at end of file +} diff --git a/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 index 83515b9..e8d94b7 100644 --- a/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 @@ -6,11 +6,13 @@ function Checkpoint-ZertoVpg { Mandatory = $true, HelpMessage = "Name of the VPG to tag." )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( Mandatory = $true, HelpMessage = "Text to tag the checkpoint with." )] + [ValidateNotNullOrEmpty()] [string]$checkpointName ) diff --git a/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 b/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 index 2b4e660..5c7b3b0 100644 --- a/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 +++ b/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 @@ -1,6 +1,7 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Connect-ZertoServer { [cmdletbinding()] + [OutputType([hashtable])] param( [Parameter( Mandatory = $true, @@ -12,14 +13,15 @@ function Connect-ZertoServer { [Parameter( HelpMessage = "Zerto Virtual Manager management port. Default value is 9669." )] + [ValidateNotNullOrEmpty()] + [ValidateRange(1024, 65535)] [Alias("port")] [string]$zertoPort = "9669", [Parameter( Mandatory = $true, HelpMessage = "Valid credentials to connect to the Zerto Management Server" )] - [System.Management.Automation.PSCredential] - $credential, + [System.Management.Automation.PSCredential]$credential, [switch]$returnHeaders ) @@ -37,7 +39,7 @@ function Connect-ZertoServer { process { # Send authorization request to the function and send back the results including headers - $results = Invoke-ZertoRestRequest -uri $uri -credential $credential -returnHeaders -body $body -method POST + $results = Invoke-ZertoRestRequest -uri $uri -credential $credential -returnHeaders -body $body -method POST -ErrorAction Stop } end { diff --git a/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 b/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 index b7d07ca..4559701 100644 --- a/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 +++ b/ZertoApiWrapper/Public/Disconnect-ZertoServer.ps1 @@ -1,6 +1,7 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Disconnect-ZertoServer { [cmdletbinding()] + param() $uri = "session" # Delete API Authorization diff --git a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 index 638f37c..acf1693 100644 --- a/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Edit-ZertoVra.ps1 @@ -6,11 +6,13 @@ function Edit-ZertoVra { Mandatory = $true, HelpMessage = "Identifier of the VRA to be updated." )] + [ValidateNotNullOrEmpty()] [Alias("vraId")] [string]$vraIdentifier, [Parameter( HelpMessage = "Bandwidth group to assign to the VRA. If unspecified will not modify current assignment" )] + [ValidateNotNullOrEmpty()] [string]$groupName, [Parameter( ParameterSetName = "StaticIp", @@ -36,6 +38,9 @@ function Edit-ZertoVra { $baseUri = "vras/{0}" -f $vraIdentifier # Get the current VRA information for use if an updated parameter is not supplied $vra = Get-ZertoVra -vraIdentifier $vraIdentifier + if ( -not $vra ) { + Write-Error "VRA with Identifier: $vraIdentifier could not be found. Please check the ID and try again." + } } process { @@ -49,7 +54,7 @@ function Edit-ZertoVra { $vraUpdate['GroupName'] = $vra.VraGroup } # If ParameterSetName StaticIp is used, update the parameters submitted - if ( $PSCmdlet.ParameterSetName -eq 'StaticIp' ) { + if ( $PSCmdlet.ParameterSetName -eq 'StaticIp' -or $vra.VraNetworkDataApi.VraIPConfigurationTypeApi -eq "Static" ) { if ( $PSBoundParameters.ContainsKey('defaultGateway') ) { $vraNetwork['DefaultGateway'] = $defaultGateway } else { @@ -68,6 +73,9 @@ function Edit-ZertoVra { $vraNetwork['VraIPConfigurationTypeApi'] = "Static" # Add network information to update object. $vraUpdate['VraNetworkDataApi'] = $vraNetwork + } else { + $vraNetwork['VraIPConfigurationTypeApi'] = "Dhcp" + $vraUpdate['VraNetworkDataApi'] = $vraNetwork } # -WhatIf processing and submit! if ($PSCmdlet.ShouldProcess( "Updating " + $vra.vraName + " with these settings: $($vraUpdate | convertTo-Json)")) { @@ -79,3 +87,4 @@ function Edit-ZertoVra { # Nothing to Do } } +#TODO: Refactor \ No newline at end of file diff --git a/ZertoApiWrapper/Public/Export-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Export-ZertoVpg.ps1 index 72224e6..3f5efb8 100644 --- a/ZertoApiWrapper/Public/Export-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Export-ZertoVpg.ps1 @@ -6,17 +6,22 @@ function Export-ZertoVpg { HelpMessage = "Location where to dump the resulting JSON files containing the VPG Settings", Mandatory = $true )] - [string]$outputFolder, + [ValidateNotNullOrEmpty()] + [Alias("outputFolder")] + [string]$outputPath, [parameter( HelpMessage = "Name(s) of the VPG(s) to be exported", - ParameterSetName = "namedVpgs" + ParameterSetName = "namedVpgs", + Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [parameter( HelpMessage = "Export all VPGs at this site", ParameterSetName = "allVpgs", valuefrompipeline = $true, - ValueFromPipelineByPropertyName = $true + ValueFromPipelineByPropertyName = $true, + Mandatory = $true )] [switch]$allVpgs ) @@ -31,7 +36,7 @@ function Export-ZertoVpg { foreach ($name in $vpgName) { $vpgSettingsIdentifier = New-ZertoVpgSettingsIdentifier -vpgIdentifier $(Get-ZertoVpg -name $name).vpgIdentifier $vpgSettings = Get-ZertoVpgSetting -vpgSettingsIdentifier $vpgSettingsIdentifier - $filePath = "{0}\{1}.json" -f $outputFolder, $name + $filePath = "{0}\{1}.json" -f $outputPath, $name $vpgSettings | Convertto-Json -depth 10 | Out-File -FilePath $filePath } } diff --git a/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 b/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 index 1375ba5..1ee27f6 100644 --- a/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 @@ -9,6 +9,7 @@ function Get-ZertoAlert { ValueFromPipelineByPropertyName = $true , HelpMessage = "AlertId or array of AlertIds to be queried" )] + [ValidateNotNullOrEmpty()] [string[]]$alertId, [Parameter( ParameterSetName = "entities", @@ -32,45 +33,53 @@ function Get-ZertoAlert { ParameterSetName = "filter", HelpMessage = "Returns Alerts after the Start Date. Provide the string in the format of 'yyyy-MM-ddTHH:mm:ss.fff'" )] + [ValidateNotNullOrEmpty()] [string]$startDate, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns Alerts before the End Date. Provide the string in the format of 'yyyy-MM-ddTHH:mm:ss.fff'" )] + [ValidateNotNullOrEmpty()] [string]$endDate, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified vraIdentifier" )] + [ValidateNotNullOrEmpty()] [Alias("vpgId")] [string]$vpgIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified siteIdentifier" )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string]$siteIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified zorgIdentifier" )] + [ValidateNotNullOrEmpty()] [Alias("zorgId")] [string]$zorgIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified level" )] + [ValidateNotNullOrEmpty()] [string]$level, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified helpIdentifier" )] + [ValidateNotNullOrEmpty()] [Alias("helpId")] [string]$helpIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "Returns alerts for the specified entity" )] + [ValidateNotNullOrEmpty()] [string]$entity, [Parameter( ParameterSetName = "filter", diff --git a/ZertoApiWrapper/Public/Get-ZertoDatastore.ps1 b/ZertoApiWrapper/Public/Get-ZertoDatastore.ps1 index 46f10ae..8584e90 100644 --- a/ZertoApiWrapper/Public/Get-ZertoDatastore.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoDatastore.ps1 @@ -7,6 +7,7 @@ function Get-ZertoDatastore { ParameterSetName = "datastoreIdentifier", HelpMessage = "datastoreIdentifier or array of datastoreIdentifiers to be queried" )] + [ValidateNotNullOrEmpty()] [string[]]$datastoreIdentifier ) diff --git a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 index c87cab7..1c45ee8 100644 --- a/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoEvent.ps1 @@ -6,43 +6,51 @@ function Get-ZertoEvent { ParameterSetName = "filter", HelpMessage = "The starting date for the list of events, supplied as a date with the format of the Zerto Virtual Manager where the API runs, for example, yyyy-MM-dd. You can also specify a local time with the following format: yyyy-MM-ddTHH:mm:ss.fffZ. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startDate, [Parameter( ParameterSetName = "filter", HelpMessage = "The end date for the list, supplied as a date with the format of the Zerto Virtual Manager where the API runs, for example, yyyy-MM-dd. You can also specify a local time with the following format: yyyy-MM-ddTHH:mm:ss.fffZ. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$endDate, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the VPG for which you want to return events." )] + [ValidateNotNullOrEmpty()] [Alias("vpgName")] [string]$vpg, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the VPG for which you want to return events." )] + [ValidateNotNullOrEmpty()] [Alias("vpgId")] [string]$vpgIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The type of event. For the description of events, refer to the Zerto Virtual Replication documentation about alerts and events. Please see Zerto API Documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$eventType, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the site for which you want to return events." )] + [ValidateNotNullOrEmpty()] [string]$siteName, [Parameter( ParameterSetName = "filter", HelpMessage = "The internal site identifier for which you want to return events." )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string]$siteIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the ZORG, Zerto organization, defined in the Zerto Cloud Manager for which you want to return results." )] + [ValidateNotNullOrEmpty()] [Alias("zorgId")] [string]$zorgIdentifier, [Parameter( @@ -55,12 +63,13 @@ function Get-ZertoEvent { ParameterSetName = "filter", HelpMessage = "The name of the user for which the event occurred. If the event occurred as a result of a task started by the Zerto Virtual Manager, for example, when moving a VPG before the commit stage, the user is System." )] + [ValidateNotNullOrEmpty()] [string]$userName, [Parameter( ParameterSetName = "filter", HelpMessage = "The type of event to return. This filter behaves in the same way as the eventCategory filter. Possible Values are: Possible Values are: 'All', 'Events', 'Alerts'" )] - + [ValidateNotNullOrEmpty()] [string]$category, [Parameter( ParameterSetName = "filter", @@ -72,6 +81,7 @@ function Get-ZertoEvent { ParameterSetName = "filter", HelpMessage = "The internal alert identifier for the Event" )] + [ValidateNotNullOrEmpty()] [Alias("alertId")] [string]$alertIdentifier, [Parameter( @@ -79,7 +89,9 @@ function Get-ZertoEvent { Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, - HelpMessage = "The identifier or identifiers of the event for which information is returned.")] + HelpMessage = "The identifier or identifiers of the event for which information is returned." + )] + [ValidateNotNullOrEmpty()] [string[]]$eventId, [Parameter( ParameterSetName = "categories", diff --git a/ZertoApiWrapper/Public/Get-ZertoLicense.ps1 b/ZertoApiWrapper/Public/Get-ZertoLicense.ps1 index 2bb4e1a..1dba563 100644 --- a/ZertoApiWrapper/Public/Get-ZertoLicense.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoLicense.ps1 @@ -1,6 +1,7 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Get-ZertoLicense { [cmdletbinding()] + param() $uri = "license" Invoke-ZertoRestRequest -uri $uri } diff --git a/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 b/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 index 1b8b4f2..8f64673 100644 --- a/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoPeerSite.ps1 @@ -15,6 +15,7 @@ function Get-ZertoPeerSite { ValueFromPipelineByPropertyName = $true, HelpMessage = "The identifier(s) of the peer site(s) for which information is to be returned." )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string[]]$siteIdentifier, [Parameter( @@ -26,21 +27,25 @@ function Get-ZertoPeerSite { ParameterSetName = "filter", HelpMessage = "The pairing status for which information is to be returned." )] + [ValidateNotNullOrEmpty()] [string]$paringStatus, [Parameter ( ParameterSetName = "filter", HelpMessage = "The site location, as specified in the site information, for which information is to be returned." )] + [ValidateNotNullOrEmpty()] [string]$location, [Parameter ( ParameterSetName = "filter", HelpMessage = "The IP address of a Zerto Virtual Manager, paired with this site, for which information is to be returned." )] + [ValidateNotNullOrEmpty()] [string]$hostName, [Parameter ( ParameterSetName = "filter", HelpMessage = "The port used to access peer sites for which information is to be returned. The default port is 9081." )] + [ValidateNotNullOrEmpty()] [string]$port ) diff --git a/ZertoApiWrapper/Public/Get-ZertoProtectedVm.ps1 b/ZertoApiWrapper/Public/Get-ZertoProtectedVm.ps1 index 9dc58ae..36dc2aa 100644 --- a/ZertoApiWrapper/Public/Get-ZertoProtectedVm.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoProtectedVm.ps1 @@ -9,32 +9,38 @@ function Get-ZertoProtectedVm { ValueFromPipelineByPropertyName = $true, HelpMessage = "vmIdentifier(s) for which to return information" )] + [ValidateNotNullOrEmpty()] [Alias("vmId")] [string[]]$vmIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the VPG which protects the virtual machine." )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the virtual machine." )] + [ValidateNotNullOrEmpty()] [string]$vmName, [Parameter( ParameterSetName = "filter", HelpMessage = "The status of the VPG. Please see Zerto API documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$status, [Parameter( ParameterSetName = "filter", HelpMessage = "The substatus of the VPG, for example the VPG is in a bitmap sync. For the description of substatuses, refer to the Zerto Virtual Manager Administration Guide. Please see Zerto API documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$substatus, [Parameter( ParameterSetName = "filter", HelpMessage = "The ZORG for this VPG." )] + [ValidateNotNullOrEmpty()] [string]$organizationName, [Parameter( ParameterSetName = "filter", @@ -46,22 +52,26 @@ function Get-ZertoProtectedVm { ParameterSetName = "filter", HelpMessage = "The protected site type. Please see Zerto API documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$protectedSiteType, [Parameter( ParameterSetName = "filter", HelpMessage = "The recovery site type. Please see Zerto API documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$recoverySiteType, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the protected site where the VPG virtual machines are protected." )] + [ValidateNotNullOrEmpty()] [Alias("protectedSiteId")] [string]$protectedSiteIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the recovery site where the VPG virtual machines are recovered." )] + [ValidateNotNullOrEmpty()] [Alias("recoverySiteId")] [string]$recoverySiteIdentifier ) diff --git a/ZertoApiWrapper/Public/Get-ZertoRecoveryReport.ps1 b/ZertoApiWrapper/Public/Get-ZertoRecoveryReport.ps1 index 1e4997e..c15ba9c 100644 --- a/ZertoApiWrapper/Public/Get-ZertoRecoveryReport.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoRecoveryReport.ps1 @@ -6,31 +6,37 @@ function Get-ZertoRecoveryReport { ParameterSetName = "filter", HelpMessage = "Operations performed between the specified start Time and end Time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startTime, [Parameter( ParameterSetName = "filter", HelpMessage = "Operations performed between the specified start Time and end Time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$endTime, [Parameter( ParameterSetName = "filter", HelpMessage = "The page number the user wants to retrieve. Minimum value is 1." )] + [ValidateNotNullOrEmpty()] [string]$pageNumber, [Parameter( ParameterSetName = "filter", HelpMessage = "The number of reports to display in a single page. The maximum number of reports per page is 1000." )] + [ValidateNotNullOrEmpty()] [string]$pageSize, [Parameter( ParameterSetName = "filter", HelpMessage = "The internal identifier of the VPG. You can specify more than one VPG, separated by commas." )] + [ValidateNotNullOrEmpty()] [string]$vpgIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the VPG. You can specify more than one VPG, separated by commas." )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( ParameterSetName = "filter", @@ -42,6 +48,7 @@ function Get-ZertoRecoveryReport { ParameterSetName = "filter", HelpMessage = "Whether the recovery operation has completed." )] + [ValidateNotNullOrEmpty()] [string]$state ) diff --git a/ZertoApiWrapper/Public/Get-ZertoResourcesReport.ps1 b/ZertoApiWrapper/Public/Get-ZertoResourcesReport.ps1 index ce35557..f447777 100644 --- a/ZertoApiWrapper/Public/Get-ZertoResourcesReport.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoResourcesReport.ps1 @@ -6,86 +6,103 @@ function Get-ZertoResourcesReport { ParameterSetName = "filter", HelpMessage = "Operations performed between the specified start Time and end Time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startTime, [Parameter( ParameterSetName = "filter", HelpMessage = "Operations performed between the specified start Time and end Time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$endTime, [Parameter( ParameterSetName = "filter", HelpMessage = "The page number to retrieve. Minimum value is 1" )] + [ValidateNotNullOrEmpty()] [string]$pageNumber, [Parameter( ParameterSetName = "filter", HelpMessage = "The number of reports to display in a single page. The maximum number of reports per page is 1000." )] + [ValidateNotNullOrEmpty()] [string]$pageSize, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the organization set up in the Zerto Cloud Manager." )] + [ValidateNotNullOrEmpty()] [string]$zorgName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the virtual machine." )] + [ValidateNotNullOrEmpty()] [string]$vmName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the VPG." )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the protected site." )] + [ValidateNotNullOrEmpty()] [string]$protectedSiteName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the cluster containing the host where the virtual machine in the recovery site resides." )] + [ValidateNotNullOrEmpty()] [string]$protectedClusterName, [Parameter( ParameterSetName = "filter", HelpMessage = "The address or DNS name of the host where the virtual machine in the recovery site resides." )] + [ValidateNotNullOrEmpty()] [string]$protectedHostName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the vDC organization in the protected site." )] + [ValidateNotNullOrEmpty()] [string]$protectedOrgVdc, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the vCD organization in the protected site." )] + [ValidateNotNullOrEmpty()] [string]$protectedVdcOrg, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the recovery site." )] + [ValidateNotNullOrEmpty()] [string]$recoverySiteName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the cluster containing the host where the virtual machine in the recovery site resides." )] + [ValidateNotNullOrEmpty()] [string]$recoveryClusterName, [Parameter( ParameterSetName = "filter", HelpMessage = "The address or DNS name of the host where the virtual machine in the recovery site resides." )] + [ValidateNotNullOrEmpty()] [string]$recoveryHostName, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the vDC organization in the recovery site." )] + [ValidateNotNullOrEmpty()] [string]$recoveryOrgVdc, [Parameter( ParameterSetName = "filter", HelpMessage = "The name of the recovery vCD organization." )] + [ValidateNotNullOrEmpty()] [string]$recoveryVdcOrg ) diff --git a/ZertoApiWrapper/Public/Get-ZertoServiceProfile.ps1 b/ZertoApiWrapper/Public/Get-ZertoServiceProfile.ps1 index 4081a9d..76a5e2e 100644 --- a/ZertoApiWrapper/Public/Get-ZertoServiceProfile.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoServiceProfile.ps1 @@ -6,12 +6,15 @@ function Get-ZertoServiceProfile { ParameterSetName = "siteIdentifier", HelpMessage = "The identifier of the site for which service profiles should be returned." )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string]$siteIdentifier, [Parameter( ParameterSetName = "serviceProfileId", HelpMessage = "The service profile ID for which information should be returned." )] + [ValidateNotNullOrEmpty()] + [Alias("serviceProfileIdentifier")] [string[]]$serviceProfileId ) diff --git a/ZertoApiWrapper/Public/Get-ZertoTask.ps1 b/ZertoApiWrapper/Public/Get-ZertoTask.ps1 index fb670bc..d8f1537 100644 --- a/ZertoApiWrapper/Public/Get-ZertoTask.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoTask.ps1 @@ -6,6 +6,7 @@ function Get-ZertoTask { ParameterSetName = "taskIdentifier", HelpMessage = "The identifier(s) for which task information is to be returned." )] + [ValidateNotNullOrEmpty()] [Alias("taskId")] [string[]]$taskIdentifier, [Parameter( @@ -17,26 +18,31 @@ function Get-ZertoTask { ParameterSetName = "filter", HelpMessage = "Tasks started before this time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startedBeforeDate, [Parameter( ParameterSetName = "filter", HelpMessage = "Tasks started after this time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startedAfterDate, [Parameter( ParameterSetName = "filter", HelpMessage = "Tasks completed after this time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$completedAfterDate, [Parameter( ParameterSetName = "filter", HelpMessage = "Tasks completed before this time (inclusive) are displayed. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$completedBeforeDate, [Parameter( ParameterSetName = "filter", HelpMessage = "The type of task. For the description of the tasks, refer to the Zerto Virtual Replication documentation about monitoring tasks. Please see Zerto API Documentation for possible types and values." )] + [ValidateNotNullOrEmpty()] [string]$type, [Parameter( ParameterSetName = "filter", diff --git a/ZertoApiWrapper/Public/Get-ZertoUnprotectedVm.ps1 b/ZertoApiWrapper/Public/Get-ZertoUnprotectedVm.ps1 index b69aa27..d76e96c 100644 --- a/ZertoApiWrapper/Public/Get-ZertoUnprotectedVm.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoUnprotectedVm.ps1 @@ -1,6 +1,7 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Get-ZertoUnprotectedVm { [cmdletbinding()] + param() $uri = "virtualizationsites/{0}/vms" -f $script:zvmLocalInfo.siteidentifier Invoke-ZertoRestRequest -uri $uri } diff --git a/ZertoApiWrapper/Public/Get-ZertoVirtualizationSite.ps1 b/ZertoApiWrapper/Public/Get-ZertoVirtualizationSite.ps1 index a7e4e01..e296887 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVirtualizationSite.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVirtualizationSite.ps1 @@ -52,6 +52,7 @@ function Get-ZertoVirtualizationSite { Mandatory = $true, HelpMessage = "The identifier of the Zerto Virtual Manager site." )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string]$siteIdentifier, [Parameter( @@ -82,6 +83,7 @@ function Get-ZertoVirtualizationSite { Mandatory = $false, HelpMessage = "The identifier of the host at the selected site to return information for only one host." )] + [ValidateNotNullOrEmpty()] [Alias("hostId")] [string]$hostIdentifier, [Parameter( diff --git a/ZertoApiWrapper/Public/Get-ZertoVolume.ps1 b/ZertoApiWrapper/Public/Get-ZertoVolume.ps1 index 6f44002..dee5130 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVolume.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVolume.ps1 @@ -6,29 +6,34 @@ function Get-ZertoVolume { ParameterSetName = "filter", HelpMessage = "The type of volume. Please see Zerto API Documentation for possible values." )] + [ValidateNotNullOrEmpty()] [string]$volumeType, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the VPG." )] + [ValidateNotNullOrEmpty()] [Alias("vpgId")] [string]$vpgIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the datastore." )] + [ValidateNotNullOrEmpty()] [Alias("datastoreId", "dsId")] [string]$datastoreIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the protected virtual machine." )] + [ValidateNotNullOrEmpty()] [Alias("protectedVmId")] [string]$protectedVmIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the owning virtual machine." )] + [ValidateNotNullOrEmpty()] [Alias("owningVmId")] [string]$owningVmIdentifier ) diff --git a/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 index b3d686a..d151152 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 @@ -17,6 +17,7 @@ function Get-ZertoVpg { Mandatory = $true, HelpMessage = "The identifier(s) of the Virtual Protection Group to return" )] + [ValidateNotNullOrEmpty()] [Alias("vpgId", "protectionGroupId", "pgId")] [string[]]$protectionGroupIdentifier, [Parameter( @@ -29,11 +30,13 @@ function Get-ZertoVpg { ParameterSetName = "checkpoints", HelpMessage = "Return checkpoints after the specified start date. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$startDate, [Parameter( ParameterSetName = "checkpoints", HelpMessage = "Return checkpoints before the specified start date. Valid formats include: 'yyyy-MM-ddTHH:mm:ss.fffZ', 'yyyy-MM-ddTHH:mm:ssZ', 'yyyy-MM-ddTHH:mmZ', 'yyyy-MM-ddTHHZ', 'yyyy-MM-dd', 'yyyy-MM', 'yyyy'. Adding Z to the end of the time sets the time to UTC." )] + [ValidateNotNullOrEmpty()] [string]$endDate, [Parameter( ParameterSetName = "stats", Mandatory = $true, @@ -86,47 +89,56 @@ function Get-ZertoVpg { ParameterSetName = "filter", HelpMessage = "The name of the VPG." )] + [ValidateNotNullOrEmpty()] [Alias("vpgName")] [string]$name, [Parameter( ParameterSetName = "filter", HelpMessage = "The status of the VPG. Please use 'Get-ZertoVpg -statuses' for valid values" )] + [ValidateNotNullOrEmpty()] [string]$status, [Parameter( ParameterSetName = "filter", HelpMessage = "The substatus of the VPG. Please use 'Get-ZertoVpg -substatuses' for valid values" )] + [ValidateNotNullOrEmpty()] [string]$subStatus, [Parameter( ParameterSetName = "filter", HelpMessage = "The protected site environment. This filter behaves in the same way as the sourceType filter. Please see Zerto API Documentation for vaild values and discriptions." )] + [ValidateNotNullOrEmpty()] [string]$protectedSiteType, [Parameter( ParameterSetName = "filter", HelpMessage = "The recovery site environment. This filter behaves in the same way as the sourceType filter. Please see Zerto API Documentation for vaild values and discriptions." )] + [ValidateNotNullOrEmpty()] [string]$recoverySiteType, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the protected site where the VPG virtual machines are protected." )] + [ValidateNotNullOrEmpty()] [string]$protectedSiteIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The identifier of the protected site where the VPG virtual machines are recovered." )] + [ValidateNotNullOrEmpty()] [string]$recoverySiteIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "The ZORG for this VPG." )] + [ValidateNotNullOrEmpty()] [string]$organizationName, [Parameter( ParameterSetName = "filter", HelpMessage = "The internal identifier for the ZORG." )] + [ValidateNotNullOrEmpty()] [string]$zorgIdentifier, [Parameter( ParameterSetName = "filter", @@ -138,6 +150,7 @@ function Get-ZertoVpg { ParameterSetName = "filter", HelpMessage = "The identifier of the service profile to use for the VPG when a Zerto Cloud Manager is used." )] + [ValidateNotNullOrEmpty()] [string]$serviceProfileIdentifier, [Parameter( ParameterSetName = "filter", @@ -173,9 +186,9 @@ function Get-ZertoVpg { if ( $PSBoundParameters.ContainsKey("startDate") -or $PSBoundParameters.ContainsKey("endDate") ) { $filter = $true $filterTable = @{} - foreach ( $key in $PSBoundParameters.Keys ) { - if ( $key -eq "startDate" -or $key -eq "endDate") { - $filterTable[$key] = $PSBoundParameters[$key] + foreach ( $param in $PSBoundParameters.GetEnumerator() ) { + if ( $param.key -eq "startDate" -or $param.key -eq "endDate") { + $filterTable[$param.key] = $param.value } } $filter = Get-ZertoApiFilter -filterTable $filterTable diff --git a/ZertoApiWrapper/Public/Get-ZertoVpgSetting.ps1 b/ZertoApiWrapper/Public/Get-ZertoVpgSetting.ps1 index 5c68f54..a5b8f53 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVpgSetting.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVpgSetting.ps1 @@ -131,6 +131,7 @@ function Get-ZertoVpgSetting { Mandatory = $true, HelpMessage = "The identifier of the VPG settings object for which information is retrieved." )] + [ValidateNotNullOrEmpty()] [Alias("vpgSettingsId", "settingsId")] [string]$vpgSettingsIdentifier, [Parameter( @@ -230,6 +231,7 @@ function Get-ZertoVpgSetting { Mandatory = $true, HelpMessage = "VM Identifier" )] + [ValidateNotNullOrEmpty()] [Alias("vmId")] [string]$vmIdentifier, [Parameter( @@ -243,6 +245,7 @@ function Get-ZertoVpgSetting { Mandatory = $true, HelpMessage = "Return NIC information for specified NIC of the specified VM" )] + [ValidateNotNullOrEmpty()] [Alias("nicId")] [string]$nicIdentifier, [Parameter( @@ -256,6 +259,7 @@ function Get-ZertoVpgSetting { Mandatory = $true, HelpMessage = "Return volume information for the specified volume of the specified VM" )] + [ValidateNotNullOrEmpty()] [Alias("volumeId")] [string]$volumeIdentifier ) diff --git a/ZertoApiWrapper/Public/Get-ZertoVra.ps1 b/ZertoApiWrapper/Public/Get-ZertoVra.ps1 index 5f80ea7..e94d08b 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVra.ps1 @@ -18,52 +18,62 @@ function Get-ZertoVra { ParameterSetName = "vraIdentifier", HelpMessage = "Returns information for provided VRA identifier(s)" )] + [ValidateNotNullOrEmpty()] [Alias("vraId")] [string[]]$vraIdentifier, [Parameter( ParameterSetName = "filter", HelpMessage = "VRA Name to return information for." )] + [ValidateNotNullOrEmpty()] [string]$vraName, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs in a specific status" )] + [ValidateNotNullOrEmpty()] [string]$status, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs of a specific version" )] + [ValidateNotNullOrEmpty()] [string]$vraVersion, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs paired to a specific host version" )] + [ValidateNotNullOrEmpty()] [string]$hostVersion, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for a VRA with the specified IP address" )] + [ValidateNotNullOrEmpty()] [string]$ipAddress, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs belonging to a specific group" )] + [ValidateNotNullOrEmpty()] [string]$vraGroup, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs on a specific datastore" )] + [ValidateNotNullOrEmpty()] [string]$datastoreName, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs on a specific datastore cluster" )] + [ValidateNotNullOrEmpty()] [string]$datastoreClusterName, [Parameter( ParameterSetName = "filter", HelpMessage = "Search for VRAs on a specific network" )] + [ValidateNotNullOrEmpty()] [string]$networkName ) @@ -84,7 +94,7 @@ function Get-ZertoVra { } # When vra ids are provided, return for each id provided - "vraIdentifierifierifier" { + "vraIdentifier" { $returnObject = foreach ( $vraId in $vraIdentifier ) { $uri = "{0}/{1}" -f $baseUri, $vraId Invoke-ZertoRestRequest -uri $uri diff --git a/ZertoApiWrapper/Public/Get-ZertoZorg.ps1 b/ZertoApiWrapper/Public/Get-ZertoZorg.ps1 index 5d17d29..27f39ee 100644 --- a/ZertoApiWrapper/Public/Get-ZertoZorg.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoZorg.ps1 @@ -6,6 +6,7 @@ function Get-ZertoZorg { ParameterSetName = "zorgIdentifier", HelpMessage = "Identifier(s) of the ZORG." )] + [ValidateNotNullOrEmpty()] [Alias("zorgId")] [string[]]$zorgIdentifier ) diff --git a/ZertoApiWrapper/Public/Get-ZertoZsspSession.ps1 b/ZertoApiWrapper/Public/Get-ZertoZsspSession.ps1 index 2d6b293..1c11b36 100644 --- a/ZertoApiWrapper/Public/Get-ZertoZsspSession.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoZsspSession.ps1 @@ -6,6 +6,7 @@ function Get-ZertoZsspSession { ParameterSetName = "zsspSessionIdentifier", HelpMessage = "ZSSP Session Id(s) to get information." )] + [ValidateNotNullOrEmpty()] [Alias("zsspSessionId")] [string[]]$zsspSessionIdentifier ) diff --git a/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 index bbc45ef..48a72cc 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 @@ -8,6 +8,7 @@ function Import-ZertoVpg { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] + [ValidateNotNullOrEmpty()] [Alias("FullName")] [string[]]$settingsFile ) diff --git a/ZertoApiWrapper/Public/Install-ZertoVra.ps1 b/ZertoApiWrapper/Public/Install-ZertoVra.ps1 index 719f6a4..2bca65f 100644 --- a/ZertoApiWrapper/Public/Install-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Install-ZertoVra.ps1 @@ -1,18 +1,22 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> -#TODO - Add ability to installed with root password. +#TODO - Add ability to installed with root password, Move to Begin, Process, End Format function Install-ZertoVra { [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( Mandatory = $true, HelpMessage = "Host name where the VRA is to be installed." )] + [ValidateNotNullOrEmpty()] [string]$hostName, [Parameter( Mandatory = $true, HelpMessage = "Datastore name where the VRA is to be installed." )] + [ValidateNotNullOrEmpty()] [string]$datastoreName, [Parameter( Mandatory = $true, HelpMessage = "Network name the VRA is to be assigned." )] + [ValidateNotNullOrEmpty()] [string]$networkName, [Parameter( HelpMessage = "Initial amount of memory to assign to the VRA in GB. Default is 3, Minimum is 1, Maximum is 16" )] [ValidateRange(1, 16)] [int]$memoryInGB = 3, [Parameter( HelpMessage = "Bandwidth group to assign to the VRA. If unspecified will assign to the 'default_group'" )] + [ValidateNotNullOrEmpty()] [string]$groupName, [Parameter( ParameterSetName = "Dhcp", Mandatory = $true, HelpMessage = "Assign a DHCP address to the VRA." )] [switch]$Dhcp, diff --git a/ZertoApiWrapper/Public/Invoke-ZertoFailover.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoFailover.ps1 index 75f70cc..5eb5500 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoFailover.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoFailover.ps1 @@ -1,16 +1,19 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Invoke-ZertoFailover { - [cmdletbinding()] + [cmdletbinding( SupportsShouldProcess = $true )] param( + #TODO - Refactor? [Parameter( Mandatory = $true, HelpMessage = "Name of the VPG to Failover" )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( HelpMessage = "Checkpoint Identifier to use as the Point-In-Time to rollback to." )] [Alias("checkpointId")] + [ValidateNotNullOrEmpty()] [string]$checkpointIdentifier, [Parameter( HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back. @@ -19,22 +22,20 @@ function Invoke-ZertoFailover { Default is the Site Settings setting." )] [ValidateSet("Rollback", "Commit", "None")] - [string]$commitPolicy, + [string]$commitPolicy = "Rollback", [Parameter( - HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is the Site Setting" - )] - [string]$commitValue, - [Parameter( - HelpMessage = "0: The protected virtual machines are not touched before starting the failover. This assumes that you do not have access to the protected virtual machines. -- DEFAULT - 1: If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the virtual machines are gracefully shut down, otherwise the failover operation fails. This is similar to performing a Move operation to a specified checkpoint. - 2: The protected virtual machines are forcibly shut down before starting the failover. If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. This is similar to performing a Move operation to a specified checkpoint." + HelpMessage = "0: The protected virtual machines are not touched before starting the failover. -- DEFAULT + 1: If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the virtual machines are gracefully shut down, otherwise the failover operation fails. This is similar to performing a Move operation to a specified checkpoint. This assumes that you do not have access to the protected virtual machines. + 2: The protected virtual machines are forcibly shut down before starting the failover. If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. This is similar to performing a Move operation to a specified checkpoint. This assumes that you do not have access to the protected virtual machines" )] [ValidateSet(0, 1, 2)] [int]$shutdownPolicy = 0, [Parameter( - HelpMessage = "Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs" + HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is 60 Minutes (3600 Seconds)" )] - [long]$timeToWaitBeforeShutdownInSec = 300, + # Min 5 Minutes, Max 24 Hours, Default 1 Hour. + [ValidateRange(300, 86400)] + [int]$timeToWaitBeforeShutdownInSec = 3600, [Parameter( HelpMessage = "True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set." @@ -43,29 +44,56 @@ function Invoke-ZertoFailover { [Parameter( HelpMessage = "Name(s) of VMs in the VPG to failover" )] + [ValidateNotNullOrEmpty()] [string[]]$vmName ) begin { - $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier - $baseUri = "vpgSettings/{0}/failover" -f $vpgId - $body = [ordered]@{} - foreach ($key in $PSBoundParameters.Keys) { - if ($key -notlike 'vpgGroup' -or $key -notlike 'vmName') { - $body[$key] = $PSBoundParameters['key'] - } + $vpgId = $(Get-ZertoVpg -name $vpgName).vpgIdentifier + if ( -not $vpgId) { + Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop } - if ($PSBoundParameters.ContainsKey('vmName')) { - $vmIdentifiers = @() - $vmIdentifiers = foreach ( $name in $vmName ) { - $(Get-ZertoProtectedVm -vmName $name).vmIdentifier + $baseUri = "vpgs/{0}/failover" -f $vpgId + $body = @{} + # Setup Required Defaults + $body['commitpolicy'] = $commitPolicy + $body['TimeToWaitBeforeShutdownInSec'] = $timeToWaitBeforeShutdownInSec + + Switch ($PSBoundParameters.Keys) { + "checkpointIdentifier" { + $body['checkpointIdentifier'] = $checkpointIdentifier + } + + "shutdownPolicy" { + $body['shutdownPolicy'] = $shutdownPolicy + } + + "reverseProtection" { + $body['reverseProtection'] = $reverseProtection + } + + "vmName" { + $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName + [System.Collections.ArrayList]$vmIdentifiers = @() + foreach ( $name in $vmName ) { + $selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()} + if ($null -eq $selectedVm) { + Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop + } elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) { + Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop + } else { + $vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null + } + } + $body['VmIdentifiers'] = $vmIdentifiers } - $body['VmIdentifiers'] = $vmIdentifiers } } process { - Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST" + if ($PSCmdlet.ShouldProcess("$vpgName with identifier $vpgId and these options $($body | convertto-json)")) { + Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST" + } } end { diff --git a/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 index 05f40b5..5f88c47 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoFailoverCommit.ps1 @@ -6,31 +6,36 @@ function Invoke-ZertoFailoverCommit { HelpMessage = "Name(s) of the VPG(s) to commit.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [Parameter( HelpMessage = "Use this switch to reverse protect the VPG(s) to the source site." )] - [switch]$reverseProtect + [switch]$reverseProtection ) begin { $baseUri = "vpgs" - if ( $reverseProtect ) { - $body = @{"IsReverseProtect" = $true} + if ( $reverseProtection ) { + $body = @{"IsReverseProtection" = $true} } else { - $body = @{"IsReverseProtect" = $false} + $body = @{"IsReverseProtection" = $false} } } process { foreach ($name in $vpgName) { $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + if ( -not $vpgId ) { + Write-Error "VPG: $name could not be found. Please check the name and try again. Skipping." + } else { + $uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId + Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + } } } end { # Nothing to do } -} \ No newline at end of file +} diff --git a/ZertoApiWrapper/Public/Invoke-ZertoFailoverRollback.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoFailoverRollback.ps1 index e6bc6cb..fc6b92f 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoFailoverRollback.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoFailoverRollback.ps1 @@ -6,6 +6,7 @@ function Invoke-ZertoFailoverRollback { HelpMessage = "Name(s) of VPG(s) to roll back from failing over", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName ) @@ -16,8 +17,12 @@ function Invoke-ZertoFailoverRollback { process { foreach ($name in $vpgName) { $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/FailoverRollback" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -method "POST" + if ( -not $vpgId ) { + Write-Error "VPG: $name not found. Please check the name and try again. Skipping" + } else { + $uri = "{0}/{1}/FailoverRollback" -f $baseUri, $vpgId + Invoke-ZertoRestRequest -uri $uri -method "POST" + } } } diff --git a/ZertoApiWrapper/Public/Invoke-ZertoForceSync.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoForceSync.ps1 index 5dac2eb..81ee866 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoForceSync.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoForceSync.ps1 @@ -6,6 +6,7 @@ function Invoke-ZertoForceSync { HelpMessage = "Name(s) of VPG(s) to force sync", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName ) @@ -16,8 +17,12 @@ function Invoke-ZertoForceSync { process { foreach ($name in $vpgName) { $id = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/forcesync" -f $baseUri, $id - Invoke-ZertoRestRequest -uri $uri -method "POST" + if ( -not $id ) { + Write-Error "VPG: $name not found. Please check the name and try again. Skipping" + } else { + $uri = "{0}/{1}/forcesync" -f $baseUri, $id + Invoke-ZertoRestRequest -uri $uri -method "POST" + } } } diff --git a/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 index 1007b5d..8c7a9a3 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 @@ -1,11 +1,12 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Invoke-ZertoMove { - [CmdletBinding()] + [CmdletBinding( DefaultParameterSetName = "main", SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Name(s) of the VPG(s) you want to move.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [Parameter( HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back. @@ -18,37 +19,35 @@ function Invoke-ZertoMove { [Parameter( HelpMessage = "The amount of time, in seconds, the Move is in a 'Before Commit' state, before performing the commitPolicy setting. If omitted, the site settings default will be applied." )] - [Int32]$commitPolicyTimeout, + # Min 5 Minutes, Max 24 Hours, Default 1 Hour. + [ValidateRange(300, 86400)] + [Int]$commitPolicyTimeout, [Parameter( - HelpMessage = "False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. - True: To force a shutdown of the virtual machines. - Default: True" + HelpMessage = "If this switch is specified, Zerto will attempt to gracefully shut down the Virtual Machines. If the machines do not poweroff within 5 minutes, they will be forcibly powering them off." )] - [bool]$forceShutdown, + [switch]$forceShutdown, [Parameter( - HelpMessage = "False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. - True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. - Default Value: True - Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached." + ParameterSetName = "disableReverseProtection", + HelpMessage = "Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set.", + Mandatory = $true )] - [bool]$reverseProtection = $false, + [switch]$disableReverseProtection, [Parameter( - HelpMessage = "False: Remove the protected virtual machines from the protected site. - True: Prevent the protected virtual machines from being deleted in the protected site. - Default: False" + ParameterSetName = "keepSourceVms", + HelpMessage = "Prevent the protected virtual machines from being deleted in the protected site. Using this setting disables reverse protection.", + Mandatory = $true )] - [bool]$keepSourceVms = $false, + [switch]$keepSourceVms, [Parameter( - HelpMessage = "False: Do not continue the Move operation in case of failure of script executing prior the operation. - True: Continue the Move operation in case of failure of script executing prior the operation. - Default: False" + HelpMessage = "Continue the Move operation in case of failure of script executing prior the operation. If this switch is not set a failure of the script executing prior to the operation will cause the operation to fail." )] - [bool]$continueOnPreScriptFailure + [switch]$ContinueOnPreScriptFailure ) begin { $baseUri = "vpgs" $body = [ordered]@{} + #TODO - use a foreach loop to populate the body without all the if statments if ($PSBoundParameters.ContainsKey('commitPolicy')) { $body['commitPolicy'] = $commitPolicy } @@ -56,24 +55,44 @@ function Invoke-ZertoMove { $body['commitPolicyTimeout'] = $commitPolicyTimeout } if ($PSBoundParameters.ContainsKey('forceShutdown')) { - $body['forceShutdown'] = $forceShutdown + $body['forceShutdown'] = $true + } else { + $body['forceShutdown'] = $false } - if ($PSBoundParameters.ContainsKey('reverseProtection')) { - $body['reverseProtection'] = $reverseProtection + if ($PSBoundParameters.ContainsKey('ContinueOnPreScriptFailure')) { + $body['ContinueOnPreScriptFailure'] = $true + } else { + $body['ContinueOnPreScriptFailure'] = $false } - if ($PSBoundParameters.ContainsKey('keepSourceVms')) { - $body['keepSourceVms'] = $keepSourceVms - } - if ($PSBoundParameters.ContainsKey('continueOnPreScriptFail')) { - $body['continueOnPreScriptFail'] = $continueOnPreScriptFailure + switch ($PSCmdlet.ParameterSetName) { + "disableReverseProtection" { + $body['reverseProtection'] = $false + $body['keepSourceVms'] = $false + } + + "keepSourceVms" { + $body['reverseProtection'] = $false + $body['keepSourceVms'] = $true + } + + "main" { + $body['reverseProtection'] = $true + $body['keepSourceVms'] = $false + } } } process { foreach ($name in $vpgName) { $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/move" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) + if ( -not $vpgId ) { + Write-Error "VPG: $name not found. Please check the name and try again. Skipping" + } else { + $uri = "{0}/{1}/move" -f $baseUri, $vpgId + if ($PSCmdlet.ShouldProcess("Moving VPG: $name wiht settings: $($body | convertto-json)")) { + Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) + } + } } } diff --git a/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 index eedb889..f524af1 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 @@ -1,16 +1,17 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Invoke-ZertoMoveCommit { - [cmdletbinding()] + [cmdletbinding(SupportsShouldProcess = $true)] param( [Parameter( HelpMessage = "Name(s) of the VPG(s) to commit.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [Parameter( HelpMessage = "Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False" )] - [bool]$reverseProtect, + [switch]$reverseProtection, [Parameter( HelpMessage = "Use this switch to keep the source VMs. If not set, they will be destroyed." )] @@ -19,22 +20,29 @@ function Invoke-ZertoMoveCommit { begin { $baseUri = "vpgs" - if ($reverseProtect) { - $body = @{"ReverseProtection" = $reverseProtect; "KeepSourceVms" = $keepSourceVms} - } else { - $body = @{"KeepSourceVms" = $keepSourceVms} + $body = @{} + if ($reverseProtection) { + $body["ReverseProtection"] = $true + } elseif ($keepSourceVms) { + $body["KeepSourceVms"] = $true } } process { foreach ($name in $vpgName) { $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + if ( -not $vpgId ) { + Write-Error "VPG: $name not found. Please check the name and try again. Skipping." + } else { + $uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId + if ($PSCmdlet.ShouldProcess("Commiting VPG: $name with settings $($body | convertto-json)")) { + Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + } + } } } end { # Nothing to do } -} \ No newline at end of file +} diff --git a/ZertoApiWrapper/Public/Invoke-ZertoMoveRollback.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoMoveRollback.ps1 index d51ecc5..b1d7e24 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoMoveRollback.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoMoveRollback.ps1 @@ -1,11 +1,12 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Invoke-ZertoMoveRollback { - [cmdletbinding()] + [cmdletbinding(SupportsShouldProcess = $true)] param( [Parameter( HelpMessage = "Name(s) of VPG(s) to roll back from failing over", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName ) @@ -16,8 +17,14 @@ function Invoke-ZertoMoveRollback { process { foreach ($name in $vpgName) { $id = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/moveRollBack" -f $baseUri, $id - Invoke-ZertoRestRequest -uri $uri -method "POST" + if ( -not $id ) { + Write-Error "VPG: $name not found. Please check the name and try again." + } else { + $uri = "{0}/{1}/moveRollBack" -f $baseUri, $id + if ($PSCmdlet.ShouldProcess("Rolling back VPG: $name")) { + Invoke-ZertoRestRequest -uri $uri -method "POST" + } + } } } diff --git a/ZertoApiWrapper/Public/New-ZertoVpg.ps1 b/ZertoApiWrapper/Public/New-ZertoVpg.ps1 index 48c96b3..a4885f5 100644 --- a/ZertoApiWrapper/Public/New-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/New-ZertoVpg.ps1 @@ -6,6 +6,7 @@ function New-ZertoVpg { HelpMessage = "Name of the VPG", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( HelpMessage = "VPG Priority. High, Medium, or Low. Default value is Medium" @@ -27,6 +28,7 @@ function New-ZertoVpg { HelpMessage = "Name of the site where the VM(s) will be recovered", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$recoverySite, [Parameter( HelpMessage = "Name of the cluster where the VM(s) will be recovered.", @@ -38,6 +40,7 @@ function New-ZertoVpg { ParameterSetName = "recoveryClusterDatastoreCluster", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$recoveryCluster, [Parameter( HelpMessage = "Name of the host where the VM(s) will be recovered.", @@ -49,6 +52,7 @@ function New-ZertoVpg { ParameterSetName = "recoveryHostDatastoreCluster", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$recoveryHost, [Parameter( HelpMessage = "Name of the resource pool where the VM(s) will be recovered.", @@ -60,6 +64,7 @@ function New-ZertoVpg { ParameterSetName = "recoveryResourcePoolDatastoreCluster", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$recoveryResourcePool, [Parameter( HelpMessage = "Name of the datastore where the VM(s), Volume(s), and Journal(s) will reside.", @@ -76,6 +81,7 @@ function New-ZertoVpg { ParameterSetName = "recoveryResourcePoolDatastore", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$datastore, [Parameter( HelpMessage = "Name of the datastore cluster where the VM(s), Volume(s), and Journal(s) will reside.", @@ -92,11 +98,13 @@ function New-ZertoVpg { ParameterSetName = "recoveryResourcePoolDatastoreCluster", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$datastoreCluster, [Parameter( HelpMessage = "Name of folder at recovery location where the recovered virtual machine(s) will be created.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$recoveryFolder, [Parameter( HelpMessage = "RPO alert" @@ -111,6 +119,7 @@ function New-ZertoVpg { [Parameter( HelpMessage = "Service profile name to use." )] + [ValidateNotNullOrEmpty()] [string]$serviceProfile, [Parameter( HelpMessage = "Turn on or off WAN and Journal Compression. Default is turned on." @@ -119,31 +128,37 @@ function New-ZertoVpg { [Parameter( HelpMessage = "Name of ZORG to use." )] + [ValidateNotNullOrEmpty()] [String]$zorg, [Parameter( HelpMessage = "Name of the network to use during a Failover Live \ Move VPG operation.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [String]$recoveryNetwork, [Parameter( HelpMessage = "Name of the network to use during a Failover Test operation", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$testNetwork, [Parameter( HelpMessage = "Name of the datastore to utilize to store Journal data. If not specified, the default datastore will be used.", Mandatory = $false )] + [ValidateNotNullOrEmpty()] [string]$journalDatastore, [Parameter( HelpMessage = "Default journal hard limit in megabytes. Default set to 153600 MB (150 GB). Set to 0 to set the journal to unlimited", Mandatory = $false )] + [ValidateNotNullOrEmpty()] [uint64]$journalHardLimitInMb = 153600, [Parameter( HelpMessage = "Default journal warning threshold in megabytes. If unset or greater than the hard limit, will be set to 75% of the journal hard limit.", Mandatory = $false )] + [ValidateNotNullOrEmpty()] [uint64]$journalWarningThresholdInMb = 0 ) @@ -241,8 +256,7 @@ function New-ZertoVpg { } if ( -not $validSettings ) { - Write-Error "One or more parameters passed do not have valid identifiers or 0 valid VMs were found. Please check your settings and try again." - Break + Write-Error "One or more parameters passed do not have valid identifiers or 0 valid VMs were found. Please check your settings and try again." -ErrorAction Stop } } diff --git a/ZertoApiWrapper/Public/New-ZertoVpgSettingsIdentifier.ps1 b/ZertoApiWrapper/Public/New-ZertoVpgSettingsIdentifier.ps1 index 401b85d..07273b8 100644 --- a/ZertoApiWrapper/Public/New-ZertoVpgSettingsIdentifier.ps1 +++ b/ZertoApiWrapper/Public/New-ZertoVpgSettingsIdentifier.ps1 @@ -1,6 +1,6 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function New-ZertoVpgSettingsIdentifier { - [cmdletbinding()] + [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Identifier of the VPG to create a VPG settings identifier. If a vpgIdentifier is not provided, a new VPG settings object is created without any configured settings. This would be used for creating a new VPG from scratch.", @@ -9,6 +9,7 @@ function New-ZertoVpgSettingsIdentifier { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] + [ValidateNotNullOrEmpty()] [Alias("vpgId")] [string]$vpgIdentifier, [Parameter( @@ -33,10 +34,12 @@ function New-ZertoVpgSettingsIdentifier { } process { - Invoke-ZertoRestRequest -uri $baseUri -body $body -Method "POST" + if ($PSCmdlet.ShouldProcess("Creating VPG Settings Object")) { + Invoke-ZertoRestRequest -uri $baseUri -body $body -Method "POST" + } } end { - + #Nothing to do } } diff --git a/ZertoApiWrapper/Public/Remove-ZertoPeerSite.ps1 b/ZertoApiWrapper/Public/Remove-ZertoPeerSite.ps1 index 6eb8740..0d818e9 100644 --- a/ZertoApiWrapper/Public/Remove-ZertoPeerSite.ps1 +++ b/ZertoApiWrapper/Public/Remove-ZertoPeerSite.ps1 @@ -12,6 +12,7 @@ function Remove-ZertoPeerSite { ValueFromPipelineByPropertyName = $true, Mandatory = $true )] + [ValidateNotNullOrEmpty()] [Alias("siteId")] [string[]]$siteIdentifier, [Parameter( @@ -21,6 +22,7 @@ function Remove-ZertoPeerSite { ValueFromPipelineByPropertyName = $true, Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$peerSiteName, [Parameter( HelpMessage = "IP address of the peer site to be removed from the connected site", diff --git a/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 index b3cedcf..5e453fb 100644 --- a/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 @@ -9,6 +9,7 @@ function Remove-ZertoVpg { ValueFromPipelineByPropertyName = $true, HelpMessage = "Name(s) of the VPG(s) to delete." )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [Parameter( Mandatory = $true, @@ -17,6 +18,7 @@ function Remove-ZertoVpg { ValueFromPipelineByPropertyName = $true, HelpMessage = "vpgIdentifier(s) of the VPG(s) to delete." )] + [ValidateNotNullOrEmpty()] [Alias("vpgId")] [string[]]$vpgidentifier, [Parameter( @@ -55,7 +57,7 @@ function Remove-ZertoVpg { Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" } } else { - Write-Output "VPG with name $vpgName not found. Please check the name and try again" + Write-Error "VPG with name $vpgName not found. Please check the name and try again" } } } diff --git a/ZertoApiWrapper/Public/Resume-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Resume-ZertoVpg.ps1 index f5e1181..24e1c8f 100644 --- a/ZertoApiWrapper/Public/Resume-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Resume-ZertoVpg.ps1 @@ -6,6 +6,7 @@ function Resume-ZertoVpg { HelpMessage = "Name(s) of VPG(s) to resume replication", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName ) @@ -16,8 +17,12 @@ function Resume-ZertoVpg { process { foreach ($name in $vpgName) { $id = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/resume" -f $baseUri, $id - Invoke-ZertoRestRequest -uri $uri -method "POST" + if ( -not $id ) { + Write-Error "VPG: $name not found. Please check the name and try again. Skipping." + } else { + $uri = "{0}/{1}/resume" -f $baseUri, $id + Invoke-ZertoRestRequest -uri $uri -method "POST" + } } } diff --git a/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 b/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 index 8e06784..64c9127 100644 --- a/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 +++ b/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 @@ -10,6 +10,7 @@ function Save-ZertoVpgSetting { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] + [ValidateNotNullOrEmpty()] [Alias("vpgSettingsId")] [string]$vpgSettingsIdentifier ) diff --git a/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 b/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 index 8724476..1969177 100644 --- a/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 +++ b/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 @@ -2,14 +2,14 @@ function Set-ZertoAlert { [cmdletbinding( SupportsShouldProcess = $true )] param ( - [Alias("identifier")] [Parameter( ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true, HelpMessage = "Alert identifier(s) to be dismissed or undismissed." )] - [Alias("alertIdentifier")] + [ValidateNotNullOrEmpty()] + [Alias("alertIdentifier", "identifier", "id")] [string[]]$alertId, [Parameter( ParameterSetName = "dismiss", diff --git a/ZertoApiWrapper/Public/Set-ZertoLicense.ps1 b/ZertoApiWrapper/Public/Set-ZertoLicense.ps1 index 3c5de54..6ce7e32 100644 --- a/ZertoApiWrapper/Public/Set-ZertoLicense.ps1 +++ b/ZertoApiWrapper/Public/Set-ZertoLicense.ps1 @@ -6,6 +6,7 @@ function Set-ZertoLicense { Mandatory = $true, HelpMessage = "License Key to apply to the Zerto Virtual Manager" )] + [ValidateNotNullOrEmpty()] [string]$licenseKey ) diff --git a/ZertoApiWrapper/Public/Start-ZertoCloneVpg.ps1 b/ZertoApiWrapper/Public/Start-ZertoCloneVpg.ps1 index 45ffd5b..1678c8b 100644 --- a/ZertoApiWrapper/Public/Start-ZertoCloneVpg.ps1 +++ b/ZertoApiWrapper/Public/Start-ZertoCloneVpg.ps1 @@ -1,41 +1,62 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Start-ZertoCloneVpg { - [cmdletbinding()] + [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Name of the VPG you wish to clone.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( HelpMessage = "The identifier of the checkpoint to use for cloning. If unspecified, the latest checkpoint will be used." )] + [ValidateNotNullOrEmpty()] [Alias("checkpointId")] [string]$checkpointIdentifier, [Parameter( HelpMessage = "The datastore name where the clone is to be created. If unspecified, will auto select the datastore with the most free space." )] + [ValidateNotNullOrEmpty()] [string]$datastoreName, [Parameter( HelpMessage = "The name(s) of the VMs you wish to clone. If unspecified, all VMs in the VPG will be cloned." )] + [ValidateNotNullOrEmpty()] [string[]]$vmName ) begin { $baseUri = "vpgs" - $vpgInfo = Get-ZertoVpg -name $vpgName + if ( -not $vpgInfo ) { + Write-Error "VPG: $vpgName could not be found. Please check the name and try again." + } $vpgIdentifier = $vpgInfo.vpgIdentifier if ( $PSBoundParameters.ContainsKey('datastoreName') ) { $recoverysiteIdentifier = $vpgInfo.recoverysite.identifier $recoverySiteDatastores = Get-ZertoVirtualizationSite -siteIdentifier $recoverysiteIdentifier -datastores $datastoreIdentifier = $($recoverySiteDatastores | Where-Object {$_.datastoreName -like $datastoreName}).DatastoreIdentifier + if ( -not $datastoreIdentifier ) { + Write-Error "Datastore: $datastoreName is not a valid datastore. Please check the name and try again." -ErrorAction Stop + } } if ( $PSBoundParameters.ContainsKey('vmName') ) { - $vmIdentifiers = @() - $vmIdentifiers = foreach ( $name in $vmName ) { - $(Get-ZertoProtectedVm -vmName $name).vmIdentifier + $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName + [System.Collections.ArrayList]$vmIdentifiers = @() + foreach ( $name in $vmName ) { + $selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()} + if ($null -eq $selectedVm) { + Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop + } elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) { + Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop + } else { + $vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null + } + } + $body['VmIdentifiers'] = $vmIdentifiers + if ($checkpointIdentifier) { + $body['CheckpointIdentifier'] = $checkpointIdentifier } } } @@ -53,7 +74,9 @@ function Start-ZertoCloneVpg { $body['VmIdentifiers'] = $vmIdentifiers } Write-Verbose $body - Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -method "POST" + if ($PSCmdlet.ShouldProcess("Clone Vpg")) { + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -method "POST" + } } end { diff --git a/ZertoApiWrapper/Public/Start-ZertoFailoverTest.ps1 b/ZertoApiWrapper/Public/Start-ZertoFailoverTest.ps1 index 6e8ce11..ee044e3 100644 --- a/ZertoApiWrapper/Public/Start-ZertoFailoverTest.ps1 +++ b/ZertoApiWrapper/Public/Start-ZertoFailoverTest.ps1 @@ -1,48 +1,57 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Start-ZertoFailoverTest { - [cmdletbinding()] + [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Name of VPG to failover test", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$vpgName, [Parameter( HelpMessage = "The identifier of the checkpoint to use for testing. If unspecified, the latest checkpoint will be used." )] + [ValidateNotNullOrEmpty()] [Alias("checkpointId")] [string]$checkpointIdentifier, [Parameter( HelpMessage = "The name(s) of the VMs within the selected VPG you wish to test. If unspecified, all VMs in the VPG will be tested." )] + [ValidateNotNullOrEmpty()] [string[]]$vmName ) begin { $baseUri = "vpgs" $vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier + if ( -not $vpgIdentifier) { + Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop + } if ( $PSBoundParameters.ContainsKey('vmName') ) { - $vmIdentifiers = @() - $vmIdentifiers = foreach ( $name in $vmName ) { - $(Get-ZertoProtectedVm -vmName $name).vmIdentifier + $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName + [System.Collections.ArrayList]$vmIdentifiers = @() + foreach ( $name in $vmName ) { + $selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()} + if ($null -eq $selectedVm) { + Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop + } elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) { + Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop + } else { + $vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null + } + } + $body['VmIdentifiers'] = $vmIdentifiers + if ($checkpointIdentifier) { + $body['CheckpointIdentifier'] = $checkpointIdentifier } } } process { $uri = "{0}/{1}/FailoverTest" -f $baseUri, $vpgIdentifier - $body = [ordered]@{} - if ($checkpointIdentifier) { - $body['CheckpointIdentifier'] = $checkpointIdentifier + if ($PSCmdlet.ShouldProcess($vpgName)) { + Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) } - if ( $PSBoundParameters.ContainsKey('vmName') ) { - $vmIdentifiers = @() - $vmIdentifiers = foreach ( $name in $vmName ) { - $(Get-ZertoProtectedVm -vmName $name).vmIdentifier - } - $body['VmIdentifiers'] = $vmIdentifiers - } - Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) } end { diff --git a/ZertoApiWrapper/Public/Stop-ZertoCloneVpg.ps1 b/ZertoApiWrapper/Public/Stop-ZertoCloneVpg.ps1 index 8e797d7..6e78ade 100644 --- a/ZertoApiWrapper/Public/Stop-ZertoCloneVpg.ps1 +++ b/ZertoApiWrapper/Public/Stop-ZertoCloneVpg.ps1 @@ -1,21 +1,29 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Stop-ZertoCloneVpg { + [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Name of the VPG to stop cloning", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string]$vpgName ) begin { $baseUri = "vpgs" $vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier + if ( -not $vpgIdentifier ) { + Write-Error "VPG: $vpgName could not be found. Please check the name and try again." -ErrorAction Stop + } } process { $uri = "{0}/{1}/CloneAbort" -f $baseUri, $vpgIdentifier - invoke-ZertoRestRequest -uri $uri -method "POST" + if ($PSCmdlet.ShouldProcess("Stopping VPG Clone Operation")) { + invoke-ZertoRestRequest -uri $uri -method "POST" + } + } end { diff --git a/ZertoApiWrapper/Public/Stop-ZertoFailoverTest.ps1 b/ZertoApiWrapper/Public/Stop-ZertoFailoverTest.ps1 index 56f7d1b..babb190 100644 --- a/ZertoApiWrapper/Public/Stop-ZertoFailoverTest.ps1 +++ b/ZertoApiWrapper/Public/Stop-ZertoFailoverTest.ps1 @@ -1,11 +1,12 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Stop-ZertoFailoverTest { - [cmdletbinding()] + [cmdletbinding( SupportsShouldProcess = $true )] param( [Parameter( HelpMessage = "Name(s) of VPG(s) to stop testing.", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName, [Parameter( HelpMessage = "Was the test successful? True or False. True is Default." @@ -14,6 +15,7 @@ function Stop-ZertoFailoverTest { [Parameter( HelpMessage = "Free text field for any notes to add to the test report." )] + [ValidateNotNullOrEmpty()] [string]$failoverTestSummary = "Stop Failover Test for $vpgName" ) @@ -25,8 +27,13 @@ function Stop-ZertoFailoverTest { process { foreach ($name in $vpgName) { $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier + if ( -not $vpgId) { + Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop + } $uri = "{0}/{1}/FailoverTestStop" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) + if ($PSCmdlet.ShouldProcess("Stopping Failover Test on VPG: $name")) { + Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) + } } } diff --git a/ZertoApiWrapper/Public/Suspend-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Suspend-ZertoVpg.ps1 index e19bf3f..c590859 100644 --- a/ZertoApiWrapper/Public/Suspend-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Suspend-ZertoVpg.ps1 @@ -6,6 +6,7 @@ function Suspend-ZertoVpg { HelpMessage = "Name(s) of VPG(s) to pause replication", Mandatory = $true )] + [ValidateNotNullOrEmpty()] [string[]]$vpgName ) @@ -16,8 +17,12 @@ function Suspend-ZertoVpg { process { foreach ($name in $vpgName) { $id = $(Get-ZertoVpg -name $name).vpgIdentifier - $uri = "{0}/{1}/pause" -f $baseUri, $id - Invoke-ZertoRestRequest -uri $uri -method "POST" + if ( -not $id ) { + Write-Error "VPG: $name not found. Skipping." + } else { + $uri = "{0}/{1}/pause" -f $baseUri, $id + Invoke-ZertoRestRequest -uri $uri -method "POST" + } } } diff --git a/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 b/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 index dc5b8b4..b62f332 100644 --- a/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 @@ -6,6 +6,7 @@ function Uninstall-ZertoVra { Mandatory = $true, HelpMessage = "Host Name attached to the VRA to be removed." )] + [ValidateNotNullOrEmpty()] [string[]]$hostName ) @@ -17,8 +18,12 @@ function Uninstall-ZertoVra { foreach ($name in $hostName) { $vraName = "Z-VRA-{0}" -f $name $vraIdentifier = get-zertovra -vraName $vraName | Select-Object vraIdentifier -ExpandProperty vraIdentifier - $uri = "{0}/{1}" -f $baseUri, $vraIdentifier.toString() - Invoke-ZertoRestRequest -uri $uri -method "DELETE" + if ( -not $vraIdentifier ) { + Write-Error "Host: $hostName either does not have a VRA or was not found. Please check the name and try again. Skipping." + } else { + $uri = "{0}/{1}" -f $baseUri, $vraIdentifier.toString() + Invoke-ZertoRestRequest -uri $uri -method "DELETE" + } if ($hostName.Count -gt 1) { Start-Sleep 1 } diff --git a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml index 98cacd1..df46e9f 100644 --- a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml +++ b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml @@ -769,7 +769,7 @@ Export-ZertoVpg - + allVpgs Export all VPGs at this site @@ -780,8 +780,8 @@ False - - outputFolder + + outputPath Location where to dump the resulting JSON files containing the VPG Settings @@ -795,8 +795,8 @@ Export-ZertoVpg - - outputFolder + + outputPath Location where to dump the resulting JSON files containing the VPG Settings @@ -807,7 +807,7 @@ None - + vpgName Name(s) of the VPG(s) to be exported @@ -822,7 +822,7 @@ - + allVpgs Export all VPGs at this site @@ -834,8 +834,8 @@ False - - outputFolder + + outputPath Location where to dump the resulting JSON files containing the VPG Settings @@ -846,7 +846,7 @@ None - + vpgName Name(s) of the VPG(s) to be exported @@ -887,14 +887,14 @@ -------------------------- Example 1 -------------------------- - PS C:> Export-ZertoVpg -outputFolder "C:\ZertoVPGs" -vpgName "My Vpg", "My Other Vpg" + PS C:> Export-ZertoVpg -outputPath "C:\ZertoVPGs" -vpgName "My Vpg", "My Other Vpg" Exports VPG settings for VPGs "My Vpg" and "My Other Vpg". Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. -------------------------- Example 2 -------------------------- - PS C:> Export-ZertoVpg -outputFolder "C:\ZertoVPGs" -allVpgs + PS C:> Export-ZertoVpg -outputPath "C:\ZertoVPGs" -allVpgs Exports VPG settings for all Vpgs replicated to or from this site. Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. If a VPG is in an un-editable state, it cannot be exported. @@ -3422,7 +3422,7 @@ Get-ZertoServiceProfile - + serviceProfileId The service profile ID for which information should be returned. @@ -3452,7 +3452,7 @@ - + serviceProfileId The service profile ID for which information should be returned. @@ -7151,18 +7151,6 @@ None - - commitValue - - The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is the Site Setting - - String - - String - - - None - shutdownPolicy @@ -7180,11 +7168,11 @@ timeToWaitBeforeShutdownInSec - Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs + Time, in seconds, before the commitPolicy is invoked. Default setting is 3600 seconds (60 Minutes). Min value is 300 seconds (5 minutes). Max Value is 86,400 seconds (24 Hours). - Int64 + Int32 - Int64 + Int32 None @@ -7214,6 +7202,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -7244,18 +7254,6 @@ None - - commitValue - - The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is the Site Setting - - String - - String - - - None - reverseProtection @@ -7286,11 +7284,11 @@ timeToWaitBeforeShutdownInSec - Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs + Time, in seconds, before the commitPolicy is invoked. Default setting is 3600 seconds (60 Minutes). Min value is 300 seconds (5 minutes). Max Value is 86,400 seconds (24 Hours). - Int64 + Int32 - Int64 + Int32 None @@ -7319,6 +7317,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -7353,6 +7375,13 @@ Start a failover of VPG "MyVpg" with the latest checkpoint and site default policies. + + -------------------------- Example 2 -------------------------- + PS C:\> Invoke-ZertoFailover -vpgName "MyVpg" -shutdownPolicy 2 -reverseProtection $false -commitPolicy 'Commit' -timeToWaitBeforeShutdownInSec 7200 + + Start a failover of VPG "MyVpg" with the latest checkpoint. VMs will attempt to be gracefully shutdown and if unsuccessful will be forcibly powered off. After 2 hours, if the VPG has not been committed or rolled back, the VPG will auto commit. Reverse protection will not be enabled. + + @@ -7393,7 +7422,7 @@ None - reverseProtect + reverseProtection Use this switch to reverse protect the VPG(s) to the source site. @@ -7407,7 +7436,7 @@ - reverseProtect + reverseProtection Use this switch to reverse protect the VPG(s) to the source site. @@ -7466,7 +7495,7 @@ -------------------------- Example 1 -------------------------- - PS C:\> Invoke-ZertoFailoverCommit -vpgName "MyVpg" -reverseProtect + PS C:\> Invoke-ZertoFailoverCommit -vpgName "MyVpg" -reverseProtection Commits a VPG with reverse protection @@ -7716,60 +7745,155 @@ forceShutdown - False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. - True: To force a shutdown of the virtual machines. - Default: True + By default all virtual machines will attempt to be gracefully shutdown. If a source VM is not running VMware tools or cannot be gracefully shutdown, use this switch to force shutdown the source VMs. - Boolean - Boolean + SwitchParameter - None - - - reverseProtection - - False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. - True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. - Default Value: True - Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached. - - Boolean - - Boolean - - - None - - - keepSourceVms - - False: Remove the protected virtual machines from the protected site. - True: Prevent the protected virtual machines from being deleted in the protected site. - Default: False - - Boolean - - Boolean - - - None + False - continueOnPreScriptFailure + ContinueOnPreScriptFailure - False: Do not continue the Move operation in case of failure of script executing prior the operation. - True: Continue the Move operation in case of failure of script executing prior the operation. - Default: False + Use this switch to continue the Move operation even if the Pre-Script fails to run properly. - Boolean - Boolean + SwitchParameter + + + False + + + disableReverseProtection + + Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + Invoke-ZertoMove + + vpgName + + Name(s) of the VPG(s) you want to move. + + String[] + + String[] None + + commitPolicy + + 'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back. + 'Commit': After the seconds specified in the commitValue setting have elapsed, the failover continues, committing the virtual machines in the recovery site. + 'None': The virtual machines in the VPG being failed over remain in the Before Commit state until either they are committed with Commit a failover, or rolled back with Roll back a failover. + Default is the Site Settings setting. + + String + + String + + + None + + + commitPolicyTimeout + + The amount of time, in seconds, the Move is in a 'Before Commit' state, before performing the commitPolicy setting. If omitted, the site settings default will be applied. + + Int32 + + Int32 + + + None + + + forceShutdown + + By default all virtual machines will attempt to be gracefully shutdown. If a source VM is not running VMware tools or cannot be gracefully shutdown, use this switch to force shutdown the source VMs. + + + SwitchParameter + + + False + + + keepSourceVms + + Use this switch to Prevent the protected virtual machines from being deleted in the protected site. Reverse protection is not automatic with this selection and should reverse protection be required, must be manually configured post commit. + + + SwitchParameter + + + False + + + ContinueOnPreScriptFailure + + Use this switch to continue the Move operation even if the Pre-Script fails to run properly. + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -7801,61 +7925,52 @@ None - continueOnPreScriptFailure + ContinueOnPreScriptFailure - False: Do not continue the Move operation in case of failure of script executing prior the operation. - True: Continue the Move operation in case of failure of script executing prior the operation. - Default: False + Use this switch to continue the Move operation even if the Pre-Script fails to run properly. - Boolean + SwitchParameter - Boolean + SwitchParameter - None + False + + + disableReverseProtection + + Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. + + SwitchParameter + + SwitchParameter + + + False forceShutdown - False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. - True: To force a shutdown of the virtual machines. - Default: True + By default all virtual machines will attempt to be gracefully shutdown. If a source VM is not running VMware tools or cannot be gracefully shutdown, use this switch to force shutdown the source VMs. - Boolean + SwitchParameter - Boolean + SwitchParameter - None + False - + keepSourceVms - False: Remove the protected virtual machines from the protected site. - True: Prevent the protected virtual machines from being deleted in the protected site. - Default: False + Use this switch to Prevent the protected virtual machines from being deleted in the protected site. Reverse protection is not automatic with this selection and should reverse protection be required, must be manually configured post commit. - Boolean + SwitchParameter - Boolean + SwitchParameter - None - - - reverseProtection - - False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. - True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. - Default Value: True - Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached. - - Boolean - - Boolean - - - None + False vpgName @@ -7869,6 +7984,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -7942,18 +8081,6 @@ None - - reverseProtect - - Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False - - Boolean - - Boolean - - - None - keepSourceVms @@ -7965,6 +8092,39 @@ False + + reverseProtection + + Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False + + + SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -7980,17 +8140,17 @@ False - - reverseProtect + + reverseProtection Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False - Boolean + SwitchParameter - Boolean + SwitchParameter - None + False vpgName @@ -8004,6 +8164,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -8077,6 +8261,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -8092,6 +8298,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -8383,6 +8613,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpg @@ -8615,6 +8867,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpg @@ -8847,6 +9121,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpg @@ -9079,6 +9375,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpg @@ -9311,6 +9629,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpg @@ -9543,6 +9883,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -9798,6 +10160,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -9947,6 +10333,28 @@ False + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + New-ZertoVpgSettingsIdentifier @@ -9962,6 +10370,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -9989,6 +10419,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -10824,7 +11278,7 @@ Set-ZertoAlert - + alertId Alert identifier(s) to be dismissed or undismissed. @@ -10872,7 +11326,7 @@ Set-ZertoAlert - + alertId Alert identifier(s) to be dismissed or undismissed. @@ -10920,7 +11374,7 @@ - + alertId Alert identifier(s) to be dismissed or undismissed. @@ -11230,6 +11684,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -11281,6 +11757,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -11378,6 +11878,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -11417,6 +11939,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -11490,6 +12036,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -11505,6 +12073,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + @@ -11602,6 +12194,28 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + @@ -11641,6 +12255,30 @@ None + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + diff --git a/ZertoApiWrapper/ZertoApiWrapper.psd1 b/ZertoApiWrapper/ZertoApiWrapper.psd1 index 58177f0..c86a32b 100644 --- a/ZertoApiWrapper/ZertoApiWrapper.psd1 +++ b/ZertoApiWrapper/ZertoApiWrapper.psd1 @@ -9,7 +9,7 @@ @{ # Script module or binary module file associated with this manifest. - RootModule = 'ZertoApiWrapper.psm1' + RootModule = '.\ZertoApiWrapper.psm1' # Version number of this module. ModuleVersion = '0.0.1' @@ -69,16 +69,16 @@ # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = '*' + FunctionsToExport = 'Add-ZertoPeerSite', 'Checkpoint-ZertoVpg', 'Connect-ZertoServer', 'Disconnect-ZertoServer', 'Edit-ZertoVra', 'Export-ZertoVpg', 'Get-ZertoAlert', 'Get-ZertoDatastore', 'Get-ZertoEvent', 'Get-ZertoLicense', 'Get-ZertoLocalSite', 'Get-ZertoPeerSite', 'Get-ZertoProtectedVm', 'Get-ZertoRecoveryReport', 'Get-ZertoResourcesReport', 'Get-ZertoServiceProfile', 'Get-ZertoTask', 'Get-ZertoUnprotectedVm', 'Get-ZertoVirtualizationSite', 'Get-ZertoVolume', 'Get-ZertoVpg', 'Get-ZertoVpgSetting', 'Get-ZertoVra', 'Get-ZertoZorg', 'Get-ZertoZsspSession', 'Import-ZertoVpg', 'Install-ZertoVra', 'Invoke-ZertoFailover', 'Invoke-ZertoFailoverCommit', 'Invoke-ZertoFailoverRollback', 'Invoke-ZertoForceSync', 'Invoke-ZertoMove', 'Invoke-ZertoMoveCommit', 'Invoke-ZertoMoveRollback', 'New-ZertoVpg', 'New-ZertoVpgSettingsIdentifier', 'Remove-ZertoPeerSite', 'Remove-ZertoVpg', 'Resume-ZertoVpg', 'Save-ZertoVpgSettings', 'Set-ZertoAlert', 'Set-ZertoLicense', 'Start-ZertoCloneVpg', 'Start-ZertoFailoverTest', 'Stop-ZertoCloneVpg', 'Stop-ZertoFailoverTest', 'Suspend-ZertoVpg', 'Uninstall-ZertoVra' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = '*' + CmdletsToExport = @() # Variables to export from this module - VariablesToExport = '*' + VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = '*' + AliasesToExport = @() # DSC resources to export from this module # DscResourcesToExport = @() diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3baef72..46201e1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,56 +3,91 @@ # Add steps that build, run tests, deploy, and more: # https://aka.ms/yaml -name: $(TeamProject)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.rr) +name: $(TeamProject)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.rr) + +# Trigger CI on commit to master and develop branches +trigger: + branches: + include: + - master + - develop + - TestingBranch + +# Trigger CI on pull requests to master and develop branches +pr: + - master + - develop + - TestingBranch jobs: + # Windows Build Job - job: Build_PS_Win2016 timeoutInMinutes: 10 cancelTimeoutInMinutes: 2 pool: vmImage: vs2017-win2016 steps: - - script: | - pwsh -c ".\build.ps1 -Verbose" + # Run build.ps1 script in PowerShell Core + - pwsh: | + .\build.ps1 -Verbose displayName: 'Build and Test' + # Upload test results to Azure Pipeline - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/Public/TestResults.xml' + testResultsFiles: '**/TestResults.xml' testRunTitle: 'PS_Win2016' displayName: 'Publish Test Results' condition: always() + # Linux Build Job - job: Build_PSCore_Ubuntu1604 timeoutInMinutes: 10 cancelTimeoutInMinutes: 2 pool: vmImage: ubuntu-16.04 steps: - - script: | - pwsh -c '.\build.ps1 -verbose' + # Run build.ps1 script in PowerShell Core + - pwsh: | + .\build.ps1 -verbose displayName: 'Build and Test' + # Upload test results to Azure Pipeline - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/Public/TestResults.xml' + testResultsFiles: '**/TestResults.xml' testRunTitle: 'PSCore_Ubuntu1604' displayName: 'Publish Test Results' condition: always() + - task: PublishPipelineArtifact@0 + displayName: 'Publish compiled module Artifact' + inputs: + artifactName: 'ZertoApiWrapper' + targetPath: ./temp + condition: always() + - task: PublishPipelineArtifact@0 + displayName: 'Publish Data' + inputs: + artifactName: 'ReleaseData' + targetPath: ./publish + condition: always() + # MacOS Build Job - job: Build_PSCore_MacOS1013 timeoutInMinutes: 10 cancelTimeoutInMinutes: 2 pool: vmImage: xcode9-macos10.13 steps: - - script: | - pwsh -c '.\build.ps1 -verbose' + # Run build.ps1 script in PowerShell Core + - pwsh: | + .\build.ps1 -verbose displayName: 'Build and Test' + # Upload test results to Azure Pipeline - task: PublishTestResults@2 inputs: testRunner: 'NUnit' - testResultsFiles: '**/Public/TestResults.xml' + testResultsFiles: '**/TestResults.xml' testRunTitle: 'PSCore_MacOS1013' displayName: 'Publish Test Results' condition: always() diff --git a/docs/Export-ZertoVpg.md b/docs/Export-ZertoVpg.md index 9bd5be3..1c0d9f8 100644 --- a/docs/Export-ZertoVpg.md +++ b/docs/Export-ZertoVpg.md @@ -1,105 +1,105 @@ ---- -external help file: ZertoApiWrapper-help.xml -Module Name: ZertoApiWrapper -online version: https://github.com/wcarroll/ZertoApiWrapper/blob/Master/docs/Export-ZertoVpg.md -schema: 2.0.0 ---- - -# Export-ZertoVpg - -## SYNOPSIS -Exports a VPG Settings Object to a JSON file. This file can be used to re-import the VPG at a later time. - -## SYNTAX - -### namedVpgs -``` -Export-ZertoVpg -outputFolder [-vpgName ] [] -``` - -### allVpgs -``` -Export-ZertoVpg -outputFolder [-allVpgs] [] -``` - -## DESCRIPTION -Exports a VPG Settings Object to a JSON file. This file can be used to re-import the VPG at a later time. - -## EXAMPLES - -### Example 1 -```powershell -PS C:> Export-ZertoVpg -outputFolder "C:\ZertoVPGs" -vpgName "My Vpg", "My Other Vpg" -``` - -Exports VPG settings for VPGs "My Vpg" and "My Other Vpg". Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. - -### Example 2 -```powershell -PS C:> Export-ZertoVpg -outputFolder "C:\ZertoVPGs" -allVpgs -``` - -Exports VPG settings for all Vpgs replicated to or from this site. Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. If a VPG is in an un-editable state, it cannot be exported. - -## PARAMETERS - -### -allVpgs -Export all VPGs at this site - -```yaml -Type: SwitchParameter -Parameter Sets: allVpgs -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### -outputFolder -Location where to dump the resulting JSON files containing the VPG Settings - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -vpgName -Name(s) of the VPG(s) to be exported - -```yaml -Type: String[] -Parameter Sets: namedVpgs -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.Management.Automation.SwitchParameter - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS - -[Zerto REST API VPG Settings End Point Documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/RestfulAPIs/StatusAPIs.5.108.html#) +--- +external help file: ZertoApiWrapper-help.xml +Module Name: ZertoApiWrapper +online version: https://github.com/wcarroll/ZertoApiWrapper/blob/Master/docs/Export-ZertoVpg.md +schema: 2.0.0 +--- + +# Export-ZertoVpg + +## SYNOPSIS +Exports a VPG Settings Object to a JSON file. This file can be used to re-import the VPG at a later time. + +## SYNTAX + +### namedVpgs +``` +Export-ZertoVpg -outputPath -vpgName [] +``` + +### allVpgs +``` +Export-ZertoVpg -outputPath [-allVpgs] [] +``` + +## DESCRIPTION +Exports a VPG Settings Object to a JSON file. This file can be used to re-import the VPG at a later time. + +## EXAMPLES + +### Example 1 +```powershell +PS C:> Export-ZertoVpg -outputPath "C:\ZertoVPGs" -vpgName "My Vpg", "My Other Vpg" +``` + +Exports VPG settings for VPGs "My Vpg" and "My Other Vpg". Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. + +### Example 2 +```powershell +PS C:> Export-ZertoVpg -outputPath "C:\ZertoVPGs" -allVpgs +``` + +Exports VPG settings for all Vpgs replicated to or from this site. Each settings object will be placed inside a JSON file at C:\ZertoVPGs\ with the name of the file being the name of the VPG. If a VPG is in an un-editable state, it cannot be exported. + +## PARAMETERS + +### -allVpgs +Export all VPGs at this site + +```yaml +Type: SwitchParameter +Parameter Sets: allVpgs +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -outputPath +Location where to dump the resulting JSON files containing the VPG Settings + +```yaml +Type: String +Parameter Sets: (All) +Aliases: outputFolder + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -vpgName +Name(s) of the VPG(s) to be exported + +```yaml +Type: String[] +Parameter Sets: namedVpgs +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.Management.Automation.SwitchParameter + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS + +[Zerto REST API VPG Settings End Point Documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/RestfulAPIs/StatusAPIs.5.108.html#) diff --git a/docs/Get-ZertoServiceProfile.md b/docs/Get-ZertoServiceProfile.md index 21a381c..536e4e9 100644 --- a/docs/Get-ZertoServiceProfile.md +++ b/docs/Get-ZertoServiceProfile.md @@ -47,7 +47,7 @@ The service profile ID for which information should be returned. ```yaml Type: String[] Parameter Sets: serviceProfileId -Aliases: +Aliases: serviceProfileIdentifier Required: False Position: Named diff --git a/docs/Invoke-ZertoFailover.md b/docs/Invoke-ZertoFailover.md index ecc48e6..0c9f515 100644 --- a/docs/Invoke-ZertoFailover.md +++ b/docs/Invoke-ZertoFailover.md @@ -14,8 +14,8 @@ Start a failover of a VPG ``` Invoke-ZertoFailover [-vpgName] [[-checkpointIdentifier] ] [[-commitPolicy] ] - [[-commitValue] ] [[-shutdownPolicy] ] [[-timeToWaitBeforeShutdownInSec] ] - [[-reverseProtection] ] [[-vmName] ] [] + [[-shutdownPolicy] ] [[-timeToWaitBeforeShutdownInSec] ] [[-reverseProtection] ] + [[-vmName] ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -30,6 +30,13 @@ PS C:\> Invoke-ZertoFailover -vpgName "MyVpg" Start a failover of VPG "MyVpg" with the latest checkpoint and site default policies. +### Example 2 +```powershell +PS C:\> Invoke-ZertoFailover -vpgName "MyVpg" -shutdownPolicy 2 -reverseProtection $false -commitPolicy 'Commit' -timeToWaitBeforeShutdownInSec 7200 +``` + +Start a failover of VPG "MyVpg" with the latest checkpoint. VMs will attempt to be gracefully shutdown and if unsuccessful will be forcibly powered off. After 2 hours, if the VPG has not been committed or rolled back, the VPG will auto commit. Reverse protection will not be enabled. + ## PARAMETERS ### -checkpointIdentifier @@ -68,22 +75,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -commitValue -The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. -Default is the Site Setting - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 3 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -reverseProtection True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. @@ -128,10 +119,10 @@ Accept wildcard characters: False ``` ### -timeToWaitBeforeShutdownInSec -Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs +Time, in seconds, before the commitPolicy is invoked. Default setting is 3600 seconds (60 Minutes). Min value is 300 seconds (5 minutes). Max Value is 86,400 seconds (24 Hours). ```yaml -Type: Int64 +Type: Int32 Parameter Sets: (All) Aliases: @@ -172,6 +163,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Invoke-ZertoFailoverCommit.md b/docs/Invoke-ZertoFailoverCommit.md index afdaa91..b1abfa4 100644 --- a/docs/Invoke-ZertoFailoverCommit.md +++ b/docs/Invoke-ZertoFailoverCommit.md @@ -13,7 +13,7 @@ Commit a running VPG failover ## SYNTAX ``` -Invoke-ZertoFailoverCommit [-vpgName] [-reverseProtect] [] +Invoke-ZertoFailoverCommit [-vpgName] [-reverseProtection] [] ``` ## DESCRIPTION @@ -30,14 +30,14 @@ Commits VPG "MyVpg" without reverse protection ### Example 1 ```powershell -PS C:\> Invoke-ZertoFailoverCommit -vpgName "MyVpg" -reverseProtect +PS C:\> Invoke-ZertoFailoverCommit -vpgName "MyVpg" -reverseProtection ``` Commits a VPG with reverse protection ## PARAMETERS -### -reverseProtect +### -reverseProtection Use this switch to reverse protect the VPG(s) to the source site. ```yaml diff --git a/docs/Invoke-ZertoMove.md b/docs/Invoke-ZertoMove.md index 4cfd149..0f0ac71 100644 --- a/docs/Invoke-ZertoMove.md +++ b/docs/Invoke-ZertoMove.md @@ -12,10 +12,23 @@ Start a move of a VPG. ## SYNTAX +### main (Default) ``` Invoke-ZertoMove [-vpgName] [[-commitPolicy] ] [[-commitPolicyTimeout] ] - [[-forceShutdown] ] [[-reverseProtection] ] [[-keepSourceVms] ] - [[-continueOnPreScriptFailure] ] [] + [-forceShutdown] [-ContinueOnPreScriptFailure] [-WhatIf] [-Confirm] [] +``` + +### disableReverseProtection +``` +Invoke-ZertoMove [-vpgName] [[-commitPolicy] ] [[-commitPolicyTimeout] ] + [-forceShutdown] [-disableReverseProtection] [-ContinueOnPreScriptFailure] [-WhatIf] [-Confirm] + [] +``` + +### keepSourceVms +``` +Invoke-ZertoMove [-vpgName] [[-commitPolicy] ] [[-commitPolicyTimeout] ] + [-forceShutdown] [-keepSourceVms] [-ContinueOnPreScriptFailure] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -69,15 +82,11 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -continueOnPreScriptFailure -False: Do not continue the Move operation in case of failure of script executing prior the operation. - -True: Continue the Move operation in case of failure of script executing prior the operation. - -Default: False +### -ContinueOnPreScriptFailure +Use this switch to continue the Move operation even if the Pre-Script fails to run properly. ```yaml -Type: Boolean +Type: SwitchParameter Parameter Sets: (All) Aliases: @@ -88,15 +97,26 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -forceShutdown -False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. - -True: To force a shutdown of the virtual machines. - -Default: True +### -disableReverseProtection +Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. ```yaml -Type: Boolean +Type: SwitchParameter +Parameter Sets: disableReverseProtection +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -forceShutdown +By default all virtual machines will attempt to be gracefully shutdown. If a source VM is not running VMware tools or cannot be gracefully shutdown, use this switch to force shutdown the source VMs. + +```yaml +Type: SwitchParameter Parameter Sets: (All) Aliases: @@ -108,47 +128,20 @@ Accept wildcard characters: False ``` ### -keepSourceVms -False: Remove the protected virtual machines from the protected site. - -True: Prevent the protected virtual machines from being deleted in the protected site. - -Default: False +Use this switch to Prevent the protected virtual machines from being deleted in the protected site. Reverse protection is not automatic with this selection and should reverse protection be required, must be manually configured post commit. ```yaml -Type: Boolean -Parameter Sets: (All) +Type: SwitchParameter +Parameter Sets: keepSourceVms Aliases: -Required: False +Required: True Position: 5 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -reverseProtection -False: Do not enable reverse protection. -The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. - -True: Enable reverse protection. -The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. - -Default Value: True - -Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached. - -```yaml -Type: Boolean -Parameter Sets: (All) -Aliases: - -Required: False -Position: 4 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -vpgName Name(s) of the VPG(s) you want to move. @@ -164,6 +157,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Invoke-ZertoMoveCommit.md b/docs/Invoke-ZertoMoveCommit.md index 584ee4c..72c687e 100644 --- a/docs/Invoke-ZertoMoveCommit.md +++ b/docs/Invoke-ZertoMoveCommit.md @@ -13,7 +13,7 @@ Commit a VPG currently undergoing a move operation. ## SYNTAX ``` -Invoke-ZertoMoveCommit [-vpgName] [[-reverseProtect] ] [-keepSourceVms] +Invoke-ZertoMoveCommit [-vpgName] [-reverseProtection] [-keepSourceVms] [-WhatIf] [-Confirm] [] ``` @@ -47,18 +47,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -reverseProtect -Set this to True to reverse protect the VPG(s) to the source site. -If not set, will use selection made during move initiation. -True or False +### -reverseProtection +Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False ```yaml -Type: Boolean +Type: SwitchParameter Parameter Sets: (All) Aliases: Required: False -Position: 1 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -79,6 +77,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Invoke-ZertoMoveRollback.md b/docs/Invoke-ZertoMoveRollback.md index 40b5501..e7fd776 100644 --- a/docs/Invoke-ZertoMoveRollback.md +++ b/docs/Invoke-ZertoMoveRollback.md @@ -13,7 +13,7 @@ Rollback a VPG currently undergoing a Move operation ## SYNTAX ``` -Invoke-ZertoMoveRollback [-vpgName] [] +Invoke-ZertoMoveRollback [-vpgName] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -45,6 +45,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/New-ZertoVpg.md b/docs/New-ZertoVpg.md index 73d2536..317c9cb 100644 --- a/docs/New-ZertoVpg.md +++ b/docs/New-ZertoVpg.md @@ -19,7 +19,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ### recoveryClusterDatastore @@ -29,7 +29,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ### recoveryHostDatastoreCluster @@ -39,7 +39,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ### recoveryHostDatastore @@ -49,7 +49,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ### recoveryResourcePoolDatastoreCluster @@ -59,7 +59,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ### recoveryResourcePoolDatastore @@ -69,7 +69,7 @@ New-ZertoVpg -vpgName [-vpgPriority ] [-journalHistoryInHours < [-rpoInSeconds ] [-testIntervalInMinutes ] [-serviceProfile ] [-useWanCompression ] [-zorg ] -recoveryNetwork -testNetwork [-journalDatastore ] [-journalHardLimitInMb ] [-journalWarningThresholdInMb ] - [] + [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -492,6 +492,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/New-ZertoVpgSettingsIdentifier.md b/docs/New-ZertoVpgSettingsIdentifier.md index 93f9beb..4c73305 100644 --- a/docs/New-ZertoVpgSettingsIdentifier.md +++ b/docs/New-ZertoVpgSettingsIdentifier.md @@ -14,12 +14,12 @@ Creates and returns a VPG Settings Identifier either for an existing VPG or a ne ### existingVpg ``` -New-ZertoVpgSettingsIdentifier -vpgIdentifier [] +New-ZertoVpgSettingsIdentifier -vpgIdentifier [-WhatIf] [-Confirm] [] ``` ### newVpg ``` -New-ZertoVpgSettingsIdentifier [-newVpg] [] +New-ZertoVpgSettingsIdentifier [-newVpg] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -75,6 +75,36 @@ Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Set-ZertoAlert.md b/docs/Set-ZertoAlert.md index 9e68770..9de6fc9 100644 --- a/docs/Set-ZertoAlert.md +++ b/docs/Set-ZertoAlert.md @@ -49,7 +49,7 @@ Alert identifier(s) to be dismissed or undismissed. ```yaml Type: String[] Parameter Sets: (All) -Aliases: alertIdentifier, identifier +Aliases: alertIdentifier, identifier, id Required: True Position: Named diff --git a/docs/Start-ZertoCloneVpg.md b/docs/Start-ZertoCloneVpg.md index 467068c..226e97a 100644 --- a/docs/Start-ZertoCloneVpg.md +++ b/docs/Start-ZertoCloneVpg.md @@ -14,7 +14,7 @@ Start a Virtual Protection Group Clone operation ``` Start-ZertoCloneVpg [-vpgName] [[-checkpointIdentifier] ] [[-datastoreName] ] - [[-vmName] ] [] + [[-vmName] ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -94,6 +94,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Start-ZertoFailoverTest.md b/docs/Start-ZertoFailoverTest.md index c5622da..e2d3c1d 100644 --- a/docs/Start-ZertoFailoverTest.md +++ b/docs/Start-ZertoFailoverTest.md @@ -13,8 +13,8 @@ Start a Test Failover of a specific Virtual Protection Group ## SYNTAX ``` -Start-ZertoFailoverTest [-vpgName] [[-checkpointIdentifier] ] [[-vmName] ] - [] +Start-ZertoFailoverTest [-vpgName] [[-checkpointIdentifier] ] [[-vmName] ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -78,6 +78,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Stop-ZertoCloneVpg.md b/docs/Stop-ZertoCloneVpg.md index f4905c6..65e7ab4 100644 --- a/docs/Stop-ZertoCloneVpg.md +++ b/docs/Stop-ZertoCloneVpg.md @@ -13,7 +13,7 @@ Stops a Virtual Protection Group Clone Operation currently running ## SYNTAX ``` -Stop-ZertoCloneVpg [-vpgName] [] +Stop-ZertoCloneVpg [-vpgName] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -45,6 +45,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/docs/Stop-ZertoFailoverTest.md b/docs/Stop-ZertoFailoverTest.md index 0a499dd..63d9f95 100644 --- a/docs/Stop-ZertoFailoverTest.md +++ b/docs/Stop-ZertoFailoverTest.md @@ -14,7 +14,7 @@ Stops a running Failover Test operation. ``` Stop-ZertoFailoverTest [-vpgName] [[-failoverTestSuccess] ] - [[-failoverTestSummary] ] [] + [[-failoverTestSummary] ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -78,6 +78,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.0