VMware Cloud Community
BBB36
Enthusiast
Enthusiast
Jump to solution

Generate CSV syslog report with headings

I'm trying to get this script to connect to multiple vCenter servers to collect all syslog server and port information and generate a CSV report with the headings: vCenter, ESXi Host, Syslog Server, Syslog Port. Afterwards to disconnect from all vCenter servers.
I know I need a calculated property (amongst possibly other things) but I'm unable to conceptualize it. Any assistance will be greatly appreciated. Thank you.

#This will prompt you to enter your credentials and load the corresponding module
$vCenterCredential = Get-Credential -Message "Enter account with access to the vCenter(s)" -ErrorAction SilentlyContinue;

Try {Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue}
Catch
{
	$ErrorMessage = $_.Exception.Message
	Write-Host "Error loading Powercli :" $ErrorMessage
	Exit $exitcode
}

if ($vCenterCredential -eq $null) {
    Write-Host = "Credentials are required.  Cannot continue.";
    return 1;
}

#List of vCenter server(s) in a text file either on local or shared drive location
$vCenters = Get-Content -Path "H:\Files\Scripts\Inputs\vcenters.txt" | FT -Autosize -Wrap

#Ignore certificate errors and do not join CEIP
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false

#Connect to vCenters
$report = ForEach ($vCenter in $vCenters) {
Connect-VIServer -Server $vCenter -Credential $vCenterCredential -Protocol https | Out-Null
}

#Get all vm host objects and set to variable
$allvmhosts = get-vmhost  

#cycle through all the esxi hosts and retrieve the syslog attribute, if any                          
foreach ($vmhost in $allvmhosts){                  
    $vmhost | get-vmhostsyslogserver | select @{N='VMHost';E={$vmhost.name}},host,port | FT -AutoSize -Wrap
	}

Select @{N='vCenter';E={$vCenter.Name}},
 }
 
$report | Export-Csv "H:\Files\Scripts\Outputs\syslog-report.csv" -NoTypeInformation -UseCulture

 Disconnect-VIServer -Server $vCenter -Confirm:$false
} 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Basically you could do something like this

#This will prompt you to enter your credentials and load the corresponding module
$vCenterCredential = Get-Credential -Message "Enter account with access to the vCenter(s)" -ErrorAction SilentlyContinue;

#List of vCenter server(s) in a text file either on local or shared drive location
$vCenters = Get-Content -Path "H:\Files\Scripts\Inputs\vcenters.txt"

#Connect to vCenters
Connect-VIServer -Server $vCenters -Credential $vCenterCredential -Protocol https | Out-Null

Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
    Get-VMHostSysLogServer -VMHost $esx |
    Select-Object @{N = 'vCenter'; E = { ([uri]$esx.ExtensionData.Client.ServiceUrl).Host}},
        @{N='VMHost';E={$esx.Name}},
        Host,Port
} | Export-Csv -Path .\syslog-report.csv -NoTypeInformation -UseCulture

Disconnect-VIServer -Server $vCenters -Confirm:$false


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

First question, why are you still using a PSSnapin?
Those were abolished years ago.

Which PowerCLI version are you running?

Get-Module -Name VMware.PowerCLI -ListAvailable


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

0 Kudos
BBB36
Enthusiast
Enthusiast
Jump to solution

I probably don't need it. I'm reusing an old script. If you can help clean it up I'll sincerely appreciate that.

This is the output:

ModuleType Version    Name                                ExportedCommands                                                                                                                                                                                       
---------- -------    ----                                ----------------                                                                                                                                                                                       
Manifest   12.7.0.... VMware.PowerCLI             
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Basically you could do something like this

#This will prompt you to enter your credentials and load the corresponding module
$vCenterCredential = Get-Credential -Message "Enter account with access to the vCenter(s)" -ErrorAction SilentlyContinue;

#List of vCenter server(s) in a text file either on local or shared drive location
$vCenters = Get-Content -Path "H:\Files\Scripts\Inputs\vcenters.txt"

#Connect to vCenters
Connect-VIServer -Server $vCenters -Credential $vCenterCredential -Protocol https | Out-Null

Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
    Get-VMHostSysLogServer -VMHost $esx |
    Select-Object @{N = 'vCenter'; E = { ([uri]$esx.ExtensionData.Client.ServiceUrl).Host}},
        @{N='VMHost';E={$esx.Name}},
        Host,Port
} | Export-Csv -Path .\syslog-report.csv -NoTypeInformation -UseCulture

Disconnect-VIServer -Server $vCenters -Confirm:$false


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

0 Kudos
BBB36
Enthusiast
Enthusiast
Jump to solution

Perfect! Thank you as always. 

0 Kudos