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.
Remove-20533DEnvironment-1.log
Capture-for-powershell-issue-250418.PNG
Remove-script.docx
alanlam123Asked:
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 CEE Solution Guide - CEO Faru Bonon ITCommented:
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.
try{
    # We want to see any errors...
    $ErrorActionPreference='Continue'

    # Store the start time
    $startTime = Get-Date

    Add-AzureRmAccount

    # Select the target subscription    
    Select-20533DSubscriptionARM

    $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
                Write-Host
                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")
                continue
            }  
            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
    Write-Host

    $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-Host
    Stop-Transcript
}
catch{
    Write-Error $($_.Exception.Message)
}

Open in new window

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

Install-AzureRM. 
Get-AzureRmResourceGroup | select resourcegroupname

Open in new window




Source:
https://stackoverflow.com/questions/41592445/get-azurermresourcegroup-the-term-get-azurermresourcegroup-is-not-recognized
0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.