header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Object reference not set to an instance of an object.
Last Post 17 Jan 2008 07:28 AM by tHyEstes. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
tHyEstesUser is Offline
New Member
New Member
Posts:13
Avatar

--
16 Jan 2008 12:53 PM  

Hello all

I want to create an IIS6 application pool using powershell and the Microsoft.Sharepoint.Administration namespace. Everytime I want to set the password for the Application pool Identity I get an error: "Object reference not set to an instance of an object"

Does somebody know what I am doing wrong? I use the following lines of code to try to accomplish this:

$app = new-object Microsoft.SharePoint.Administration.SPApplicationPool
$app.currentIdentitytype = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser
$app.name = "test"
$app.username = "winadmin" $password = read-host "Enter a Password:" -assecurestring
$app.password = $password 
$app.provision()
 

Can somebody help me out or does somebody know another good powershell way of creating an IIS6 application pool?

Thanks a lot.

Regards,

Martijn

smurawskiUser is Offline
New Member
New Member
Posts:46

--
16 Jan 2008 01:24 PM  
Martijn,

In looking at the MSDN docs, it appears that $app.password is looking for a string, not a SecureString. There are three ways you can do this. You could replace:
$app.username = "winadmin" $password = read-host "Enter a Password:" -assecurestring
with:
$credential = Get-Credential -Credential "winadmin"
$app.username = $credential.username
$app.password = $credential.GetNetworkCredential().Password #This returns the password to cleartext

or you could:
$app.username = "winadmin" $password = read-host "Enter a Password:" -assecurestring
$app.password = (New-Object System.Management.Automation.PSCredential $app.username, $password).GetNetworkCredential().Password
#which essentially does the same thing.

finally, you could:
$app.password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
#which is a bit more difficult to understand, in my opinion

Of the three, the first is the easiest and makes best use of the cmdlet. Hope this helps!
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
tHyEstesUser is Offline
New Member
New Member
Posts:13
Avatar

--
17 Jan 2008 07:28 AM  

Hi Steven,

thanks for your reply. I tried all three options but unfortunately I get the same error message every time.

Exception setting "Password": "Object reference not set to an instance of an object"

 

Do you have some more suggestions?

 

Regards,

Martijn

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer