When you
write a Power Shell script sometimes you may require to get some parameter
values from the configuration file. While deployment usually we need to passing
some values from the configuration file.
You can
create configuration file and take those values from it to the PowerShell
script. Example we may need to create sub sites or lists / libraries or content
types etc. To do this you need site URL to be passed to the script.
You may also
need to pass in list name with site URL post deployment when the system is in
use and later you want to make any changes.
We can
create XML file which has data that can be passed to the PowerShell.
Let's create
one configuration file.
Let's now
create one power shell script and get the value from XML file to the script.
What we have
done is we took the xml file reference and then declared one variable in which
we will store site URL.
After that we get the value of that specific site collection URL. We have written loop here because you can also define multiple <name> inside <site collection> tag.
As of now we
are considering one single site collection.
and then we
print the site URL in green color with Write-Host options.
Now open the
SharePoint 2010 management shell.
and execute
the script by typing ./PowerShellScript.ps1
and here is
what you get.
In the same
way, you can define as many tags as you like in XML file and can take those
values inside the power shell script.
I hope this
helps.
No comments:
Post a Comment