HPE OneView
1832910 Members
2904 Online
110048 Solutions
New Discussion

Powershell: enable-ovmaintenancemode

 
SOLVED
Go to solution
DanS2
Occasional Contributor

Powershell: enable-ovmaintenancemode

Hello,

I've got some scheduled downtime soon and it looks like OneView still doesn't have a maintenance schedule option, so I thought i'd use Powershell to do this, however i'm stuck.

I can see the option "enable-ovmaintenancemode" but when I press enter it just says InputObject, no idea what that is.  No matter what I type in it says the following

"Enable-OVMaintenanceMode: The specified 'InputObject' is not an object or is missing the 'ApplianceConnection' property. Please correct this value and try again."

What i'm after is something like enable-ovmaintenancemode -servers server1, server2, server3

Can anyone help out?

Thanks

7 REPLIES 7
ChrisLynch
HPE Pro

Re: Powershell: enable-ovmaintenancemode

You need to pass a server object to the Cmdlet.  Using Get-Help Enable-OVMaintenanceMode, you will get the Cmdlet help showing you how to use it.  So, for example, you need to use Get-OVServer first to get the list of servers (or alternatively you can get the Server Profile instead using Get-OVServerProfile):

$Server = Get-OVServer -Name Server
Enable-OVMaintenanceMode -InputObject $Server

# You can also use the PowerShell pipeline
Get-OVServer -Name Server | Enable-OVMaintenanceMode
I work at HPE
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DanS2
Occasional Contributor

Re: Powershell: enable-ovmaintenancemode

Hello,

 

thanks for that that seems to be working; however how do I remove the prompt for confirmation?  I've tried the following

get-ovserver -name servernamehere | enable-ovmaintenancemode -force -confirm:$true

it's saying there isn't a parameter, i'm hoping to have this script created as a scheduled task so needs to run automatically.

Also how can I put in mulitple servers as a list? like servername1,servername2

Thanks

ChrisLynch
HPE Pro

Re: Powershell: enable-ovmaintenancemode

-Confirm:$false is supposed to override the prompt.  -Force isn't a parameter option for Enable-OVMaintenanceMode.

I work at HPE
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DanS2
Occasional Contributor

Re: Powershell: enable-ovmaintenancemode

I’ll be able to test that tomorrow but yes my mistake it should be false not true oops.

Are you able to assist in helping with having multiple servers in the script?

That’s just the final bit I hope, one side of our infrastructure is going down, so I need to be able to have multiple servers go into maintenance mode and not all

Thanks
ChrisLynch
HPE Pro
Solution

Re: Powershell: enable-ovmaintenancemode

One technique you can use is to put these servers into a Scope, then use the Scope resource to get the list of servers.  That way, you don't have to use some naming scheme for server names to figure out how to locate them using Get-OVServer.  For instance:

 

# Get the scope
$Scope = Get-OVScope -Name ServersForMaintenance

# Process scope resources for server hardware, then enable maintenance mode and saving task objects to runtime variable $Tasks
$Scope.Members | ? Type -eq ServerHardware | % { Get-OVServer -Name $_.Name } | Enable-OVMaintenanceMode -OutVariable Tasks

 

Then, you can monitor or view the asynctask(s) status in the $Tasks variable.  Use the Wait-OVTaskComplete Cmdlet to monitor the progression of the async tasks.  By default, all operation-based Cmdlets, like Enable-OVMaintenanceMode, are blocking while it waits for the task to complete.  You can check for Cmdlets that support the -Async parameter switch, which will return the async task object immediately upon being accepted by the appliance.  Then use the Wait-OVTaskComplete to monitor as previously stated.  Keep in mind that the Wait-OVTaskComplete will timeout after 20 minutes.  That does not mean the task failed if the timeout is reached.  You can override it with the -Timeout parameter in Wait-OVTaskComplete.

I work at HPE
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
DanS2
Occasional Contributor

Re: Powershell: enable-ovmaintenancemode

Awesome thank you, thats worked a treat using the scopes, thank you very much

Sunitha_Mod
Honored Contributor

Re: Powershell: enable-ovmaintenancemode

@DanS2 

That's excellent! 

We are extremely glad to know the issue has been resolved and we appreciate you for keeping us posted.