PowerCLI

 View Only
  • 1.  Error in script

    Posted 28 days ago

    Hello,

    I'm trying to create a bulg of datastores.

    # Connect to vCenter Server:
    $credential = Import-Clixml -Path xxxxxx
    Connect-VIServer -Server xxxxxx -Credential $credential

    $CSVFile = "D:\xxxx.csv"
    $Datastores = Import-CSV $CSVFile
    Foreach ($Store in $Datastores) {
    New-Datastore -VMHost "xxxxxx" -Name $Store.DatastoreName -Path $Store.CanonicalName -Vmfs -FileSystemVersion 6
    }

    But there is something wrong:

    New-Datastore : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At D:\xxxxx.ps1:8 char:51
    + ... ore -VMHost "xxxxxx" -Name $($Store.DatastoreName) -Path $ ...
    +                                             ~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [New-Datastore], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.NewDatastore

    When trying this:

    $CSVFile = "D:\xxxxx"
    $Datastores = Import-CSV $CSVFile

    PS C:\Windows\system32> $Datastores

    CanonicalName;DatastoreName                            
    ---------------------------                            
    naa.xxxxxxxxxx;ab_cd_01
    naa.xxxxxxxxxx;ab_cd_02

    i see that there are values for DatastoreName and CanonicalName.

    So why can this values not be used by the script?

    regards

    Andi



  • 2.  RE: Error in script

    Posted 28 days ago

    Hi,

    In your CSV, change all semi-colons to commas.




  • 3.  RE: Error in script

    Posted 28 days ago

    Hi James,

    Thank you so much. It works :-)




  • 4.  RE: Error in script

    Posted 28 days ago

    Instead of updating your CSV, you can also use the Delimiter parameter.

    Import-Csv -Delimiter ';'


    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 5.  RE: Error in script

    Posted 27 days ago

    Hi Luc,

    Thx for your assistence.

    regards

    Andi