Try this:
$Datacenter = Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name | Select-Object -ExpandProperty MoRef
Get-View -ViewType VirtualMachine -Filter @{Name="test"} -Property Name -SearchRoot $Datacenter
Or one-liner:
Get-View -ViewType VirtualMachine -Filter @{Name="test"} -Property Name -SearchRoot $(Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name).MoRef
...Just make sure to add properties or remove the properties parameter altogether from the VirtualMachine Get-View to return all or specific property values.
Specifying properties will greatly improve the query speed.
$Datacenter = (Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name).MoRef
Get-View -ViewType HostSystem -Filter @{Name="test"} -Property Name -SearchRoot $Datacenter