Skip to content

Select-Object works correctly only when a cmdlet is wrapped in parentheses #46

Closed
@avirupch

Description

@avirupch

Context:

StorSimple service contains 4 StorageAccountCredential objects, we are trying to select the first one, and use that to create a new VolumeContainer object.

Failure scenario:

$sacToUse = Get-AzureStorSimpleStorageAccountCredential | Select-Object -First 1 -Wait
$sacToUse | New-AzureStorSimpleDeviceVolumeContainer -DeviceName avirupch_app3 -Name vc_11 -BandWidthRate 256 –WaitForComplete

$sacToUse is a list of all 4 StorageAccountCredential objects instead of only the first one, and when piped to the second cmdlet it results in the latter being called once for each object, that is total 4 times.

Succeess scenario:

$sacToUse2 = (Get-AzureStorSimpleStorageAccountCredential) | Select-Object -First 1 -Wait
$sactoUse2 | New-AzureStorSimpleDeviceVolumeContainer -DeviceName avirupch_app3 -Name vc_12 -BandWidthRate 256 –WaitForComplete

After wrapping the first cmdlet in parentheses, $sacToUse2 now returns only the first object, and thus the second cmdlet is also called once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions