Domanda

I got a custom Sharepoint list which has the following list items

Hostname  -   IP   -     OS     -    CPUs - RAM -    Disk

Server      1.1.1.1   Server 2003     3      8    Disk C: 20gb

If i then change, lets say, the RAM so there is now 12gb (or CPU or any of the other values) i would like it to update it)

I got scripts that pull all the information from the servers via WMI and exporting it to a .csv

The csv layout looks like the following

IP,Hostname,OS,CPU,Ram,Disk
1.1.1.1,Server,Server 2003,3,12,Disk C: 20gb

Now here's the real question, i got a script that add's the items to the list, but if i run it again it adds the item to the list so its now there twice, (one with the old value and one with the new) but i need a script that can update the diffrent column values if they should change, without having to remove the item and add it again with the new values.

È stato utile?

Soluzione

Update list item using powershell -

$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb http://SP -AssignmentCollection $spAssignment

Next step is to get the list:

$SPList = $SPWeb.Lists["Announcements"]

When we have located the list we can retrieve the item. The quickest way is to use the GetItemByID() method:

$SPItem = $SPList.GetItemById("1")

The example above requires that you know the ID of the item. If you don’t know the items ID you can use the Where-Object cmdlet instead:

$SPItem = $SPList.Items | Where { $_["Title"] -eq "New Announcement" }

When you’ve retrieved the item you can modify the item information.

$SPItem[“Title”] = "MyTitle"
$SPItem[“Body”] = "MyBody"

After modifying an item you have to call the Update() method to set the changes.

$SPItem.Update()

When you’re done, use the Stop-SPAssignment cmdlet to dispose the SPWeb object.

Stop-SPAssignment $SPAssignment

Source and more info here: http://mysharepointwork.blogspot.com/2010/09/addupdatedelete-list-items-using.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top