VicMware
Contributor
Contributor

Need help with Set-VMHostAdvancedConfiguration

Jump to solution

Hi

For some reason following commands don't work.

Please see the ouput errors.

Any idea why it doesn't work?

$value1 = "[$datastorename] $syslogFoldername/$hostname.log"
$value2 = "[]/scratch/log"

Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "ScratchConfig.ConfiguredScratchLocation" -Value $value1
Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.log.DirUnique" -Value $value2

Set-VMHostAdvancedConfiguration : 25/02/2013 11:55:51 AM    Set-VMHostAdvancedConfiguration
A specified parameter was not correct.

At D:\sm\ScratchFolders\folder.ps1:23 char:33
+     Set-VMHostAdvancedConfiguration <<<<  -VMHost $vmhost -Name "ScratchConfig.ConfiguredScratchL
ocation" -Value $value1
    + CategoryInfo          : NotSpecified: (:) [Set-VMHostAdvancedConfiguration], InvalidArgument
    + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_GetVmHostAdvancedConfiguration_
   ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAdvancedConfiguration

Set-VMHostAdvancedConfiguration : 25/02/2013 11:55:52 AM    Set-VMHostAdvancedConfiguration
'Syslog.global.log.DirUnique' is invalid or exceeds the maximum number of characters permitted.
At D:\sm\ScratchFolders\folder.ps1:25 char:36
+     Set-VMHostAdvancedConfiguration <<<<  -VMHost $vmhost -Name "Syslog.global.log.DirUnique" -Va
lue $value2
    + CategoryInfo          : NotSpecified: (:) [Set-VMHostAdvancedConfiguration], InvalidName
    + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_GetVmHostAdvancedConfiguration_
   ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAdvancedConfiguration

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Afaik the 1st config entry should be ä path in the local filesystem, something like "/vmfs/volumes/...."

See KB1033696.

For the 2nd value the key should be "Syslog.global.logDirUnique"

Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.logDirUnique" -Value $value2


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership

Afaik the 1st config entry should be ä path in the local filesystem, something like "/vmfs/volumes/...."

See KB1033696.

For the 2nd value the key should be "Syslog.global.logDirUnique"

Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.logDirUnique" -Value $value2


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

0 Kudos
VicMware
Contributor
Contributor

Thank you Luc

Will it work if its a path with variables???

$value1 = "/vmfs/volumes/$datastorename/$syslogFoldername"

Thanks

Vickie

0 Kudos
LucD
Leadership
Leadership

That will work with variable names, but make sure the folder exists.

See the Configuring a persistent scratch location using PowerCLI section in the KB I mentioned.


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

0 Kudos
VicMware
Contributor
Contributor

Hi LucD

I need your help with this....following doesn't work because of the variable $datastorename and I can't work out the issue....

Connect-VIServer 'vcenter'

$tempstring = get-datastore
$datastorename = $tempstring -like '*scratch'  #There is a datastore called vcenter12_scratch

New-PSDrive -Name $hostname -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore $datastorename) -Scope global  #Get-Datastore doesn't work

$value1 = "/vmfs/volumes/$datastorename/$syslogFoldername"       #Will this work?

Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "ScratchConfig.ConfiguredScratchLocation" -Value $value1

Thanks for your help

Vickie

0 Kudos
LucD
Leadership
Leadership

Try changing those first two lines into

$datastorename = Get-Datastore | where {$_.Name -like '*scratch'} | Select -ExpandProperty Name


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

0 Kudos
VicMware
Contributor
Contributor

Hi LucD

Thanks for your help so far. I replaced the commands but still getting the same error.

Here is the script:

$datastorename = Get-Datastore | where {$_.Name -like '*scratch'} | Select -ExpandProperty Name


ForEach ($vmhost in Get-VMHost) {

$hostname = $vmhost.name.split(".")[0].ToUpper() 

$syslogFolderName = ".locker-$hostname" 


#Make the local datastore accessible as a PSdrive
New-PSDrive -Name $hostname -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore $datastorename) -Scope global

#Access the new PSDrive
Set-Location $hostname":"

#Create the syslog folder
New-Item $syslogFolderName -ItemType directory

#Set the advanced parameter to configure the syslog on the local datastore
$value1 = "/vmfs/volumes/$datastorename/$syslogFoldername"                  
    $value2 = "[]/scratch/log"
    $value3 = "10.96.132.30:514"
Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "ScratchConfig.ConfiguredScratchLocation" -Value $value1
    Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "ScratchConfig.ConfiguredSwapState" -Value $true
    Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.logDir" -Value $value2
    Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.logHost" -Value $value3

    #Cleanup
Set-Location $PSHOME
Remove-PSDrive $hostname
Clear-Variable hostname -ErrorAction SilentlyContinue
Clear-Variable datastorename -ErrorAction SilentlyContinue
Clear-Variable value -ErrorAction SilentlyContinue
}


Disconnect-VIServer -confirm:$false

0 Kudos
LucD
Leadership
Leadership

What error messages are you getting ? And on which line ?


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

0 Kudos
VicMware
Contributor
Contributor

See attached image.

Third error message is related to this line:

New-PSDrive -Name $hostname -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore $datastorename) -Scope global  

First two error messages are related to :

Set-VMHostAdvancedConfiguration -VMHost $vmhost -Name "Syslog.global.logHost" -Value $value3

0 Kudos
LucD
Leadership
Leadership

It looks like the $datastorename variable is empty.

Does this return anything ?

Get-Datastore | where {$_.Name -like '*scratch'} | Select -ExpandProperty Name


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

0 Kudos
AlexNTTA
Contributor
Contributor

In case anyone stumbles on this thread. When I was trying to set Syslog.global.logDir via PowerCLI, I got this :

'syslog.global.logDir' is invalid or exceeds the maximum number of characters permitted.

The reason is because the "Value" parameter in the Set-VMHostAdvancedConfiguration is of type "object". I kept feeding it a string before I looked more closely. Something like this will work :

> Set-VMHostAdvancedConfiguration -VMHost myesxhost -Name "Syslog.global.logDir" -Value ( [string] "[hostname-local] /log" )

I had no easy way of making an object variable with my custom naming convention, so I came up with the above when I saw VMware's example :

> Get-VMHost 10.23.123.144 | Set-VmHostAdvancedConfiguration -Name Migrate.NetTimeout -Value ( [system.int32] 10 )

Evil in some regards. Smiley Happy Hope this helps someone.

-Alex

0 Kudos