Correcting Miss-Used Script Blocks

Hello, I am told my code has miss-used script blocks in it. I don’t really understand what constitutes a script block exactly. Would anyone be willing to give me any method of how you can tell what is or isn’t a script block and where I messed mine up? Thank you!

#create temp directory under user public desktop profile
$directorypath = "C:\temp"
if (-not (Test-Path $directorypath)) {
    New-Item -ItemType Directory -Path "$directorypath"
}  
#uninstall all old existing Firefox components
$LocalUsers = (Get-ChildItem -Path "C:\Users").name

# Uninstalling from Program Files
if (Test-Path "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles(x86)}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}
if (Test-Path "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe"){
    Start-Process -FilePath "${env:ProgramFiles}\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
}

# Uninstalling for each user
ForEach ($LocalUser in $LocalUsers){
    $Userpath = "C:\Users\" + $LocalUser
    if (Test-Path "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe"){
        Start-Process -FilePath "$Userpath\AppData\Local\Mozilla Firefox\uninstall\helper.exe" -ArgumentList '/S' -Verbose #-ErrorAction SilentlyContinue
    }

    Start-Sleep 20

    # Remove shortcuts from appdata
    Remove-Item -Path "$userpath\AppData\Local\Mozilla" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\LocalLow\Mozilla" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Firefox.lnk" -Force -Verbose -ErrorAction SilentlyContinue
    Remove-Item -Path "$userpath\desktop\firefox.lnk" -Force -Verbose -ErrorAction SilentlyContinue
}
$pathToRemove = @(
    'HKLM:\Software\Mozilla'
    'HKLM:\SOFTWARE\mozilla.org'
    'HKLM:\SOFTWARE\MozillaPlugins'
    'HKLM:\SOFTWARE\WOW6432Node\Mozilla'
    'HKLM:\SOFTWARE\WOW6432Node\mozilla.org'
    'HKLM:\SOFTWARE\WOW6432Node\MozillaPlugins'
    'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Firefox.lnk'
)

foreach($path in $pathToRemove) {
    if(Test-Path $path) {
        try {
            Write-Verbose "Attempting to remove: $path" -Verbose
            Remove-Item $path -Recurse -Force
            Write-Verbose "Successfully removed: $path" -Verbose
        }
        catch {
            Write-Warning $_.Exception.Message
        }
    }
}

#clear .txt for fresh start
If (Test-Path C:\temp\Files.txt){
    Remove-Item C:\temp\Files.txt -Force
}
$directoryPath = "C:\temp"

#Script block executes as long as condition value = False
$filepath = "$directoryPath\FireFoxESR.zip"
# Do While loop
Do {
    # Do Something
        aws s3 cp s3://my_company_s3bucket/FireFoxESR/102.4.0/FireFoxESR.zip $directoryPath --profile appstream_machine_role
    }while(!(Test-Path -Path $filepath))

#call the function until there are no folders left and all items have been listed, append output to Files.txt
Function Get-FilesFromZipRecursively {
param (
$InputItem
)

New-Object -TypeName PSCustomObject -Property @{
'BaseName' = $InputItem.name
'FullName' = $InputItem.path
'IsFolder' = $InputItem.isfolder
'Size' = $InputItem.size
'SizeMB' = "{0:n2} MB" -f ($_.size / 1MB )
}

if ($InputItem.IsFolder) {
foreach ($Item in ($Shell.NameSpace($InputItem.Path)).Items()) {
Get-FilesFromZipRecursively -InputItem $Item 
}
}
}
$shell = new-object -com shell.application
$fileName = "$directoryPath\FireFoxESR.zip"
$zip = $shell.namespace("$filename")
$zip.items() | ForEach-Object {
Get-FilesFromZipRecursively -InputItem $_ | Select-String '[A-Z:]+\\[A-Z0-9._]+\\[A-Z0-9._]+\\[A-Z0-9._]*' -AllMatches |
        ForEach-Object {$_.Matches.Value} >> $directoryPath\Files.txt
}
    
Do{expand-archive -Path "$directoryPath\FireFoxESR.zip" -DestinationPath "$directoryPath\FireFoxESR" -Force
    }while(
        (!(Test-Path (Get-Content $directoryPath\Files.txt)))
        )     
        
#execute silent installation of msi
$path = "C:\Windows\System32\msiexec.exe"
$argumentlist = '/i "C:\temp\FireFoxESR\FireFoxESR.msi" /qb'

Do{Start-Process -FilePath $path -ArgumentList $argumentlist -Wait}
    while(!(Test-Path -Path "C:\Program Files\Mozilla Firefox\firefox.exe"))

#Copy new json to session script path
Do{Copy-Item "$directoryPath\FireFoxESR\config.json" -Destination "C:\Appstream\sessionscripts" -Force}
    while(!(Test-Path -Path "C:\appstream\SessionScripts\config.json"))

BTW, loading your code in VS Code gave no errors or warnings for me.