How to parse the .txt file and know that there is no letter assigned to the volume listedAnother grep / awk q, parsing diskpart outputHow to get the actual size-on-disk of a file from PowerShell?find disk signature from wmi for a volume?SQL agent job calling powershell script with “PSExe \server diskpart /s filename” hangs and never completeFind the volume letter of EFI partitionHow to convert text table to HTML table in powershellWindows Volume without a PartitionHow to process out put of diskpart command using PowerShellMount-WindowsImage IssueGetting Volume by Path using PowerShell

st_isvalid and duplicate vertex

Why would an AC motor heavily shake when driven with certain frequencies?

antimatter annihilation in stars

Would scoring well on a non-required GRE Mathematics Subject Test make me more competitive?

Schrodinger's Cat Isn't Meant To Be Taken Seriously, Right?

What is the purpose of the rotating plate in front of the lock?

The Green Glass Door, Revisited

Did "Dirty Harry" feel lucky?

Bashrc file opens up continuously

What happens when a file that is 100% paged in to the page cache gets modified by another process

When does order matter in probability?

What is the delta-v required to get a mass in Earth orbit into the sun using a SINGLE transfer?

How can faith be maintained in a world of living gods?

How do English-speaking kids loudly request something?

If every star in the universe except the Sun were destroyed, would we die?

Is a MySQL database a viable alternative to LDAP?

Supervisor wants me to support a diploma-thesis SW tool after I graduated

Could someone please explain what this inline #define assembly is doing?

Why is infinite intersection "towards infinity" an empty set?

Why did Tony's Arc Reactor do this?

Poor management handling of recent sickness and how to approach my return?

Why is Sojdlg123aljg a common password?

What precisely does the commonly reported network hash rate refer to?

Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?



How to parse the .txt file and know that there is no letter assigned to the volume listed


Another grep / awk q, parsing diskpart outputHow to get the actual size-on-disk of a file from PowerShell?find disk signature from wmi for a volume?SQL agent job calling powershell script with “PSExe \server diskpart /s filename” hangs and never completeFind the volume letter of EFI partitionHow to convert text table to HTML table in powershellWindows Volume without a PartitionHow to process out put of diskpart command using PowerShellMount-WindowsImage IssueGetting Volume by Path using PowerShell






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a text file which has contents listed due to commands



select disk 0,
select partition 1,
detail partition


enter image description here



Is there a way I can script using PowerShell/Batch that can tell me there is no Letter (Ltr) assigned to volume 4. It should say that "no letter is assigned for this Volume 4".



Note: I have tried already the below way, but I think it's not good way of getting the result.



Get-Content .test.txt
$test.GetType() | Format-Table -AutoSize
$x = $test[21][15]
if ($x -eq $null)
Write-Output "No letter assigned. Retrying to Generate a New letter"










share|improve this question


























  • Do you want powershell or batch to do this?

    – Gerhard Barnard
    Mar 28 at 6:55











  • I would prefer powershell to do this

    – Akash P
    Mar 28 at 6:56






  • 1





    gone now. Let me see If I can code it for him

    – Ranadip Dutta
    Mar 28 at 6:57






  • 1





    Please don't post pictures of text but the text itself - sanitized if necessary.

    – LotPings
    Mar 28 at 7:07











  • Related.

    – Ansgar Wiechers
    Mar 28 at 10:04

















0















I have a text file which has contents listed due to commands



select disk 0,
select partition 1,
detail partition


enter image description here



Is there a way I can script using PowerShell/Batch that can tell me there is no Letter (Ltr) assigned to volume 4. It should say that "no letter is assigned for this Volume 4".



Note: I have tried already the below way, but I think it's not good way of getting the result.



Get-Content .test.txt
$test.GetType() | Format-Table -AutoSize
$x = $test[21][15]
if ($x -eq $null)
Write-Output "No letter assigned. Retrying to Generate a New letter"










share|improve this question


























  • Do you want powershell or batch to do this?

    – Gerhard Barnard
    Mar 28 at 6:55











  • I would prefer powershell to do this

    – Akash P
    Mar 28 at 6:56






  • 1





    gone now. Let me see If I can code it for him

    – Ranadip Dutta
    Mar 28 at 6:57






  • 1





    Please don't post pictures of text but the text itself - sanitized if necessary.

    – LotPings
    Mar 28 at 7:07











  • Related.

    – Ansgar Wiechers
    Mar 28 at 10:04













0












0








0








I have a text file which has contents listed due to commands



select disk 0,
select partition 1,
detail partition


enter image description here



Is there a way I can script using PowerShell/Batch that can tell me there is no Letter (Ltr) assigned to volume 4. It should say that "no letter is assigned for this Volume 4".



Note: I have tried already the below way, but I think it's not good way of getting the result.



Get-Content .test.txt
$test.GetType() | Format-Table -AutoSize
$x = $test[21][15]
if ($x -eq $null)
Write-Output "No letter assigned. Retrying to Generate a New letter"










share|improve this question
















I have a text file which has contents listed due to commands



select disk 0,
select partition 1,
detail partition


enter image description here



Is there a way I can script using PowerShell/Batch that can tell me there is no Letter (Ltr) assigned to volume 4. It should say that "no letter is assigned for this Volume 4".



Note: I have tried already the below way, but I think it's not good way of getting the result.



Get-Content .test.txt
$test.GetType() | Format-Table -AutoSize
$x = $test[21][15]
if ($x -eq $null)
Write-Output "No letter assigned. Retrying to Generate a New letter"







powershell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:02









Ansgar Wiechers

154k15 gold badges144 silver badges206 bronze badges




154k15 gold badges144 silver badges206 bronze badges










asked Mar 28 at 6:45









Akash PAkash P

64 bronze badges




64 bronze badges















  • Do you want powershell or batch to do this?

    – Gerhard Barnard
    Mar 28 at 6:55











  • I would prefer powershell to do this

    – Akash P
    Mar 28 at 6:56






  • 1





    gone now. Let me see If I can code it for him

    – Ranadip Dutta
    Mar 28 at 6:57






  • 1





    Please don't post pictures of text but the text itself - sanitized if necessary.

    – LotPings
    Mar 28 at 7:07











  • Related.

    – Ansgar Wiechers
    Mar 28 at 10:04

















  • Do you want powershell or batch to do this?

    – Gerhard Barnard
    Mar 28 at 6:55











  • I would prefer powershell to do this

    – Akash P
    Mar 28 at 6:56






  • 1





    gone now. Let me see If I can code it for him

    – Ranadip Dutta
    Mar 28 at 6:57






  • 1





    Please don't post pictures of text but the text itself - sanitized if necessary.

    – LotPings
    Mar 28 at 7:07











  • Related.

    – Ansgar Wiechers
    Mar 28 at 10:04
















Do you want powershell or batch to do this?

– Gerhard Barnard
Mar 28 at 6:55





Do you want powershell or batch to do this?

– Gerhard Barnard
Mar 28 at 6:55













I would prefer powershell to do this

– Akash P
Mar 28 at 6:56





I would prefer powershell to do this

– Akash P
Mar 28 at 6:56




1




1





gone now. Let me see If I can code it for him

– Ranadip Dutta
Mar 28 at 6:57





gone now. Let me see If I can code it for him

– Ranadip Dutta
Mar 28 at 6:57




1




1





Please don't post pictures of text but the text itself - sanitized if necessary.

– LotPings
Mar 28 at 7:07





Please don't post pictures of text but the text itself - sanitized if necessary.

– LotPings
Mar 28 at 7:07













Related.

– Ansgar Wiechers
Mar 28 at 10:04





Related.

– Ansgar Wiechers
Mar 28 at 10:04












1 Answer
1






active

oldest

votes


















2
















Don't mess around with a text file - just query the partitions directly in PowerShell.



$nodriveletter = Get-partition | where (-not $_.driveletter) -and $_.type -ne "Reserved" |select disknumber,partitionnumber

$nodriveletter

disknumber partitionnumber
---------- ---------------
3 2


You can then do a Foreach on the results to process any unconfigured partition.



If you want to know what letters are already in use, get all the partition information and extract the results you want after.



$Partitions = Get-partition | where $_.type -ne "Reserved" 
$noDriveLetter = $partitions | where -not $_.driveletter | select disknumber,partitionnumber
$driveletters = $partitions.driveletter #grabs all driveletters in use





share|improve this answer



























  • This answer is precise.

    – Ranadip Dutta
    Mar 28 at 7:16











  • As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

    – Akash P
    Mar 28 at 7:28











  • Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

    – Akash P
    Mar 28 at 7:33












  • I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

    – Trix
    Mar 28 at 7:33












  • Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

    – Akash P
    Mar 29 at 9:43











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/4.0/"u003ecc by-sa 4.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
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391625%2fhow-to-parse-the-txt-file-and-know-that-there-is-no-letter-assigned-to-the-volu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2
















Don't mess around with a text file - just query the partitions directly in PowerShell.



$nodriveletter = Get-partition | where (-not $_.driveletter) -and $_.type -ne "Reserved" |select disknumber,partitionnumber

$nodriveletter

disknumber partitionnumber
---------- ---------------
3 2


You can then do a Foreach on the results to process any unconfigured partition.



If you want to know what letters are already in use, get all the partition information and extract the results you want after.



$Partitions = Get-partition | where $_.type -ne "Reserved" 
$noDriveLetter = $partitions | where -not $_.driveletter | select disknumber,partitionnumber
$driveletters = $partitions.driveletter #grabs all driveletters in use





share|improve this answer



























  • This answer is precise.

    – Ranadip Dutta
    Mar 28 at 7:16











  • As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

    – Akash P
    Mar 28 at 7:28











  • Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

    – Akash P
    Mar 28 at 7:33












  • I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

    – Trix
    Mar 28 at 7:33












  • Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

    – Akash P
    Mar 29 at 9:43
















2
















Don't mess around with a text file - just query the partitions directly in PowerShell.



$nodriveletter = Get-partition | where (-not $_.driveletter) -and $_.type -ne "Reserved" |select disknumber,partitionnumber

$nodriveletter

disknumber partitionnumber
---------- ---------------
3 2


You can then do a Foreach on the results to process any unconfigured partition.



If you want to know what letters are already in use, get all the partition information and extract the results you want after.



$Partitions = Get-partition | where $_.type -ne "Reserved" 
$noDriveLetter = $partitions | where -not $_.driveletter | select disknumber,partitionnumber
$driveletters = $partitions.driveletter #grabs all driveletters in use





share|improve this answer



























  • This answer is precise.

    – Ranadip Dutta
    Mar 28 at 7:16











  • As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

    – Akash P
    Mar 28 at 7:28











  • Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

    – Akash P
    Mar 28 at 7:33












  • I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

    – Trix
    Mar 28 at 7:33












  • Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

    – Akash P
    Mar 29 at 9:43














2














2










2









Don't mess around with a text file - just query the partitions directly in PowerShell.



$nodriveletter = Get-partition | where (-not $_.driveletter) -and $_.type -ne "Reserved" |select disknumber,partitionnumber

$nodriveletter

disknumber partitionnumber
---------- ---------------
3 2


You can then do a Foreach on the results to process any unconfigured partition.



If you want to know what letters are already in use, get all the partition information and extract the results you want after.



$Partitions = Get-partition | where $_.type -ne "Reserved" 
$noDriveLetter = $partitions | where -not $_.driveletter | select disknumber,partitionnumber
$driveletters = $partitions.driveletter #grabs all driveletters in use





share|improve this answer















Don't mess around with a text file - just query the partitions directly in PowerShell.



$nodriveletter = Get-partition | where (-not $_.driveletter) -and $_.type -ne "Reserved" |select disknumber,partitionnumber

$nodriveletter

disknumber partitionnumber
---------- ---------------
3 2


You can then do a Foreach on the results to process any unconfigured partition.



If you want to know what letters are already in use, get all the partition information and extract the results you want after.



$Partitions = Get-partition | where $_.type -ne "Reserved" 
$noDriveLetter = $partitions | where -not $_.driveletter | select disknumber,partitionnumber
$driveletters = $partitions.driveletter #grabs all driveletters in use






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 7:18

























answered Mar 28 at 7:09









TrixTrix

5382 silver badges14 bronze badges




5382 silver badges14 bronze badges















  • This answer is precise.

    – Ranadip Dutta
    Mar 28 at 7:16











  • As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

    – Akash P
    Mar 28 at 7:28











  • Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

    – Akash P
    Mar 28 at 7:33












  • I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

    – Trix
    Mar 28 at 7:33












  • Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

    – Akash P
    Mar 29 at 9:43


















  • This answer is precise.

    – Ranadip Dutta
    Mar 28 at 7:16











  • As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

    – Akash P
    Mar 28 at 7:28











  • Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

    – Akash P
    Mar 28 at 7:33












  • I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

    – Trix
    Mar 28 at 7:33












  • Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

    – Akash P
    Mar 29 at 9:43

















This answer is precise.

– Ranadip Dutta
Mar 28 at 7:16





This answer is precise.

– Ranadip Dutta
Mar 28 at 7:16













As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

– Akash P
Mar 28 at 7:28





As i only want to query volume labels under Disk 0,partition 1 ,then how do i set the disknumber to 0 and paritionnumber to 1.

– Akash P
Mar 28 at 7:28













Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

– Akash P
Mar 28 at 7:33






Above code is giving me results which includes C and D drive. Its like --> null,null,C,D, null .Basically i am using diskpart to mount a vhdx file hence i do select vhdx/disk 0 , select partition 1 and followed by detail partition.

– Akash P
Mar 28 at 7:33














I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

– Trix
Mar 28 at 7:33






I suggest you do Get-Partition | fl to look at the properties you can inspect in this cmdlet (it's really getting the data out of WMI). In this instance, you could make the Where clause $_.type -ne "Reserved" -and $_.disknumber -eq 0. Since I don't know your hardware, you will have to experiment.

– Trix
Mar 28 at 7:33














Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

– Akash P
Mar 29 at 9:43






Tried above script with local drives and works perfectly fine. However as i am working with vhdx file to mount the virtual disk, how do i select that virtual disk using PS ? I mean first i want to select the vdisk (not attach) then execute above logic

– Akash P
Mar 29 at 9:43









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391625%2fhow-to-parse-the-txt-file-and-know-that-there-is-no-letter-assigned-to-the-volu%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현