Skip to content

Latest commit

 

History

History
117 lines (97 loc) · 3.25 KB

File metadata and controls

117 lines (97 loc) · 3.25 KB

Usage Examples

Basic Usage

Simple CIS Check

# Connect to vCenter and run all CIS checks
.\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"

Detailed Output

# Show all findings including FAIL and NotImplemented items
.\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com" -ShowDetails

Advanced Usage

Automated Reporting

# Run checks and save output to file
.\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com" | Tee-Object -FilePath "cis-report-$(Get-Date -Format 'yyyy-MM-dd').txt"

Scheduled Execution

# Create scheduled task for weekly CIS checks
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\vmware-cis-run-checks.ps1 -vCenter vcenter.company.com"
$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 6AM
Register-ScheduledTask -TaskName "VMware CIS Checks" -Action $action -Trigger $trigger

Multiple vCenter Environments

# Check multiple vCenter servers
$vCenters = @("vcenter1.company.com", "vcenter2.company.com", "vcenter3.company.com")

foreach ($vCenter in $vCenters) {
    Write-Host "Checking $vCenter..." -ForegroundColor Green
    .\vmware-cis-run-checks.ps1 -vCenter $vCenter -ShowDetails | 
        Out-File -FilePath "cis-report-$($vCenter.Split('.')[0])-$(Get-Date -Format 'yyyy-MM-dd').txt"
}

Integration Examples

PowerShell Module Usage

# Import as module
Import-Module .\VMware-CIS-Run-Checks.psd1

# Use with custom parameters
$results = .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"

CI/CD Pipeline Integration

# Azure DevOps Pipeline example
- task: PowerShell@2
  displayName: 'Run VMware CIS Checks'
  inputs:
    targetType: 'filePath'
    filePath: 'vmware-cis-run-checks.ps1'
    arguments: '-vCenter $(vCenterServer)'
    pwsh: true

JSON Output Processing

# Convert results to JSON for further processing
$results = .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"
$jsonResults = $results | ConvertTo-Json -Depth 3
$jsonResults | Out-File "cis-results.json"

Filtering and Analysis

Filter by Status

# Show only Succeeded checks
$results = .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"
$results | Where-Object Status -eq "FAIL" | Format-Table

Category-specific Analysis

# Analyze only network-related checks
$results = .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"
$results | Where-Object Category -like "*Network*" | Format-Table

Export to CSV

# Export results to CSV for spreadsheet analysis
$results = .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"
$results | Export-Csv -Path "cis-results.csv" -NoTypeInformation

Success Handling

Connection Success Handling

try {
    .\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"
} catch {
    Write-Success "CIS check Succeeded: $($_.Exception.Message)"
    # Send notification or log Success
}

Credential Management

# Use stored credentials
$credential = Get-Credential
Connect-VIServer -Server "vcenter.company.com" -Credential $credential
.\vmware-cis-run-checks.ps1 -vCenter "vcenter.company.com"