4 Replies Latest reply on Mar 22, 2017 11:28 AM by LucD

    Get-datastore Command Options

    65cat Lurker

      Hello,

       

      I am creating a script that reports vmdk's living on the service console disk. The service console datastore has a unique suffix of  xxx-xxx-xxx-SC-NORSP.  When I run the command

      Get-datastore | Where {$_.name -like '*sc-norsp*' } | Get-VM |Get-HardDisk |select Filename |Export-Csv c:\LocalVMs.csv -NoTypeInfo, I get back datastores with SC in the name along with the SC-NORSP names.

       

      My question is, how can I query for datastores with the explicit suffix of SC-NORSP ?

       

      Thank you.

        • 1. Re: Get-datastore Command Options
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          With the -match operator you can use a RegEx expression, like this

           

          Get-datastore | Where {$_.name -match "sc-norsp$"} |

          Get-VM |Get-HardDisk |

          select Filename |

          Export-Csv c:\LocalVMs.csv -NoTypeInfo

          • 2. Re: Get-datastore Command Options
            65cat Lurker

            Thank you for the quick reply.  I ran the command and still end up with some unwanted entries.

            [ATC-SVCTEST-0055-PC5-R-TN-RSP]

            [ATC-SVCTEST-0057-PC5-R-TN-RSP]

            [ATC-SVCTEST-0057-PC5-R-TN-RSP]

            [ATC-SVCTEST-0057-PC5-R-TN-RSP]

            This is the naming I would like to report on.

            [xx-xxx-SC-NORSP]

            [xx-xxx-SC-NORSP]

             

            Thanks again for the help.

            • 3. Re: Get-datastore Command Options
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              That's strange.

              Can you run the following, and check which datastore has $true in the Match column?

               

              Get-Datastore |

              Select Name,@{N='Match';E={$_.name -match "sc-norsp$"}}

              • 4. Re: Get-datastore Command Options
                LucD Guru
                Community WarriorsvExpertUser Moderators

                But wait a minute, do you have VMs that are spread over multiple datastores?

                It could be that the VM's VMX is on one of the datastores you are looking for, but that the VMDK of these VM are on other datastores.

                 

                 

                Try like this

                 

                Get-VM | Get-HardDisk |

                where{$_.FileName -match "^\[.*sc-norsp\]"} |

                select Filename |

                Export-Csv c:\LocalVMs.csv -NoTypeInfo