NicksonKoh
asked on
Debugging a PowerShell Simple Code
Hi Experts,
This is my first time writing a powershell script. So, I really need some help here.
Below code is a very simple code to write a new record into a list. But I am getting the following error
"Cannot index into a null array.
At D:\Batch Jobs\PowerShell Scripts\test.ps1:8 char:59
+ $root.lists.add("CTest","C ustom Test",$root.listtemplates[ <<<< "Custom List"])
+ CategoryInfo : InvalidOperation: (Custom List:String) [], RuntimeException
+ FullyQualifiedErrorId : NullArray"
Can advise what could the possible problem for the error?
This is my first time writing a powershell script. So, I really need some help here.
Below code is a very simple code to write a new record into a list. But I am getting the following error
"Cannot index into a null array.
At D:\Batch Jobs\PowerShell Scripts\test.ps1:8 char:59
+ $root.lists.add("CTest","C
+ CategoryInfo : InvalidOperation: (Custom List:String) [], RuntimeException
+ FullyQualifiedErrorId : NullArray"
Can advise what could the possible problem for the error?
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
# Connect to the site collection
$site = New-Object Microsoft.SharePoint.SPSite("http://sharepoint.apb.com.sg/gmis/ec")
$web = $site.rootweb
$list = $web.Lists["Email Convertor Service Check"]
$newitem = $list.items.Add()
$newitem["Date"]= "4/10/2012";
$newitem["Result"] = "Email Converter Service Stopped";
$newitem.update()
$web.Dispose()
$site.Dispose()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I realise my mistake is in the following 3 lines of code
$site = New-Object Microsoft.SharePoint.SPSit
$web = $site.rootweb
$list = $web.Lists["Email Convertor Service Check"]
$web changes the pointer to go to the rootweb but
my "Email Converter Service Check" is a custom list in $site
What should I change such that the list should be pointing to $site and not the rootweb.