IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Afficher le type du disque dur (SSd ou HDD)


Sujet :

Scripts/Batch

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2020
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2020
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Afficher le type du disque dur (SSd ou HDD)
    Bonjour,
    je suis débutant en powershell et j'ai un petit souci.

    J'aurais bien voulu afficher le type du disque dur (SSd ou HDD) je sais qu'on peut le voir ave Get-PhysicalDisk et bien sur que celui-ci corresponde au bon disque
    pour ma part j'ai utilisé cette méthode :

    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    function fnLSDISK {
     
            $ListeDisk=(Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType = '3'" | Select-Object Size | Select-Object -ExpandProperty Size)
            $ListeDiskNbLines=(echo $ListeDisk | Measure-Object -Line |Select-Object -ExpandProperty Lines)
     
            for ($y=1 ; $y -le $ListeDiskNbLines ; $y++ )
            {
                $Size=($ListeDisk |Select-Object -First $y |Select-Object -Last 1)
                $Size=($Size /(1GB)).Tostring(".00")
                echo "DiskTaille.$y $(fnD) $Size"
            }  
    }


    DiskTaille.1 : 237,21
    DiskTaille.2 : 931,51

    Merci bien pour vos réponse

    Cdt

    Quentin Giraud

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    Voici un script complet trouvé dans le net :
    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    cls
    $maxLineLength  = 79  # counted from the longest line in your example
    $maxValueLength = 0   # a counter to keep track of the largest value length in characters
     
    $info_diskdrive_basic = Get-WmiObject Win32_DiskDrive | ForEach-Object {
        $disk = $_
        $partitions = "ASSOCIATORS OF " + "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " + "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
        Get-WmiObject -Query $partitions | ForEach-Object {
            $partition = $_
            $drives = "ASSOCIATORS OF " + "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " + "WHERE AssocClass = Win32_LogicalDiskToPartition"
            Get-WmiObject -Query $drives | ForEach-Object {
                $obj = [PSCustomObject]@{
                    'Disk'         = $disk.DeviceID
                    'Disk Model'   = $disk.Model
                    'Partition'    = $partition.Name
                    'Raw Size'     = '{0:d} GB' -f [int]($partition.Size/1GB)
                    'Drive Letter' = $_.DeviceID
                    'Volume Name'  = $_.VolumeName
                    'Size'         = '{0:d} GB' -f [int]($_.Size/1GB)
                    'Free Space'   = '{0:d} GB' -f [int]($_.FreeSpace/1GB)
                    'MediaType'    = $disk.MediaType
                }
                # get the maximum length for all values
                $len = ($obj.PsObject.Properties.Value.ToString().Trim() | Measure-Object -Property Length -Maximum).Maximum
                $maxValueLength = [Math]::Max($maxValueLength, $len)
     
                # output the object to be collected in $info_diskdrive_basic
                $obj
            }
        }
    }
     
    # sort the returned array of objects on the DriveLetter property and loop through
    $result = $info_diskdrive_basic | Sort-Object DriveLetter | ForEach-Object {
        # loop through all the properties and calculate the padding needed for the output
        $_.PsObject.Properties | ForEach-Object {
            $label   = '# {0}:' -f $_.Name.Trim()
            $padding = $maxLineLength - $maxValueLength - $label.Length
            # output a formatted line
            "{0}{1,-$padding}{2}" -f $label, '', $_.Value.ToString().Trim()
        }
        # add a separator line between the disks
        ''
    }
     
    # output the result on screen
    $result
     
    # write to disk
    #$result | Set-Content -Path 'X:\theResult.txt'
     
    # format for HTML mail:
    #'<pre>{0}</pre>' -f ($result -join '<br>')

  3. #3
    Nouveau Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2020
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2020
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Merci bien ! :)
    Merci beaucoup pour votre réponse, dans les faits j'aimerais arriver à un résultat comme celui-ci (où le taille est suivie du type, en gros avoir ces deux informations sur une seule ligne) voici mon code actuel :


    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    function fnLSDISK {
     
            $ListeDisk=(Get-PhysicalDisk | Select-Object Size | Select-Object -ExpandProperty Size)
            $ListeDiskNbLines=(echo $ListeDisk | Measure-Object -Line |Select-Object -ExpandProperty Lines)
     
            for ($y=1 ; $y -le $ListeDiskNbLines ; $y++ )
            {
                $Size=($ListeDisk |Select-Object -First $y |Select-Object -Last 1)
                $Size=($Size /(1GB)).Tostring(".00")
                echo "DiskTaille.$y $(fnD) $Size"
            }  
    }
     
    function fnTYPE {
     
            $ListeType=(Get-PhysicalDisk | Select-Object Mediatype | Select-Object -ExpandProperty Mediatype)
            $ListeDiskNbLines=(echo $ListeType | Measure-Object -Line |Select-Object -ExpandProperty Lines)
     
            for ($y=1 ; $y -le $ListeDiskNbLines ; $y++ )
            {
                $Type=($ListeType |Select-Object -First $y |Select-Object -Last 1)
                echo "DiskType.$y $(fnD) $type"
            }  
    }


    DiskType.1 : HDD
    DiskType.2 : SSD
    DiskTaille.1 : 931,51
    DiskTaille.2 : 238,47



    Cdt


    CandyB

  4. #4
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 184
    Points : 5 755
    Points
    5 755
    Par défaut
    Get-PhysicalDisk c'est bien
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    Get-PhysicalDisk | Select-Object @{Name="Type";Expression={$_.MediaType}}, @{Name="Size";Expression={($_.Size/1GB).Tostring(".00")}}

Discussions similaires

  1. [PowerShell] besoin d'aide Powershell
    Par davidjo_20165 dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 25/07/2018, 10h27
  2. [PowerShell] besoin d'aide script Powershel
    Par samirCA007 dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 01/02/2018, 10h49
  3. [PowerShell] besoin d'aide code powershel
    Par thierryinfo2012 dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 28/01/2018, 10h38
  4. [TP]besoin d'aide pour commandes inconnues
    Par Upal dans le forum Turbo Pascal
    Réponses: 15
    Dernier message: 03/10/2002, 10h48
  5. Besoin d'aide pour l'I.A. d'un puissance 4
    Par Anonymous dans le forum C
    Réponses: 2
    Dernier message: 25/04/2002, 17h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo