Hi
We had a power outaged yesterday on one of our DC. Unfortunately, all VMs network adapters appeared to be off/unchecked its network device status, and we done checking it one by one just to be sure.
Am asking if there will be one powercli script that will do the things:
1. Get the cluster name
2. Get VMs with unchecked network adapter {Set-NetworkAdapter -Connected:$
false}
3. Set the VMs network adapter connected
4. Extract a report to csv.
this will be a big help.
here are some one liner cli.
-------------------------------------------------------------------------------
Disconnect Network Adapter on Virtual Machine
| Get-VM -Name $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$ false |
Connect Network Adapter on Virtual Machine
| Get-VM -Name $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$ true |
Check Network Adapters Connection State on VMs
| Get-VM | Get-NetworkAdapter | Select-Object Parent,ConnectionState |
To limit this to a specific cluster you could do
$clusterName = Read-Host -Prompt "Cluster name"
$cluster = Get-Cluster -Name $clusterName
$nics = Get-VM -Location $cluster | Get-NetworkAdapter | where {!$_.ConnectionState.Connected} $nics | Set-NetworkAdapter -Connected:$true -Confirm:$false
$nics | Select @{N="VM";E={$_.Parent.Name}},Name |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
And for a specific folder you could do
$folderName = Read-Host -Prompt "Folder name"
$folder = Get-Folder -Name $folderName $nics = Get-VM -Location $folder | Get-NetworkAdapter | where {!$_.ConnectionState.Connected} $nics | Set-NetworkAdapter -Connected:$true -Confirm:$false $nics | Select @{N="VM";E={$_.Parent.Name}},Name |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
The concept si each time the same, you limit the Get-VM by using the Location parameter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think you already have most of the code.
The following will connect the unconnected NICs and produce a report to a CSV file.
$nics = Get-VM | Get-NetworkAdapter | where {!$_.ConnectionState.Connected} $nics | Set-NetworkAdapter -Connected:$false -Confirm:$false $nics | Select @{N="VM";E={$_.Parent.Name}},Name |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Should that work in a specific cluster or folder?
To limit this to a specific cluster you could do
$clusterName = Read-Host -Prompt "Cluster name"
$cluster = Get-Cluster -Name $clusterName
$nics = Get-VM -Location $cluster | Get-NetworkAdapter | where {!$_.ConnectionState.Connected} $nics | Set-NetworkAdapter -Connected:$true -Confirm:$false
$nics | Select @{N="VM";E={$_.Parent.Name}},Name |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
And for a specific folder you could do
$folderName = Read-Host -Prompt "Folder name"
$folder = Get-Folder -Name $folderName $nics = Get-VM -Location $folder | Get-NetworkAdapter | where {!$_.ConnectionState.Connected} $nics | Set-NetworkAdapter -Connected:$true -Confirm:$false $nics | Select @{N="VM";E={$_.Parent.Name}},Name |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
The concept si each time the same, you limit the Get-VM by using the Location parameter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
On this command shouldn't it be set to $true?
$nics | Set-NetworkAdapter -Connected:$false -Confirm:$false
$nics | Set-NetworkAdapter -Connected:$true -Confirm:$false
Indeed, it should. I corrected it
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah... great you two.
It's working..... thanks.