alphenit
Enthusiast
Enthusiast

WARNING: Parameter 'VMHost' is obsolete. This parameter no longer accepts multiple values. WARNING: Parameter 'Principal' is obsolete

Jump to solution

After an upgrade from powercli 6.3. to 6.5.1 some parts of my script to configure an ESXi host have been showing warnings that I haven't seen before.
The iscsi-binding of 2 vmk ports completely broke but I will ask about this in a different subject if I can't fix it that myself.


question: What do I need to change in the syntax to get rid of the warnings?

The first snippit:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -Confirm:$false | out-null

Write-Host "add local user to readonly role" -foregroundcolor green

New-VIPermission -Principal testuser -Role " readonly " -Propagate:$true -Entity $vmhostname | Out-Null

Write-Host "Done"

Write-Host ""


The snippit still works but gives this warning:
WARNING: Parameter 'Principal' is obsolete. This parameter no longer accepts multiple values.

WARNING: Parameter 'Entity' is obsolete. This parameter no longer accepts multiple values


Another snippit:

Write-Host "Connect NFS Datastores" -foregroundcolor green

foreach ($datastore in (Get-cluster $cluster | Get-Datastore | where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"})){

New-Datastore -vmhost $vmhostname -Nfs -Name $datastore.Name -Path $datastore.RemotePath -NfsHost $datastore.RemoteHost | Out-Null

}

Write-Host "Done"

Write-Host ""


The snippit still works but gives this warning:

WARNING: Parameter 'VMHost' is obsolete. This parameter no longer accepts multiple values.


PowerCLI Version

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

   VMware PowerCLI 6.5 Release 1 build 4624819

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

Component Versions

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

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

   VMware Vds PowerCLI Component 6.5 build 4624695

   VMware Cloud PowerCLI Component 6.5 build 4624821

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware HorizonView PowerCLI Component 7.0.2 build 4596620

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware PCloud PowerCLI Component 6.5 build 4624825

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware vROps PowerCLI Component 6.5 build 4624824

   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

Powercli config:

pastedImage_1.png


Powercli helptext:

NAME

    New-Datastore

SYNOPSIS

    This cmdlet creates a new datastore.

    --------------  Example 1 --------------

    C:\PS>New-Datastore -VMHost $vmhost -Name Datastore -Path $scsiLun.CanonicalName -Vmfs -FileSystemVersion 3

    Creates a VMFS datastore by specifying the file system type.

    --------------  Example 2 --------------

    C:\PS>New-Datastore -Nfs -VMHost 10.23.112.60 -Name NFSDatastore -Path /mynfs -NfsHost 10.23.84.73

NAME

    New-VIPermission

SYNOPSIS

    This cmdlet creates new permissions on the specified inventory objects for the provided users and groups in the role.

    --------------  Example 1 --------------

    C:\PS>New-VIRole -Name Role -Server $server -Privilege (Get-VIPrivilege -PrivilegeGroup)

    $permission = New-VIPermission -Role Role -Principal Administrator -Entity (Get-Datacenter)

    Creates a permission on the provided server for a role with the specified privileges.

*Please consider awarding points if my response was helpful*
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You can only pass a single value to the VMHost and Principal parameter.

For example, in

New-Datastore -vmhost $vmhostname -Nfs -Name $datastore.Name -Path $datastore.RemotePath -NfsHost $datastore.RemoteHost

You have to make sure that $vmhostName holds a single value ('MyEsx'), and ot an array ('MyEsx1','MyEsx2')

No, I mean a second run of the script in the sam ePowerCLI session

Strange, when it says $false, you shouldn't be getting the depreciation warning.

Unless perhaps it is only for the 1st time PowerCLI encounters a line with a cmdlet that has a depreciation warning.

Hence my previous question.


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

View solution in original post

0 Kudos
18 Replies
LucD
Leadership
Leadership

These messages are what they say they are, warnings.

Since you are using a somehwat older version (6.5 R1), you can still use multi-values for VMHost and Principal.

In more recent versions, you can't, both parameters only accept scalar values.

Your PowerCLI Configuration seems to be configured correctly to suppress  these deprecation warnings ($false in all scopes).

Do you you always get the warnings, or only on the first time you used the cmdlet?
When you start a new PowerCLI session, is the Configuration still saying $false?

I would also advise to go for a more recent version, in fact a version that comes from the PowerShell Gallery, and that is not installed through a MSI.

Provided of course that your vSphere version is supported.


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

0 Kudos
alphenit
Enthusiast
Enthusiast

Hi Luc,
We are still running version 5.5 so  we should be able to go the latest if this still holds true:
VMware Product Interoperability Matrices

(But I'm even thinking about asking that we go back to 6.3)

Some questions:
In more recent versions, you can't, both parameters only accept scalar values
Can you please explain what you mean by this? (maybe through the snippit i showed what will need to be changed in newer versions? 10.x for example ))

Do you you always get the warnings, or only on the first time you used the cmdlet?

I rerun the script if I have to do multiple hosts but I always start with a clean powershell session to to be sure. And yes the warnings always pop-up

When you start a new PowerCLI session, is the Configuration still saying $false?
I checked, everything is screaming false...only in practice it's not it would seem.

*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

You can only pass a single value to the VMHost and Principal parameter.

For example, in

New-Datastore -vmhost $vmhostname -Nfs -Name $datastore.Name -Path $datastore.RemotePath -NfsHost $datastore.RemoteHost

You have to make sure that $vmhostName holds a single value ('MyEsx'), and ot an array ('MyEsx1','MyEsx2')

No, I mean a second run of the script in the sam ePowerCLI session

Strange, when it says $false, you shouldn't be getting the depreciation warning.

Unless perhaps it is only for the 1st time PowerCLI encounters a line with a cmdlet that has a depreciation warning.

Hence my previous question.


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

View solution in original post

0 Kudos
alphenit
Enthusiast
Enthusiast

No, I mean a second run of the script in the sam ePowerCLI session

Strange, when it says $false, you shouldn't be getting the depreciation warning.

Unless perhaps it is only for the 1st time PowerCLI encounters a line with a cmdlet that has a depreciation warning.

Hence my previous question.

I've run the script twice today in the same session and both times the same warnings came up.

Maybe a bug within that specific release?

*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

Could be, and I'm afraid I can't test/verify (I'm really not going to do a MSI install anymore :smileygrin:).


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

0 Kudos
beckylelliott
Contributor
Contributor

Luc--

With vmhost, vm and some other parameters no longer accepting multiple values, is there a preferred way to get the same functionality other than a for-each loop?  

Thanks! 

0 Kudos
LucD
Leadership
Leadership

The pipeline should be the preferred way to do this, provided the parameter accepts pipeline input.

In the New-Datastore the VMHost parameter for example accepts pipeline input.

pipeline.png

So my preferred way would be

Get-VMHost | New-Datastore -Name Test -Path $canonicalName -VMFS

If a parameter doesn't accept pipeline input, then the ForEach-Object cmdlet is the next preferred method.

Get-VMHost | ForEach-Object -Process {New-Datastore -VMHost $_ -Path $canonicalName -VMFS}

And ultimately the foreach statement (which is not the same as the ForEach-Object) can be used.

But be aware that this one breaks the pipeline!

foreach($esx in Get-VMHost){

   New-Datastore -VMHost $esx -Path $canonicalName -VMFS

}


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

0 Kudos
beckylelliott
Contributor
Contributor

Great!  Thanks, Luc!   I've never used the ForEach-object commandlet.   Going to start playing with that.   

I've been ignoring ,mulitple value depreciation warnings for awhile.  However, someone recently asked me to show them how to do some tasks using PowerCLI.  I feel like in good conscience, I can't tell them just to ignore the depreciation warnings. 

0 Kudos
alphenit
Enthusiast
Enthusiast
Hi Luc,
We are now on esxi 6.5 and this snippet is really no longer working:

Write-Host "Connect NFS Datastores" -foregroundcolor green

foreach ($datastore in (Get-cluster $cluster | Get-Datastore | where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"})){

New-Datastore -vmhost $vmhostname -Nfs -Name $datastore.Name -Path $datastore.RemotePath -NfsHost $datastore.RemoteHost | Out-Null

}

Write-Host "Done"

Write-Host ""
I really need to connect all NFS datastore from a cluster to the new hosts but I can't seem to get it working with the for-each object. Can you please show me how to acomplish this?

*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

Do you get an error?


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

0 Kudos
alphenit
Enthusiast
Enthusiast
yeah, when I run it, This errors pops up for all the datastores:

New-Datastore : Cannot validate argument on parameter 'NfsHost'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At C:\users\user\Documents\Scripts\VMWare\config_esxi\org-datastore-snippet.ps1:6 char:99

+ ... me -Path $datastore.RemotePath -NfsHost $datastore.RemoteHost | Out-N ...

+                                             ~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [New-Datastore], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.NewDatastore
*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

Can you check if the properties are available?

Run this

Get-cluster $cluster | Get-Datastore |

where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"} |

Select Name,RemoteHost,RemotePath


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

0 Kudos
alphenit
Enthusiast
Enthusiast
Hmm, you are on to somthing. name and remotepath are available, remotehost is empty...
*Please consider awarding points if my response was helpful*
0 Kudos
alphenit
Enthusiast
Enthusiast
Just ran the command against a 5.5 vcenter and there all fields are available.
*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

Which PowerCLI version are you currently using?


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

0 Kudos
alphenit
Enthusiast
Enthusiast

Sorry for the late response, kept getting "Portlet is temporarily unavailable errors" on the forum:
Tested it on 2 machines with these versions
VMware PowerCLI 6.5 Release 1 build 4624819
VMware PowerCLI 11.0.0 build 10380590
vCenter 6.5.0.9451637

Also saw this thread:
https://communities.vmware.com/message/2579931#2579931

So also tried:
get-datastore | select name, @{N="RemoteHostName";E={$_.ExtensionData.info.nas.remotehostnames}}
and
$rhn = get-view -viewtype datastore
$rhn | select Name, @{N="RemoteHostName";E={$rhn.info.nas.remotehostnames[0]}} | fl

But everywhere, remotehostname is empty.

*Please consider awarding points if my response was helpful*
0 Kudos
LucD
Leadership
Leadership

Did you try with RemoteHost?

Get-cluster $cluster | Get-Datastore |

where {$_.Type -eq "nfs" -and $_.Accessible -eq "true"} |

Select Name,RemotePath,

    @{N='RemoteHost';E={$_.ExtensionData.Info.Nas.RemoteHost}}

   


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

0 Kudos
alphenit
Enthusiast
Enthusiast

You are a true hero LucD!
remote host data is being shown and datastores are being mapped.

You Sir....,Rock!

*Please consider awarding points if my response was helpful*
0 Kudos