Good day. I am using a variant of PowerShell called PowerCLI 5.1. I am using this to update a multi-column SharePoint 2013 List with multiple items from a VMware Virtual Center database. The code that I'm using is this:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$viservers = "MyServer"
ForEach ($singleViserver in $viservers)
{
Connect-VIServer $singleViserver -User domainuser -Password accountpassword
$HostReport = @()
Get-Datacenter -Name NYDC | Get-VM |Get-View| %{
$Report = "" | select Name, VMos, IP, NumCPU, MemoryMB, FQDN, Status, Admin1, Admin2
$Report.Name =$_.Name
$Report.VMos =$_.Summary.Config.GuestFullName
$Report.IP =$_.Guest.IPAddress
$Report.NumCPU =$_.Config.Hardware.NumCPU
$Report.MemoryMB =$_.Config.Hardware.MemoryMB
$Report.FQDN =$_.Guest.HostName
$Report.Admin1 = (Get-VIObjectByVIView $_).CustomFields["Admin1"]
$Report.Admin2 = (Get-VIObjectByVIView $_).CustomFields["Admin2"]
$HostReport += $Report
}
}
$web = Get-SPWeb http://mysharepointsite
$list = $web.Lists["MYVMList"]
foreach ($item in $list.Items)
{
$item["Name"] = $Report.Name;
$item["Guest_OS"] = $Report.VMos;
$item["Memory_Size"] = $Report.MemoryMB;
$item["CPU_Count"] = $Report.NumCPU;
$item["IP_Address"] = $Report.IP;
$item["FQDN"] = $Report.FQDN;
$item["Admin1"] = $Report.Admin1;
$item["Admin2"] = $Report.Admin2;
$item.Update();
}
However, it seems to populate my entire list with only the first VM properties and ignores all the other VM's. Now I know that the first part of my code works because I can properly update an Excel spreadsheet with all my VM's and their properties.
I'm not sure what I did wrong with updating the SharePoint list with those properties. Any help would be appreciate, thank you.
You are not actually iterating through the VM properties (you keep putting the same VM property into each item) Here is the code I used to get from one list to another list (kind of the same as you).