functions/Remove-AllProjects.ps1

<#
.SYNOPSIS
Deletes all projects from the server.
  
.DESCRIPTION
This is a nuclear option to delete all projects from the server. There is no reverse course for this and it should not be used lightly.
  
.EXAMPLE
Remove-AllProjects
  
#>


Function Remove-AllProjects
{
    [cmdletbinding()]
    param()
    


    $projs = Get-Projects
    $projs = $projs.projects

    $warntext = "You are about to DELETE " + $projs.count + " projects!!!"
    $warntext = $warntext.PadRight(60," ")

    Write-Host "##################################################################" -ForegroundColor Red
    Write-Host "# #" -ForegroundColor Red
    Write-Host "# " $warntext "#" -ForegroundColor Red
    Write-Host "# #" -ForegroundColor Red
    Write-Host "##################################################################" -ForegroundColor Red

    Write-Host "`r`nAre you sure?"
    $userconfirm = Read-Host -Prompt "Type NUKETHEM to confirm"

    Write-Host $userconfirm

    $i = 0

    If($userconfirm -ceq "NUKETHEM"){
        $projs | ForEach-Object {
            Write-Verbose "Removing Project: $_"
            $uri = $CDXSERVER + "/api/projects/" + $_.id
            $DeleteProject = Invoke-RestMethod -Uri $uri -Method Delete -Headers $headers -ContentType "application/json" 
            #If($DeleteProject){}
            Write-Verbose ( $respHeaders | Format-Table | Out-String )
            $i++
        } 
    }
    Write-Host "Process Complete."
    Write-Host "Removed $i projects from the server."
}