Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class WebSite {
- [string] $Name
- [string] $Category # Can be one of: Production, Test, Development
- }
- Function CategoryToImpact([string]$Category) {
- Switch ($Category) {
- 'Production' {
- [System.Management.Automation.ConfirmImpact]::High
- break
- }
- 'Test' {
- [System.Management.Automation.ConfirmImpact]::Medium
- break
- }
- 'Development' {
- [System.Management.Automation.ConfirmImpact]::Low
- break
- }
- default {
- [System.Management.Automation.ConfirmImpact]::None
- break
- }
- }
- }
- Function Remove-WebSite {
- [CmdletBinding(SupportsShouldProcess=$true<#,ConfirmImpact="Depends!"#>)]
- Param(
- [Parameter(Mandatory=$true)]
- [WebSite] $WebSite
- )
- # This doesn't work but I hope it illustrates what I'd *like* to do
- #$PSCmdLet.ConfirmImpact = CategoryToImpact($WebSite.Category)
- if ($PSCmdlet.ShouldProcess("$($WebSite.Category) site $($WebSite.Name)")) {
- Write-Host "$($WebSite.Name) was destroyed"
- }
- }
- $prod = New-Object WebSite
- $prod.Name = 'www.example.com'
- $prod.Category = 'Production'
- Remove-WebSite $prod
- $test = New-Object WebSite
- $test.Name = 'test.example.com'
- $test.Category = 'Test'
- Remove-WebSite $test
- $dev = New-Object WebSite
- $dev.Name = 'dev.example.com'
- $dev.Category = 'Development'
- Remove-WebSite $dev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement