Disk Management refresh command from script

Status
Not open for further replies.

zolakk

Ars Scholae Palatinae
909
This has been bugging me from quite some time and I feel like there must be a way but google has proven fruitless. I know I can do a rescan from diskpart, but I also need the ability to run the "Refresh" command from a script that gets run by right-clicking on Disk Management and clicking on Refresh. Language doesn't really matter, but I am ultimately rolling it into a c# program but I can call external commands if needed but WMI/.NET/Win32 is probably more elegant. Alternatively, a pre-written but free program that will extend a parition to fill a resized base disk (extend only) would work too, as that's the operation i'm trying to work through.

Any thoughts?

Edit: I'm working with Windows 2003 R2 and 2008 R2, so ideally it would work for both but 2008 R2 is the focus
 

zolakk

Ars Scholae Palatinae
909
Diskpart will extend a volume for you, no need to refresh anything:
Code:
diskpart
rescan
list volume
select volume 1
extend


Diskpart also supports scripts:
http://technet.microsoft.com/en-us/libr ... 14984.aspx
That's exactly what's i'm doing currently, but it doesn't always work. Sometimes you run into this doing it manually where if you go to extend the disk and windows complains there isn't enough space available to complete the operation, and doing the refresh command clears this error (rescan will not). The difference from what I understand is the rescan command only refreshes the info on a hardware level (scanning the bus) where the refresh command forces windows to refresh the logical disk information.
 

zolakk

Ars Scholae Palatinae
909
i've run into it on Windows 7 and 2008 R2 for sure, and i'm pretty sure also 2003 R2 but not 100% on that. It is definitely not a consistent thing so it's not easily repeatable but doing a rescan never works to resolve the error and the refresh command works 100% of the time. It's probably only because i'm dealing with 100s of Windows VMs and frequently have to extend data disks for users that i'm even catching this. Next time I run into it, i'll take some screenshots to show what i'm talking about
 
[url=http:/civis/viewtopic.php?p=28110787#p28110787:t4plvyzw said:
zolakk[/url]":t4plvyzw]i've run into it on Windows 7 and 2008 R2 for sure, and i'm pretty sure also 2003 R2 but not 100% on that. It is definitely not a consistent thing so it's not easily repeatable but doing a rescan never works to resolve the error and the refresh command works 100% of the time. It's probably only because i'm dealing with 100s of Windows VMs and frequently have to extend data disks for users that i'm even catching this. Next time I run into it, i'll take some screenshots to show what i'm talking about
I only do it a dozen or so times a month (because SQL admins are entirely incapable of estimating how much disk they'll need), but I've never had it fail. I think there's some weirdness with 2003, but I've never seen it with 2008R2 or 2012R2. Not that I'm saying it can't happen, just that it's sort of rare.

Have you considered just not worrying about it, and doing the ones that fail by hand? Spending a ton of time to resolve the edge cases never seems to pay off in my book.
 
Status
Not open for further replies.