So I have a little background in programming and I have become extremely interested in PowerShell CLI. I was given the task to find and enter certain fields that the Server Team manager wants to have so we can create a CI when we switch software. Initially it was supposed to be done manually but I have found a script that can do it but I need to add some other information that my supervisor is looking for. Where is the best place to learn the syntax and structure for the language? Below is the code and I would like the script to find the
VM Host
Switchport
Data Stores
Data Center
Notes for the Equipment
Application Name
Application Info
App Owner
If it is for testing, development or production
System POC
Application Client PC
Domain
This is the script I have found. Just need to be pointed in the right direction to add the other fields to be filled. Thank you so much.
#Specify the output CSV file bellow
$ExportPath = "Output CSV file FullPath"
#Temporary variable to run this script faster
$VmInfo = Get-VM
$VMS = ($VmInfo).Name
#Getting the required value
$VCenter = @()
foreach ($VMin$VMS)
{
$HostServer = (($VmInfo| ? {$_.Name -eq $VM}).Host).Name
$VMSysInfo = Get-VMGuest -VM $VM
$MyObject = New-Object PSObject -Property @{
VMName = $VM
VMHostName = $VMSysInfo.HostName
VMIP = $VMSysInfo.IPAddress
VMInstalledOS = $VMSysInfo.OSFullName
PowerState = ($VmInfo| ? {$_.Name -eq $VM}).PowerState
NumberOfCPU = ($VmInfo| ? {$_.Name -eq $VM}).NumCpu
MemoryGB = (($VmInfo| ? {$_.Name -eq $VM}).MemoryMB/1024)
VMDataS = (Get-Datastore -VM $VM).Name
HostServer = (($VmInfo| ? {$_.Name -eq $VM}).Host).Name
HostCluster = (Get-Cluster -VMHost $HostServer).Name
}
$VCenter+= $MyObject
}
$VCenter|
Select VMName,
VMHostName,
@{N='VMIPAddress';E={$_.VMIP -join '; '}},
VMInstalledOS,
PowerState,
NumberOfCPU,
MemoryGB,
@{N='VMDataStore';E={$_.VMDataS -join '; '}},
HostServer,
HostCluster |
Export-Csv$ExportPath-NoTypeInformation