Loop to identify disk units and volumes assigned to disks in CMD or PowerShell / loop para identificar unidades de disco e volumes atribuidos aos discos

Bruno d´Anna 1 Reputation point
2020-06-15T21:18:37.763+00:00

Good night,

I´m having a hard time managing some resources and I´m trying to create scripts to streamline everyday tasks.

one of these tasks is to make the script identify the volumes and disks connected to a specific station called maintenance, in this station the disks are placed in a controller and automatically mapped to a drive letter, after that I need to perform simple maintenance tasks , such as chkdsk, antivirus, defragmentation and last VHD backup of the volume.

my problem is to reconcile the outputs of the get-disk and the get-volume in order to be able to separate the physical disks and their respective volumes, after that it would just be identifying the number of the OS to organize their backup on the server.

I leave an example of what I'm trying to do below:

PS C:\windows\system32> Get-Disk

Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
Style


1 GLOWAY WAR... DA7C14D0440030031235 Healthy Online 223.57 GB GPT
0 WDC WD3200... WD-WMAV2M182177 Healthy Online 298.09 GB MBR
2 Generic ST... [ Healthy No Media 0 B RAW

1 = MY OS DISK
2 = MY FIRST DISK TO TEST
3 = USB CARD READER - NOT USED

PS C:\windows\system32> Get-Volume

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size


                               NTFS           Fixed     Healthy      OK                      1.12 MB    450 MB
  EFI                        NTFS           Fixed     Healthy      OK                    289.27 MB    350 MB

E Elaine - Docs NTFS Fixed Healthy OK 132.66 GB 197.6 GB
D Windows 7 Pro NTFS Fixed Healthy OK 12.87 GB 100.15 GB
G Unknown Removable Healthy Unknown 0 B 0 B
FAT32 Fixed Healthy OK 50.1 MB 95 MB
C NTFS Fixed Healthy OK 59.69 GB 223.02 GB

In this scenario above, I need the script to locate the non-OS disk, as I don't need to perform maintenance on it, and place Disk 2 in a service queue, but only the units related to Disk 2, but I don't know how to do this filter. by powershell

can someone help me in this matter?

the order you intend to execute would be this and the antivirus is Security essentials, the defragmenter is that of Windows itself and the backup is done by disk2vhd.

objective - disk maintenance, backup of the drives in their respective letters, antivirus, defragmentation, store by OS number

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
573 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Sumarigo-MSFT 43,801 Reputation points Microsoft Employee
    2020-06-22T10:37:29.377+00:00

    @Bruno d´Anna Firstly, apologies for the delay in responding here and any inconvenience this issue may have caused.

    Are you still facing issue in the script, If so I would like to work closer on this issue! Could you please reach to me via AZCommunity[AT]microsoft.com with a link to this Issue. Please mention "ATTN subm" in the subject field.

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.

    ---------------------------------------------------------------------------------------------

    Please don’t forget to "Accept the answer" wherever the information provided helps you, this can be beneficial to other community members.


  2. Bruno d´Anna 1 Reputation point
    2020-07-09T13:06:37.593+00:00

    Hello good afternoon,

    We are creating a script to perform some tasks in an automated way, the intention is after the script is ready to leave its code free so that it can assist other technicians.
    How the test process of our company works: When equipment arrives for maintenance, we need to automate the process in order to avoid all or any human manipulation in the customer's hard drive, the manipulation would be just removing the disk and inserting it in a piece of equipment for a disk status checking, backup, defragmentation and antivirus.
    Today we have 3 dedicated devices for this purpose, our intention is that the script can identify the corresponding disks and volumes, after that it will make a list of tasks, such as chkdsk, defragmentation and after that, disk backup and virus scanning.
    My question is when adding more than one disk on the same computer to be able to automatically separate via the power shell or some other tool such as diskpart the volumes linked to that particular disk, because when executing the commands it shows the volumes, but does not show the disks linked, and in this case we need intervention to be able to correctly list the volumes to their corresponding disks and thus continue with the process, which today part is done manually.


  3. Bruno d´Anna 1 Reputation point
    2020-07-22T19:56:33.313+00:00

    without problems, I managed to find a way to list the volume on the disks, using diskpart - list disk -> sel disk x -> detail disk, from the note of the drive of the mapped disks, but have not yet located a way to automate this, I seek some power shell type tool, as soon as I can leave the script complete in this post.
    13372-image.png

    13287-image.png

    in this image i run this script manualy on drives: D and E

    0 comments No comments