-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ShouldProcess for PowerArubaSW #120
Conversation
I've also updated the vlan tests and also the help section of the cmdlet. |
Hi, yes, i need to use ShouldProcess for all (remove) command ! What do you have make change on Connection.ps1 ? |
It should have been a separate pull. I changed it so it uses write-verbose if you specify -verbose instead of having “noverbose” flag on it. And I also added so the name of the switch is added to the connection so if for instance you have 100 switches you can do I've made a small function that imports vlans from an excel file and adds them to a collection of switches. When doing this its preferable that errors etc refers to a specific switch. Or for instance see this code that I use for cleaning up a lab I was doing. function Remove-ArubaLabVLAN {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
Param(
[Parameter (Mandatory = $False)]
[ValidateNotNullOrEmpty()]
[PSObject]$connection = $DefaultArubaSWConnection
)
Begin {
}
Process {
if ($null -eq $connection -or [string]::IsNullOrEmpty($connection)) {
write-error "No ArubaSwitch specified"
return
}
if ($connection.count -gt 1 -and $connection.GetType().basetype.name -eq 'Array') {
$buff = foreach ($aconn in $connection) {
Remove-ArubaLabVLAN -connection $aconn
}
$buff
} else {
Write-Progress -activity "Remove Vlan on $($connection.Name)" -id 4 -percentcomplete 0
$tot = 8
foreach ($id in @(601..608)) {
$count = $id-600
$uri = "rest/v4/vlans/${id}"
$target = "{0} on {1}" -f $id, $connection.Name
if ($PSCmdlet.ShouldProcess($target, "Remove VLAN")) {
Write-Progress -activity "Remove Vlan on $($connection.Name)" -status $id -id 4 -percentcomplete $($count/$tot*100)
$null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection
Write-Progress -activity "Remove Vlan on $($connection.name)" -id 4 -percentcomplete $($count/$tot*100)
}
}
}
}
End {
}
} |
Yes, it is not a good idea to have noverbose flag...
ok interesting... |
can you split your patch (and make a another PR for connection stuff ?) |
Yeah I'm working on a larger patch for more stuff so will do in a couple of days and we will see what you approve :) |
Hi! This proposed change adds support for -confirm:$false instead of using internal logic and "-noconfirm" flags. However you might want to work a bit with the message displayed if its not to your liking. PS > Remove-ArubaSwitchVLAN -id 10 Confirm Are you sure you want to perform this action? Performing the operation "Remove VLAN" on target "Vlan ID 10". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): n PS > Remove-ArubaSwitchVLAN -id 10 -Confirm:$false PS >
Only medium level for Set and high for Remove add .EXAMPLE with -confirm:false also update Test Suite
Only medium level for Set and high for Remove Update Also Test Suite
high level for Remove Update Also Test Suite
high level for Remove Update Also Test Suite
Only medium level for Set and high for Remove Update Also Test Suite
Hi!
This proposed change adds support for -confirm:$false instead of using internal logic and "-noconfirm" flags.
However you might want to work a bit with the message displayed if its not to your liking.