VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Get Advanced Settings for VMs

I have a big list of VMs and they are on different Hosts and managed by differentes vCenter.

I'm trying to create a script in order to get all Advanced Settings in order to correct them based on audit report.

I'm using the below script and it return 0 details:

# vCenter Login

$vCUser="domain\user"

$vCPass="PASSWORD"

# LIST OF vCenter

$vCenterIP = "X.X.X.X"

foreach ($IPAddress in $vCenterIP){

    # Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

$Date = get-date

$Datefile = ( get-date ).ToString("yyyy-MM-dd-hhmmss")

$ErrorActionPreference = "SilentlyContinue"

# Variable to change

$CreateCSV= "yes"

$GridView = "no"

$FileCSV = New-Item -type file "C:\Report\VMWARE_REPORT_$datefile.csv"

$output += ‘<H1>[2017 - Report Monthly Virtual Machine</H1>’

$output += ‘<H2>Date and time</H2>’,$date

Write-Host "Gathering VM statistics"

$report = @()

foreach($vm in Get-View -ViewType Virtualmachine){

Get-VM $server| Get-AdvancedSetting | Select Name, Value

}

#Output

if ($GridView -eq "yes") {

$report | Out-GridView }

if ($CreateCSV -eq "yes") {

$report | Export-Csv $FileCSV -NoTypeInformation }

#file CSV

$filename = "C:\Report\VMWARE_REPORT_$datefile.csv"

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

# vCenter Login

$vCUser="domain\user"

$vCPass="PASSWORD"

# LIST OF vCenter

$vCenterIP = "X.X.X.X"

foreach ($IPAddress in $vCenterIP){

    # Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

$Date = Get-Date

$Datefile = ( Get-Date ).ToString("yyyy-MM-dd-hhmmss")

$ErrorActionPreference = "SilentlyContinue"


# Variable to change

$CreateCSV= "yes"

$GridView = "no"

$FileCSV = New-Item -Type File -Path "C:\Report\VMWARE_REPORT_$datefile.csv"

Write-Host "Gathering VM settings"

$report = Get-VM -PipelineVariable vm | Get-AdvancedSetting |

Select @{N='VM';E={$vm.Name}},Name, Value

#Output

if ($GridView -eq "yes") {

    $report | Out-GridView

}

if ($CreateCSV -eq "yes") {

    $report | Export-Csv -LiteralPath $FileCSV -NoTypeInformation -UseCulture

}

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false


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

View solution in original post

13 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

# vCenter Login

$vCUser="domain\user"

$vCPass="PASSWORD"

# LIST OF vCenter

$vCenterIP = "X.X.X.X"

foreach ($IPAddress in $vCenterIP){

    # Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

$Date = Get-Date

$Datefile = ( Get-Date ).ToString("yyyy-MM-dd-hhmmss")

$ErrorActionPreference = "SilentlyContinue"


# Variable to change

$CreateCSV= "yes"

$GridView = "no"

$FileCSV = New-Item -Type File -Path "C:\Report\VMWARE_REPORT_$datefile.csv"

Write-Host "Gathering VM settings"

$report = Get-VM -PipelineVariable vm | Get-AdvancedSetting |

Select @{N='VM';E={$vm.Name}},Name, Value

#Output

if ($GridView -eq "yes") {

    $report | Out-GridView

}

if ($CreateCSV -eq "yes") {

    $report | Export-Csv -LiteralPath $FileCSV -NoTypeInformation -UseCulture

}

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false


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

SCharchouf
Hot Shot
Hot Shot
Jump to solution

Thank you it's working Smiley Happy

just the CSV obtained when I open it in Excel the first line containe : Column1, Column2, Column3 and the second line contain VM, Name, Value

is there any way to delete the first line?

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Also I would like to have the vCenter IP or name on the report in order to be able to trace everything Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you sure you copied my script correctly?

I see the expected column names in the CSV.

This adds the vCenter to each row

# vCenter Login

$vCUser="domain\user"

$vCPass="PASSWORD"

# LIST OF vCenter

$vCenterIP = "X.X.X.X"

foreach ($IPAddress in $vCenterIP){

    # Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

$Date = Get-Date

$Datefile = ( Get-Date ).ToString("yyyy-MM-dd-hhmmss")

$ErrorActionPreference = "SilentlyContinue"


# Variable to change

$CreateCSV= "yes"

$GridView = "no"

$FileCSV = New-Item -Type File -Path "C:\Report\VMWARE_REPORT_$datefile.csv"

Write-Host "Gathering VM settings"

$report = Get-VM -PipelineVariable vm | Get-AdvancedSetting |

Select @{N='VM';E={$vm.Name}},@{N='vCenter';E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},Name, Value

#Output

if ($GridView -eq "yes") {

    $report | Out-GridView

}

if ($CreateCSV -eq "yes") {

    $report | Export-Csv -LiteralPath $FileCSV -UseCulture

}

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false


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

SCharchouf
Hot Shot
Hot Shot
Jump to solution

Yes I'm sure That I have copied the script you shared.

Now the vce is added and I attached the output

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is the NoTypeInformation switch on the Export-Csv cmdlet.
Change that line to

$report | Export-Csv -LiteralPath $FileCSV -UseCulture -NoTypeInformation


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Thanks LucD, it's much better now but the first line still show Column 1...
I'm checking the reason why it show this details

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you Attach (bottom right) the script as you are running it?


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

#Initialize PowerCLI

#add-pssnapin VMware.VimAutomation.Core

# vCenter Login

$vCUser="domaine\user"

$vCPass="password"

# LIST OF vCenter

$vCenterIP = "X.X.X.X"

foreach ($IPAddress in $vCenterIP){

    # Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

$Date = Get-Date

$Datefile = ( Get-Date ).ToString("yyyy-MM-dd-hhmmss")

$ErrorActionPreference = "SilentlyContinue"

# Variable to change

$CreateCSV= "yes"

$GridView = "no"

$FileCSV = New-Item -Type File -Path "C:\Users\S852547ADM\Desktop\PowerShell_Script\Report\AdvancedSettings_VMs_$datefile.csv"

Write-Host "Gathering VM settings"

$report = Get-VM -PipelineVariable vm | Get-AdvancedSetting |

Select @{N='VM';E={$vm.Name}},@{N='vCenter';E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},Name, Value

#Output

if ($GridView -eq "yes") {

    $report | Out-GridView

}

if ($CreateCSV -eq "yes") {

    $report | Export-Csv -LiteralPath $FileCSV -UseCulture -NoTypeInformation

}

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, but I can't reproduce what you are seeing.

With your script, everything looks ok for me.

csv.png

Are you sure you are looking at the correct file?


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Interesting, I guess the issue is with Excel file when I import it

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try opening the file with Notepad or Notepad++


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

It's Ok when I open the CSV using Notepad++ or if I open it directly in excel but if I import it it add the line

it's fine and thank you for your help

stay safe Smiley Happy

0 Kudos