I got error "Object reference not set to an instance of an object" error with the following (slim) PS scripts -
==========================
Import-Module WebAdministration
$webSites = Get-ChildItem IIS:\Sites
for ($i=0;$i -le $webSites.Count-1;$i++)
{
func1 ($webSites[$i].Name)
}
function func1 ([String]$site_name)
{
func2 -siteName $site_name -para2 "mystring"
}
function func2
{
Param
(
[Parameter(Mandatory=$True, Position=0)]
[String]$siteName,
[Parameter(Mandatory=$True, Position=1)]
[String]$para2
)
#do things with $siteName and $para2....
}
=============================
The error is from the bold line, and it seems from the usage of '$site_name'.
Can anyone help point out what's wrong here and how to fix it?
Thanks in advance