Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Set-QADUser -Identity

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I have a script that is reading values from an Excel spreadsheet to create an Exchange 2007 Mailbox. After the mailbox is converted I use the Qwest tools to set additional user properties.

The script is successfully creating my users but I am unsuccessful in using Set-QADUser. When I pass the identity which is formed via the concatenation of two variables and then removing the space between them. The exact error I get is
Set-QADUser : The attribute syntax specified to the directory service is invalid. (Exception from HRESULT: 0x8007200B) At C:\Go\CreateUsers.ps1:97 char:13 + Set-QADUser <<<< -Identity $dl `

I was encountering problems earlier because values I was passing were somehow not strings.

Here is how I am creating $dl
Code:
	$dl = ($Domain)+($Login)
	$dl = [string] $dl.Replace(" ","") 
	Write-Host $dl

The output of Write-Host looks perfect and when I manually type the command in PowerShell with the same text it works to bind to the user object.

Does anyone have any ideas? This is my first attempt to really just use PowerShell and I am about to abandon it to get the job done and just use VBScript to create the users then fire off PowerShell to mail enable those users. Using PowerShell is my preference to force me to upgrade my skills though.

Any assistance would be most appreciated.
 
I'm not the best with this, but...
define your paramaters in a param block. Not sure how $domain and $login are being assigned but:

Code:
param(
[string]$dl,
[string]$domain,
[string]$login
)
# do stuff here....
$dl = $Domain+$Login
$dl = $dl.Replace(" ","")     
Write-Host $dl
# do stuff here...

# clean up
[url=http://technet.microsoft.com/en-us/library/dd347612.aspx]remove-variable[/url] $dl
remove-variable $domain
remove-variable $login

This is ad-hoc, so YMMV.

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
Thanks Pat, I don't understand what a param block does so I will look that up s I can follow what this should be doing differently. I will report back when I have tested it.
 
I appreciate your effort Pat but it did not work, said "The term 'Param' is not recognized as a cmdlet, function, operable program or script file."

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
#would this help?
$dl = [string] ""
$dl = ($Domain)+($Login)
$dl = $dl.Replace(" ","")
Write-Host $dl

i too had a similar issue with a moniker string, cant recall the circumstance or the solution, sorry.

would quotes round the string help? would the equiv of CStr() help?, would the little qoutes help(')?

sorry, i am still shooting in the dark with ps
 
There's got to be something else going on there. A param block allows you to define your parameters, including the type. I put this at the beginning of the script right after comment-based help, but they can also go inside of functions. mrmovie's suggestion should probably work as well, except I wouldn't put $domain and $login in parenthesis.

Maybe these will help.

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
oh, i remember what my problem was, its was this:

#this didnt work
Get-SomeSillyAddIn "SMS\Site_" + $strSSiteCode + ":SMS_Class"

#but this did work
$strMoniker = "SMS\Site_" + $strSSiteCode + ":SMS_Class"
Get-SomeSillyAddIn $strMoniker

#dont ask me, but i swear that was happening, my ears were bleeding by the end of the afternoon
 
Thanks for the suggestions guys, regretfully same result. I really wish I better understood how PS concatenates. I don't understand why it puts a space in there in the first place. I need to research PowerShell Types some more.

Pat I will take a look at those links later in the day.

If I can't get this to work I am going to drop back and write this all in VBScript to fully create the users and then use the VBScript to call PowerShell to mail enable the accounts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top