ORA-19809: limit exceeded for recovery files and flash_recovery_area

Hi.
I am getting the below errors (at the end) when trying to backup the database using RMAN.
The directory structure is
E:\oracle\TEST
E:\oracle\TEST\flash_recovery_area
E:\oracle\TEST\flash_recovery_area\arch --> HAS ARCHIVE FILES
E:\oracle\TEST\flash_recovery_area\TEST
E:\oracle\ATEST\flash_recovery_area\TEST\BACKUPSET --> RMAN backup sets
E:\oracle\TEST\flash_recovery_area\TEST\ONLINELOG --> This is empty.
D:\oracle\product\10.2.0\ is oracle home
It has:
D:\oracle\product\10.2.0\admin
D:\oracle\product\10.2.0\db1
D:\oracle\product\10.2.0\oradata
D:\oracle\product\10.2.0\oradata\test has data files.
1) I created this database using OUI and DBCA and I have a feeling that this structure is somewhat convoluted. Could you let me know if this needs to be changed?
2) Secondly, the RMAN error. The entire size of E:\oracle\TEST\flash_recovery_area is now only 1.74 GB yet I am getting this error.
I deleted old archive logs from E:\oracle\TEST\flash_recovery_area\arch . Currently it has only arch logs for seven days. Next I issued delete expired archivelog all command. Right now crosscheck archivelog all finds only 40 archive logs..
and increased db_recovery_file_dest_size to 10GB. alter system set db_recovery_file_dest_size=10000M scope=both;
select name
, floor(space_limit / 1024 / 1024) "Size MB"
, ceil(space_used / 1024 / 1024) "Used MB"
from v$recovery_file_dest
order by name
This query is returning the use space as 6GB. However physically only 1.74 GB is currenly used. Please let me know the way forward. Appreciate in advance.
channel ORA_DISK_1: starting piece 1 at 09-JUN-09
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/09/2009 17:56:
15
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 52428800 bytes disk space from 10485760000 limit
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 09-JUN-09
channel ORA_DISK_1: finished piece 1 at 09-JUN-09
piece handle=E:\ORACLE\TEST\FLASH_RECOVERY_AREA\TEST\BACKUPSET\2009_06_09\
O1_MF_NCSNF_TAG20090609T175224_52XPN0Y9_.BKP tag=TAG20090609T175224 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/09/2009 17:56:
15
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 52428800 bytes disk space from 10485760000 limit
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 06/09/2009 17:54:
19
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 52428800 bytes disk space from 10485760000 limit
RMAN>

Hi,
Thanks for looking into my problem... Here are the answers..
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination E:\oracle\TEST\flash_recovery_area\arch
Oldest online log sequence 1011
Next log sequence to archive 1013
Current log sequence 1013
SQL>
select * from v$flash_recovery_area_usage;
FILE_TYPE     PERCENT_SPACE_USED     PERCENT_SPACE_RECLAIMABLE     NUMBER_OF_FILES
CONTROLFILE     0.00               0.00                    0
ONLINELOG     0.00               0.00                    0
ARCHIVELOG     0.00               0.00                    0
BACKUPPIECE     66.57               0.20                    5
IMAGECOPY     0.00               0.00                    0
FLASHBACKLOG     0.00               0.00                    0
SQL> show parameter log_archive_dest
NAME TYPE VALUE
log_archive_dest string
log_archive_dest_1 string LOCATION=E:\oracle\TEST\flash_recovery_area\arch
log_archive_dest_10 string
log_archive_dest_2 string
log_archive_dest_3 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
log_archive_dest_7 string
log_archive_dest_8 string
NAME TYPE VALUE
log_archive_dest_9 string
log_archive_dest_state_1 string enable
log_archive_dest_state_10 string enable
log_archive_dest_state_2 string enable
log_archive_dest_state_3 string enable
log_archive_dest_state_4 string enable
log_archive_dest_state_5 string enable
log_archive_dest_state_6 string enable
log_archive_dest_state_7 string enable
log_archive_dest_state_8 string enable
log_archive_dest_state_9 string enable
SQL>

Similar Messages

  • Please HELP with ORA-19809: limit exceeded for recovery files

    Hi Gurus,
    I am not a DBA but a developer. Today my Oracle database 11g on my PC will not open and I am getting the errors,
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    I checked my alert logs and found these errors,
    Errors in file c:\oracle\diag\rdbms\orcl\orcl\trace\orcl_ora_2144.trc:
    ORA-19809: limit exceeded for recovery files
    ORA-19804: cannot reclaim 41072128 bytes disk space from 4039114752 limit
    ARCH: Error 19809 Creating archive log file to 'C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\ARCHIVELOG\2011_04_08\O1_MF_1_120_%U_.ARC'
    Errors in file c:\oracle\diag\rdbms\orcl\orcl\trace\orcl_ora_2144.trc:
    ORA-16038: log 3 sequence# 120 cannot be archived
    ORA-19809: limit exceeded for recovery files
    ORA-00312: online log 3 thread 1: 'C:\ORACLE\ORADATA\ORCL\REDO03.LOG'
    USER (ospid: 2144): terminating the instance due to error 16038
    Instance terminated by USER, pid = 2144
    So I started searching for answers on this forum and found a suggestion using RMAN to delete all the archive logs,
    RMAN> connect target sys/*******
    RMAN> delete archivelog all;
    RMAN>crosscheck archivelog all;
    But I get these errors in RMAN,
    using target database control file instead of recovery catalog
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of delete command at 04/08/2011 11:20:58
    RMAN-06403: could not obtain a fully authorized session
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    So, please help me: How do I fix this problem since I can't start the instance?
    Thank you.
    Ben

    You need to increase the FRA by changing the parameter DB_RECOVERY_FILE_DEST_SIZE. Create a parameter file while being connected as Sys user and issue,
    sql>create pfile from spfile;It would create the pfile in the Oracle_Home/database folder. Edit that file and increase the parameter to a larger size-like double of it's current value. Save the file and issue,
    sql>startup pfile=<your location of the file>HTH
    Aman....

  • Limit execeed for Recovery files.

    After starting my DB ,Getting this Erro........
    Database mounted.
    ORA-16038: log 1 sequence# 227 cannot be archived
    ORA-19809: limit exceeded for recovery files
    ORA-00312: online log 1 thread 1:
    'D:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\REDO01.LOG'
    How can Resolve this problem.

    16038, 00000, "log %s sequence# %s cannot be archived"
    // *Cause:  An attempt was made to archive the named file, but the
    //          file could not be archived. Examine the secondary error
    //          messages to determine the cause of the error.
    // *Action: No action is required.
    bcm@bcm-laptop:~$ oerr ora 19809
    19809, 00000, "limit exceeded for recovery files"
    //*Cause: The limit for recovery files specified by the
    //        DB_RECOVERY_FILE_DEST_SIZE was exceeded.
    // *Action: There are five possible solutions:
    //          1) Take frequent backup of recovery area using RMAN.
    //          2) Consider changing RMAN retention policy.
    //          3) Consider changing RMAN archived log deletion policy.
    //          4) Add disk space and increase DB_RECOVERY_FILE_DEST_SIZE.
    //          5) Delete files from recovery area using RMAN.

  • ~ORA-16038: log 2 sequence# 140 cannot be archived~ORA-19809: limit exceede

    ~ORA-16038: log 2 sequence# 140 cannot be archived~ORA-19809: limit exceeded for recovery files~ORA-00312: online log 2 thread 1: '/u02/oradata/PROD/redo02.log'
    but my /u02/oradata/PROD/ is empty, mod is set to 777
    What possible happened?
    Thanks.

    09:37:29 SQL> startup
    ORA-32004: obsolete and/or deprecated parameter(s) specified
    ORACLE instance started.
    see my init.ora, last three line is added by me,
    is it obsolete and/or deprecated parameter(s)?
    *.remote_login_passwordfile='EXCLUSIVE'
    *.sga_target=838860800
    *.undo_management='AUTO'
    *.undo_tablespace='UNDOTBS1'
    *.user_dump_dest='/u01/app/oracle/admin/PROD/udump'
    LOG_ARCHIVE_START=TRUE
    LOG_ARCHIVE_DEST=/u02/archive/PROD
    LOG_ARCHIVE_FORMAT=arc%s.arc

  • ORA-16038: log 1 sequence# 1292 cannot be archived ORA-19809: limit exceede

    I am getting this error when starting the database 10g
    ORA-16038: log 1 sequence# 1292 cannot be archived
    ORA-19809: limit exceeded for recovery files
    ORA-00312: online log 1 thread 1:
    '/usr/lib/oracle/xe/app/oracle/flash_recovery_area/XE/onlinelog/o1_mf_1_45ngtrx0_.log'
    Can someone help me, it is very urgent.
    Zulqarnain

    It is resolved when I tried
    ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = 15G SCOPE=BOTH

  • The specified file or folder name is too long,the url path for all files and folders

    The specified file or folder name is too long,the url path for all files and folders must be 260 character or less
    can we increase this limit?
    MCTS,ITIL

    Hi,
    As I understand, you want to increase the length of URL path in SharePoint 2010.
    Per my knowledge, this limit cannot be increased. SharePoint limits URL length because all relative URL links are stored in the clear forms on the SharePoint content DB and often this links are used as primary keys to link one table with another. Fields
    which are used to store these links (for instance tp_DirName from the AllUserData table) allow storing only 256 characters.
    There are several ways that you can resolve or mitigate URL length problems in the SharePoint Server 2010 environment. The following list provides suggestions:
    1. Upgrade all the end-user browsers to Internet Explorer 8, which has a longer URL length limit.
    2. Use shorter names for sites, folders, and documents and control the depth of the site and folder structures to reduce the lengths of URLs.
    3. If possible or allowed, use ASCII names for sites, folders, and documents. This will avoid situations where the URL will be lengthened by being encoded.
    4. To reduce the risk that the SharePoint Server 2010 end-users will encounter problems because of URL length limitations, we recommend that you apply the following effective limits in the deployment:
    256 Unicode (UTF-16) Code units - the effective file path length limitation, including a domain/server name
    128 Unicode (UTF-16) Code units - the path component length limitation
    More reference:
    http://technet.microsoft.com/en-us/library/ff919564(v=office.14).aspx
    http://sharepointknowledgebase.blogspot.in/2013/04/url-path-length-restrictions-in.html#.VKJN53BJA
    Best regards,
    Sara Fan

  • Attachments dont download from Gmail in Safari, They disappear,I even tried re-downloading Safari and that download disappeared, it is not in my downloads folder, I actually searched in finder for the file and it is nowhere on my computer.  Please help!

    Attachments dont download from Gmail in Safari, They disappear,I even tried re-downloading Safari and that download disappeared, it is not in my downloads folder, I actually searched in finder for the file and it is nowhere on my computer.  Please help!

    Oh my gosh I had the EXACT same problem, and for ages I couldn't figure out how to fix it until today. Here's what I did:
    First I went onto my computer, opened itunes, and un-installed tumblr, vine and kik. These were the apps I was having problems with (it said I had them on my phone but, like you, they didn't show).
    Then I went to the itunes store, searched for each one, and it said I could update them so I did (just FYI: for tumblr a window popped up saying "please click ok to confirm you are 17 years or older", so I did that also)
    When I went back to my phone and tried installing them again (still on my computer), it worked!
    I hope this helps, because it was incredibly frustrating. Good luck!

  • Wait for a file and start execute a scenario process

    What is the best way to achive: Wait for a file and then once the file in droped...execute a scenario process.
    Sample scenario:
    - Admin user ftp the file to a target directory on Unix (export/home/odi/input/files)
    - A scheduled scenario package will be running/scheduled daily
    - In the above scenario, The first step is to have one OdiFileWait (with options: Dir:/export/home/odi/input/files, File: xxxxx.txt,wait time and loop over..etc)
    /* But for some reason OdiFileWait is not waiting/checking for the file presence define in the option. It seems to run immediately without checking the presence of the file and passing it to run the second step) */
    - The second step is the "OdiStartScen" (This will run an interface generated scenario) and since the file doesn't exist as a source to load that this interface uses...its fails.
    What's the common practice to accomplish this? Appreciate your feedbacks…
    Thank you

    Update:
    I increased the timeout and Pollint setting in OdiFileWait option and its working fine now.
    When the file exists (or) ftp within the timeout the process goes to next step (OK). But, say the file doesn't exists and the timeout finished...how do i set a KO to OdiFileWait and stop/complete by existing at that step itself with out failure.

  • 8dot3 filenames not created for Program Files and Program Files (x86)

    Interesting issue we are realizing on Servers deployed from SCCM 2012. 8dot3names are not created for Program Files and Program Files (x86). they are created for other files/folders at the root of C and below Program Files and Program Files (x86). This is
    causing issues when programs are installed and the path is then created with 8dot3 filenames for program files and program files (x86)

    Arg. we just got bitten by this "feature", and it's affecting our security software stack (name starts with M and ends with ee), and some ancient crud too.
    And found this, which suggests a logical reason for 8dot3name to not be present on servers, but, on clients, I think it's a rather gross assumption...
    http://blogs.technet.com/b/josebda/archive/2012/11/13/windows-server-2012-file-server-tip-disable-8-3-naming-and-strip-those-short-names-too.aspx
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • Searching for missing files and damaged photo icon

    I am trying to view photos that I have viewed in this program numerous times before but now when I click on the photos, I get a message that says "searching for missing files". Sometimes, the photo appears with a red icon below it that resembles a wripped photo. Does this mean my photo has been damaged by the program?

    I too have been told to find them on my hard drive but still nothing comes up, I can find the picture name and then do a search, but nothing. I've tried several times and it just keeps saying seach for missing files not found. I can see my collection of pictures, but there blury and then when I try to click on them, it says searching for missing file and it gives me the file name, and then I've tried to go under my search and put that file name in and nothing comes up, I also got NO help from adobe and they want us to buy more products??? They could have warned us somehow on what happens if you move them or try and put them on disc, and that's what happen, I put some on disk or at least thought I did and then realized I didn't want to do that, so I hit the UNDUE and I guess it was so late or something, cuz I can see the pictues, just can't open them. I'm wandering if I need to have a expert see if he can get them off of Adobe, I really want the pictues I have graduation pictures on there and need them very much. Would love to have help from anybody. Please.
    Thank you
    K

  • Static credit check: credit limit exceeded for consignment issue delivery

    Hi,
    We are encountering a credit limit exceeded error in delivery creation for a consignment issue.
    In SPRO config "Credit limit check for order types", no credit limit check is assigned to the order type. However, there is one assigned for the delivery type. Also, for CCAr/Risk cat./CG combination in OVA8 (Auto Credit Block Delivery), static credit check has been activated with error message reaction. Open orders and open deliveries were also activated. Customer exceeded credit exposure but user cannot release the order in any VKMx transactions as no credit limit check is assigned to the order type.
    Given that this is the current setup, and the following conditions:
    1. Credit limit for the customer cannot be increased
    2. Oldest open item cannot be cleared just yet
    Is there any way that we can proceed with delivery creation for this customer? The other order types have credit limit check so credit management team was able to release them. However, we are unsure on how to proceed with this consignment order. Kindly advise and thank you in advance for your help.

    We are encountering a credit limit exceeded error in delivery creation for a consignment issue.
    but user cannot release the order in any VKMx transactions as no credit limit check is assigned to the order type.
    Looks contradictory and it may need to run report RVKRED77 to reorganization of open credit values. Try to run the report in test system and then run in production system. After running the report, the use must be able to release in VKM* transaction.
    Regards,

  • File Server Role: Slow access for "opened files" and slow Explorer browsing

    Since we migrated our fileserver from Windows Server 2008 R2 to Windows Server 2012 we are facing two major problems:
    1. Opening files which are already opened by other users takes about 1 minute before the file actually opens. This is not only for Office files such as Excel and Word, but also for other (not office) files. Again, this problem only rises when the file(s)
    is/are already opened by another user. There seems to be a sort of "Lock" check time which is about 45 to 60 seconds.
    2. The other problem is browsing via Explorer through the network drive (all clients are Windows 7 clients). Half of the time there is some kind of "hick up" with displaying the results of the folder. I cannot figure out a patern, but if there
    is no "hick up" then browsing is very fast (also in the busiest times of the working day)... If there is a "hick up" the result can take about 50 seconds to display the content of a folder.
    I suspect the SMB implementation / settings of Windows Server 2012 which are causing the problems...
    Things I tried:
    1. Changed the Oplocks wait time to 10 seconds (which is the minimum). The result is that openening files does indeed go some faster (still taking about 45 seconds).
    2. Disabled SMB2: the result is that browsing is fast... Opening files does go faster. BUT: we are then facing other problems like some files are not able to open... This setting was, after getting a lot of complaints from the users, changed back to enabled
    SMB2.
    3. Within the NIC card properties I disabled "QoS packet Scheduler", "Link-Layer Topology Discovery Mapper I/O Driver", "Link-Layer Topology Discovery Responder" and IPv6 (as we only use IPv4).
    All above with not the promising results.
    The server is a dedicated (virtual machine on vSphere 5.1) fileserver.
    Please Advice since this is not workable, and we have postponed the migration of the fileserver for our aother location.

    Hi Dave,
    I suggest you disable all third party applications like Anti-Virus application to test if it could reduce the waiting time when accessing a file.
    Here are some related threads below that could be useful to you:
    DFS Slowness when Opening Microsoft Documents and Excel Spreadsheets
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/61ec9a99-0027-44cb-815c-0da9276c1c96/dfs-slowness-when-opening-microsoft-documents-and-excel-spreadsheets?forum=winservergen
    Opening files over network takes long time
    http://social.technet.microsoft.com/Forums/windows/en-US/c8ddb65f-8a17-4cee-afd4-dfc09e99d562/opening-files-over-network-takes-long-time?forum=w7itpronetworking
    opening folder or file takes over a minute on Windows 2008R2 File server
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b9aa98c4-3ef7-4e6d-810d-6099e72b33f6/opening-folder-or-file-takes-over-a-minute-on-windows-2008r2-file-server?forum=winserverfiles
    Best Regards,
    Amy Wang

  • How do I set up my iPad for outlook files and folders

    I want to see and use, on my iPad, the same files and folders I have in outlook on my PC. Also I want any changes I make on the PC or the iPad to sync with each other.
    PC is running Windows 7,
    Outlook version 2007, not the exchange version although I think I can get that by re-installing outlook and choosing that option.(I don't understand what exchange is but don't bother to explain it unless the solution requires using it)
    I currently use Gmail for my email accounts server. They are set up as POP accounts with Outlook using a .PST data file. However, IMAP is available for Gmail. My brief past experience with IMAP and .OST data files was kind of a disaster so it isn't my 1st choice for this.
    As I understand it using Outlook 365 with Microsoft's cloud and mobile app would solve my problem but I don't like clouds, 365 or IMAP (I may have to concede on some of those). If there is a way to do it through the Gmail accounts without any other cloud  that would be ideal since they already have all my email and I won't be spreading my personal info to other companies.
    I do have a Drop Box account but I currently only use it for some well vetted specific files that I share with specific individuals.
    I do not have any computer or network drive that is always on and might serve as a private cloud. That could be changed but then i'm relying there being no ISP or power interruptions which, of course do occasionally happen.
    Obviously I'm being rather picky here knowing that I'll probably have to live with some things less than ideal.
    I will consider 3rd party apps if they seem to be part of the solution.
    Thank you in advance for any person/s that want to help me on this.
    hsvt

    Thanks. I can change the forwarding settings in Gmail to be either POP or IMAP. That is quite simple. I just looked at those settings on the Gmail server and, to my surprise, both are enabled. In order for outlook client on my computer to receive IMAP emails I have to change the email account settings in my current outlook from POP to IMAP. I don't need to be using the Exchange version of Outlook to receive IMAP. I guess I'll do a little research tomorrow on Exchange so i can figure out what, if anything, it might do for me.
    I glanced at the link you sent me and it looks like it might be very helpful - another project for tomorrow.
    BTW: I hit "This Solved my Question" by accident. I meant only to "like' your response so you would get some benefit from the help you've given me so far. I hope I haven't discouraged others from taking a shot at helping me. I suspect there is more than one way to approach this and, as you know, my problem isn't really solved until I have what I need all set up and running smoothly.

  • Can I partition a hard drive so that one partition is for windows files and the other is for time machine backups?

    I have a 1TB WD passport that currently contains windows files e.g photos, documents, etc. Can I partition it so that one partition contains these files and the other partition is used for time machine backups? Also, how do I change the partition system on the hard drive so that it uses the GUID partition system?
    Thanks in advance.

    Yes, you can, though you need to format and partition the drive from the scratch.
    1) back up your PC data on other drive.
    2) partitioning your drive into 2 partitions with Disk Utility.
    3) format one partition by Mac OS extended (journaling) for Time Machine, the other by exFAT for PC data.
    4) restore PC data on exFAT partitioned drive.

  • Browsing for a file and selecting a Virtual Machine on hyper-v

    Hi everyone, sorry if the title is a bit problematic.
    New to Powershell here, I'm trying to create a script that will let me Browse for a .vhd file, and then let me select a Virtual Machine to attach it to using SCSI attachment.
    So far I managed to attach and detach the VHD files using add-vmharddiskdrive, but using read-host I have to manually enter the address of the .vhd file every time, as well as using read-host to input the VM name.
    Is there any way to browse for the file, select it, and then run the add-vmharddiskdrive command?
    So far the script I have is this:
    $VHDLocation = Read-Host Enter VHD Location
    $VMName = Read-Host Enter VM Name
    Add-VMHardDiskDrive -VMName $VMName -Path $VHDLocation -ControllerType SCSI
    Basically I want to shorten the time it takes to manually type the vhd location and the VM name. Any way to do that?
    Sorry for long post, thanks everyone in advance, have a nice day :)

    I couldn't get the Select-fromgridview to work sadly, but after snooping around on several different forums I managed to copy-paste some codes and after some work and trial and error I got the script to work perfectly, except for one problem. When the box
    pops up to let met select a VM, it pops in the background, as in, behind the ISE itself. So I have to alt tab to see it. Is there any way to make it pop to the front?
    I'd go through the script myself but like I said I'm very new to this and honestly most of this could be Chinese for all I know.
    Again thanks in advance!
    set-executionpolicy unrestricted
    ############## The script for browsing #############
    Function Get-FileName($initialDirectory)
     [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
     Out-Null
     $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
     $OpenFileDialog.initialDirectory = $initialDirectory
     $OpenFileDialog.filter = "All files (*.*)| *.*"
     $OpenFileDialog.ShowDialog() | Out-Null
     $OpenFileDialog.filename
    } #end function Get-FileName
    ############## Sets the VHD location parameter to the selected file from above, and input VM Name  #############
    $VHDLocation = Get-FileName -initialDirectory "c:\fso"
    ############## Select a VM ######
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    $objForm = New-Object System.Windows.Forms.Form 
    $objForm.Text = "Select a Computer"
    $objForm.Size = New-Object System.Drawing.Size(300,200) 
    $objForm.StartPosition = "CenterScreen"
    # Got rid of the block of code related to KeyPreview and KeyDown events.
    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(75,120)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    # Got rid of the Click event for the OK button, and instead just assigned its DialogResult property to OK.
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $objForm.Controls.Add($OKButton)
    # Setting the form's AcceptButton property causes it to automatically intercept the Enter keystroke and
    # treat it as clicking the OK button (without having to write your own KeyDown events).
    $objForm.AcceptButton = $OKButton
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Size(150,120)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    # Got rid of the Click event for the Cancel button, and instead just assigned its DialogResult property to Cancel.
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $objForm.Controls.Add($CancelButton)
    # Setting the form's CancelButton property causes it to automatically intercept the Escape keystroke and
    # treat it as clicking the OK button (without having to write your own KeyDown events).
    $objForm.CancelButton = $CancelButton
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,20) 
    $objLabel.Size = New-Object System.Drawing.Size(280,20) 
    $objLabel.Text = "Please select a computer:"
    $objForm.Controls.Add($objLabel) 
    $objListBox = New-Object System.Windows.Forms.ListBox 
    $objListBox.Location = New-Object System.Drawing.Size(10,40) 
    $objListBox.Size = New-Object System.Drawing.Size(260,20) 
    $objListBox.Height = 80
    Get-VM | Format-List name | Out-File -filepath c:\VMNames.txt
    ${C:\VMNames.txt} = ${C:\VMNames.txt} | select -skip 2
    function Remove-Topline ( [string[]]$path, [int]$skip=2 ) {
      if ( -not (Test-Path $path -PathType Leaf) ) {
        throw "invalid filename"
      ls $path |
        % { iex "`${$($_.fullname)} = `${$($_.fullname)} | select -skip $skip" }
    (Get-Content C:\VMNames.txt) | 
    Foreach-Object {$_ -replace "Name :", ""} | 
    Set-Content C:\VMNames.txt
    Get-Content C:\VMNames.txt | ForEach-Object {[void] $objListBox.Items.Add($_)}
    $objForm.Controls.Add($objListBox) 
    $objForm.Topmost = $True
    # Now, instead of having events in the form assign a value to a variable outside of their scope, the code that calls the dialog
    # instead checks to see if the user pressed OK and selected something from the box, then grabs that value.
    $result = $objForm.ShowDialog()
    if ($result -eq [System.Windows.Forms.DialogResult]::OK -and $objListBox.SelectedIndex -ge 0)
        $selection = $objListBox.SelectedItem
        $selection
        # Do something with $selection
    $VMName = $selection.Trim()
    ############## Dismounts the VHD if it's mounted on host, and then mounts it on VHD #############
    Dismount-VHD $VHDLocation
    Add-VMHardDiskDrive -VMName $VMName -Path $VHDLocation -ControllerType SCSI
    ############## Detaches the VHD from VM and returns it to the host #############
    Add-Type -AssemblyName Microsoft.VisualBasic
    [Microsoft.VisualBasic.Interaction]::MsgBox('Press Ok when you are ready to detach the VHD', 'MsgBoxSetForeground,Information', 'Confirm')
    Remove-VMHardDiskDrive -VMName $VMname -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0
    Mount-VHD $VHDLocation 

Maybe you are looking for