Enthusiast
Enthusiast

Script to find VM's on datastores that begin with....

Jump to solution

Im looking for a script that will list all the VM's on specific datastores with the beginning letters T1SDX1. I've tried using some one liners I found but they dont seem to work. Here's what I have no but it doesnt list any VM's.

Get-Cluster "Test Cluster" | Get-vm |?{($_.extensiondata.config.datastoreurl|%{$_.name}) -like "T1SDX1"}| Export-Csv "H:\Excel_Reports\vms_on_whatDS.csv"

I've tried to use the -like command and the -contains command. Both show no results. I tried a one liner I found on here, but it reports a TON of data that I dont need, and doesnt even get me the info I need.

Get-Cluster "your_cluster"|Get-vm |?{($_.extensiondata.config.datastoreurl|%{$_.name}) -match "^T"}

0 Kudos
1 Solution

Accepted Solutions
Enthusiast
Enthusiast

I actually found an old script I used that pulled ALL VM's on ALL Datastores. It works, I'll just filter through the spreadsheet.

Here's the script if anyone cares or wants it:

$Today = (Get-Date -Format "yyyyMMdd-HH.mm")

$vcenter = $defaultVIServers

$report = Get-Datacenter | Get-Datastore | Foreach-Object {

    $ds = $_.Name

    $_ | Get-VM | Select-Object Name,@{n='DataStore';e={$ds}} |

    }

$report | Export-Csv "H:\Excel_Reports\DS.stats.$vcenter.$today.csv" -NoTypeInformation -UseCulture

View solution in original post

0 Kudos
1 Reply
Enthusiast
Enthusiast

I actually found an old script I used that pulled ALL VM's on ALL Datastores. It works, I'll just filter through the spreadsheet.

Here's the script if anyone cares or wants it:

$Today = (Get-Date -Format "yyyyMMdd-HH.mm")

$vcenter = $defaultVIServers

$report = Get-Datacenter | Get-Datastore | Foreach-Object {

    $ds = $_.Name

    $_ | Get-VM | Select-Object Name,@{n='DataStore';e={$ds}} |

    }

$report | Export-Csv "H:\Excel_Reports\DS.stats.$vcenter.$today.csv" -NoTypeInformation -UseCulture

View solution in original post

0 Kudos