Look for volume D if found and volume size is greater than 1tb run DISKPART /S filename
As far as I understand I can use:
WMIC /node:"%computername%" LOGICALDISK GET Name
to get the name and I can use:
WMIC /node:"%computername%" LOGICALDISK GET size
to get the size.
I am have difficulties to get this working using a batch scripting.
batch-file wmic
add a comment |
As far as I understand I can use:
WMIC /node:"%computername%" LOGICALDISK GET Name
to get the name and I can use:
WMIC /node:"%computername%" LOGICALDISK GET size
to get the size.
I am have difficulties to get this working using a batch scripting.
batch-file wmic
add a comment |
As far as I understand I can use:
WMIC /node:"%computername%" LOGICALDISK GET Name
to get the name and I can use:
WMIC /node:"%computername%" LOGICALDISK GET size
to get the size.
I am have difficulties to get this working using a batch scripting.
batch-file wmic
As far as I understand I can use:
WMIC /node:"%computername%" LOGICALDISK GET Name
to get the name and I can use:
WMIC /node:"%computername%" LOGICALDISK GET size
to get the size.
I am have difficulties to get this working using a batch scripting.
batch-file wmic
batch-file wmic
edited Nov 15 '18 at 21:38
LotPings
18.5k61532
18.5k61532
asked Nov 13 '18 at 4:46
David GreenwayDavid Greenway
81
81
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
As comparing the 1TB size would get difficult with batch, let wmic do the job
WMIC /node:"%computername%" LOGICALDISK where "Name='D:' AND Size>1099511627776" Get Name|findstr "^D:" && (
DISKPART /S filename
) || (
Echo Partition is less than 1TB
)
Otherwise you don't tell about the difficulties you have.
add a comment |
>nul 2>nul (
wmic logicaldisk where "caption='d:' and size > 1099511627776" | find "Win32_LogicalDisk"
) && (
echo Drive found
)
This code just executes the indicated wmic
query (drive d:
and size greater than 1TB) and checks the output with find
command to see if any drive has been found, while hiding the output of any message or error by redirecting standard output stream and error stream to nul
device.
If the output of the wmic
command contains Win32_LogicalDisk
, a matching drive has been found and find
will clear (set to 0
) the errorlevel
. If there is not a matching drive find
will fail and raise the errorlevel
(set to 1
)
The conditional execution operator &&
(execute next command if the previous one did not set errorlevel
) is used to check the find
sucess/failure and determine if diskpart
should be executed.
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273970%2flook-for-volume-d-if-found-and-volume-size-is-greater-than-1tb-run-diskpart-s-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As comparing the 1TB size would get difficult with batch, let wmic do the job
WMIC /node:"%computername%" LOGICALDISK where "Name='D:' AND Size>1099511627776" Get Name|findstr "^D:" && (
DISKPART /S filename
) || (
Echo Partition is less than 1TB
)
Otherwise you don't tell about the difficulties you have.
add a comment |
As comparing the 1TB size would get difficult with batch, let wmic do the job
WMIC /node:"%computername%" LOGICALDISK where "Name='D:' AND Size>1099511627776" Get Name|findstr "^D:" && (
DISKPART /S filename
) || (
Echo Partition is less than 1TB
)
Otherwise you don't tell about the difficulties you have.
add a comment |
As comparing the 1TB size would get difficult with batch, let wmic do the job
WMIC /node:"%computername%" LOGICALDISK where "Name='D:' AND Size>1099511627776" Get Name|findstr "^D:" && (
DISKPART /S filename
) || (
Echo Partition is less than 1TB
)
Otherwise you don't tell about the difficulties you have.
As comparing the 1TB size would get difficult with batch, let wmic do the job
WMIC /node:"%computername%" LOGICALDISK where "Name='D:' AND Size>1099511627776" Get Name|findstr "^D:" && (
DISKPART /S filename
) || (
Echo Partition is less than 1TB
)
Otherwise you don't tell about the difficulties you have.
edited Nov 13 '18 at 10:10
answered Nov 13 '18 at 7:01
LotPingsLotPings
18.5k61532
18.5k61532
add a comment |
add a comment |
>nul 2>nul (
wmic logicaldisk where "caption='d:' and size > 1099511627776" | find "Win32_LogicalDisk"
) && (
echo Drive found
)
This code just executes the indicated wmic
query (drive d:
and size greater than 1TB) and checks the output with find
command to see if any drive has been found, while hiding the output of any message or error by redirecting standard output stream and error stream to nul
device.
If the output of the wmic
command contains Win32_LogicalDisk
, a matching drive has been found and find
will clear (set to 0
) the errorlevel
. If there is not a matching drive find
will fail and raise the errorlevel
(set to 1
)
The conditional execution operator &&
(execute next command if the previous one did not set errorlevel
) is used to check the find
sucess/failure and determine if diskpart
should be executed.
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
add a comment |
>nul 2>nul (
wmic logicaldisk where "caption='d:' and size > 1099511627776" | find "Win32_LogicalDisk"
) && (
echo Drive found
)
This code just executes the indicated wmic
query (drive d:
and size greater than 1TB) and checks the output with find
command to see if any drive has been found, while hiding the output of any message or error by redirecting standard output stream and error stream to nul
device.
If the output of the wmic
command contains Win32_LogicalDisk
, a matching drive has been found and find
will clear (set to 0
) the errorlevel
. If there is not a matching drive find
will fail and raise the errorlevel
(set to 1
)
The conditional execution operator &&
(execute next command if the previous one did not set errorlevel
) is used to check the find
sucess/failure and determine if diskpart
should be executed.
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
add a comment |
>nul 2>nul (
wmic logicaldisk where "caption='d:' and size > 1099511627776" | find "Win32_LogicalDisk"
) && (
echo Drive found
)
This code just executes the indicated wmic
query (drive d:
and size greater than 1TB) and checks the output with find
command to see if any drive has been found, while hiding the output of any message or error by redirecting standard output stream and error stream to nul
device.
If the output of the wmic
command contains Win32_LogicalDisk
, a matching drive has been found and find
will clear (set to 0
) the errorlevel
. If there is not a matching drive find
will fail and raise the errorlevel
(set to 1
)
The conditional execution operator &&
(execute next command if the previous one did not set errorlevel
) is used to check the find
sucess/failure and determine if diskpart
should be executed.
>nul 2>nul (
wmic logicaldisk where "caption='d:' and size > 1099511627776" | find "Win32_LogicalDisk"
) && (
echo Drive found
)
This code just executes the indicated wmic
query (drive d:
and size greater than 1TB) and checks the output with find
command to see if any drive has been found, while hiding the output of any message or error by redirecting standard output stream and error stream to nul
device.
If the output of the wmic
command contains Win32_LogicalDisk
, a matching drive has been found and find
will clear (set to 0
) the errorlevel
. If there is not a matching drive find
will fail and raise the errorlevel
(set to 1
)
The conditional execution operator &&
(execute next command if the previous one did not set errorlevel
) is used to check the find
sucess/failure and determine if diskpart
should be executed.
answered Nov 13 '18 at 7:01
MC NDMC ND
58.7k54882
58.7k54882
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
add a comment |
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
Quite similar answer with a nice explanation (+1)
– LotPings
Nov 13 '18 at 7:07
1
1
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
@LotPings, maybe it is the most logical approach: let the tools do as much work as they can without additional/unnecessary code. That leads to very similar solutions.
– MC ND
Nov 13 '18 at 7:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273970%2flook-for-volume-d-if-found-and-volume-size-is-greater-than-1tb-run-diskpart-s-f%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown