unable to run remove scirpt in Powershell

Hi expert

good day

I am encountered an issued ,when i tried to execute the following command " Remove-20533DEnvironment" and error messages show in the screenshot.

I have attach the log files for your reference.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
You are cleaning up variables in the global scope that are in the "local" scope. A global variable in the global scope must be with the "$global:<variablename>".
then you can use
Remove-Variable -scope Global <variablename>

You would probably try it as a script 1st, then you can transform it to a function, you can run it on ISE.
    # We want to see any errors...

    # Store the start time
    $startTime = Get-Date


    # Select the target subscription    

    $subscriptionName = (Get-AzureRmSubscription -SubscriptionId $Global:20533DsubscriptionIdGlobal -ErrorAction SilentlyContinue).Name
    If (!($subscriptionName)) {
        $subscriptionName = (Get-AzureRmSubscription -SubscriptionId $global:20533DsubscriptionIdGlobal -ErrorAction SilentlyContinue).SubscriptionName

    if (!($Global:20533DlabNumberGlobal)) {
        Do {
            Write-Host -NoNewline "Which lab environment do you want to remove? Type a number from 1 - 11:   " -ForegroundColor Magenta
            $labNumber = Read-Host 
        } While ((1..11) -notcontains $labNumber)

        $global:20533DlabNumberGlobal = $labNumber
    Do {
        # Confirm with user before proceeding
        $labNumberTwoDigit = ([int]$Global:20533DlabNumberGlobal).ToString("00")
        Write-Host "This script will remove 20533D lab $Global:20533DlabNumberGlobal environment from the subscription $subscriptionName" -ForegroundColor Magenta
        Write-Host "The script deletes all resource groups with names starting with 20533D$labNumberTwoDigit and their resources" -ForegroundColor Magenta 
        Write-Host "To remove 20533D environment for a different lab, press D when prompted " -ForegroundColor Magenta 
        Write-Host "Do you want to proceed? Y/N/D?: "  -ForegroundColor Magenta
        $answer = read-host
        Switch ($answer)
            Y {Write-Host "Deleting all objects..." -ForegroundColor Yellow}
            N {Write-Host "Terminating the script..."; Start-Sleep -Seconds 2; Return }
            D {# Get the lab number
                Do {
                    Write-Host -NoNewline "Which lab environment do you want to remove? Type a number from 1 - 11:   " -ForegroundColor Magenta
                    $labNumber = Read-Host 
                } While ((1..11) -notcontains $labNumber)
                $global:20533DlabNumberGlobal = $labNumber
                $labNumberTwoDigit = ([int]$Global:20533DlabNumberGlobal).ToString("00")
            Default {continue}
    } While ($answer -notmatch "[YN]")

    $rootPath = (Get-Item $PSScriptRoot).Parent.Parent.FullName
    $transcriptPath = ""
    If ($Global:20533DlabNumberGlobal) {
        $transcriptPath = Join-Path -Path $rootPath -ChildPath "Logs\Remove-20533DEnvironment-$Global:20533DlabNumberGlobal.log"
    else {
        $transcriptPath = Join-Path -Path $rootPath -ChildPath "Logs\Remove-20533DEnvironment-0.log"

    Start-Transcript -Path $transcriptPath -IncludeInvocationHeader -Append -Force

    foreach ($resourceGroupName in (Get-AzureRMResourceGroup).ResourceGroupName) {
        if ($resourceGroupName -like "20533D$labNumberTwoDigit*") {
             Write-Host "Deleting $resourceGroupName resource group..."
             Remove-AzureRMResourceGroup -Name $resourceGroupName -Force -InformationAction SilentlyContinue

    # Display time taken for script to complete
    $endTime = Get-Date

    Write-Host "Started at $startTime" -ForegroundColor Magenta
    Write-Host "Ended at $endTime" -ForegroundColor Yellow

    $elapsedTime = $endTime - $startTime

    If ($elapsedTime.Hours -ne 0){
        Write-Host "Total elapsed time is $($elapsedTime.Hours) hours $($elapsedTime.Minutes) minutes" -ForegroundColor Green
    } else {

        Write-Host "Total elapsed time is $($elapsedTime.Minutes) minutes" -ForegroundColor Green

    Remove-Variable -Scope Global  20533DlabNumberGlobal, 20533DsubscriptionIdGlobal #,  20533DlocationGlobal
    Write-Error $($_.Exception.Message)

Open in new window

Chirag NagrekarSystem AnalystCommented:
As per your .PNG file below command will helpful to you.

Get-AzureRmResourceGroup | select resourcegroupname

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Chat / IM

From novice to tech pro — start learning today.