Congrats! From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Candee Sent: Thursday, July 18, 2013 9:58 AM To: powershell@lists.myitforum.com Subject: Re: [powershell] Re: Create users in AD with multiple if / then conditions
woohoo!!! Never mind this one, guys, I got it to work! Yay me! ::Go Candee:: =) On Wed, Jul 17, 2013 at 2:14 PM, Candee <can...@gmail.com<mailto:can...@gmail.com>> wrote: Let me preface this with this: Michael, you've been a tremendous help - I think you've written the entire script, just about. So of course, I have one more problem. If anyone can point me in the right direction.... The preferred first / last name is working perfectly. Testing if the user already exists, then adding a letter to the first name and testing again (so if cgmail already exists, I use cagmail). The problem is when I export the user name and other information back to HR. I need MISUSERNAME to be either the one that worked, or null or "Manually create"... It's always first initial / last name. I am attaching a copy of the script, if anyone has a few minutes to look it over. Thanks all! On Thu, Jul 11, 2013 at 2:07 PM, Candee <can...@gmail.com<mailto:can...@gmail.com>> wrote: Yes! I think I got it - thank you! I missed the '' :) That parts working, so I can start messing with the rest. Of course, as soon as I'm finished they'll change the requirements. :( thank you *so* much!! On Thu, Jul 11, 2013 at 1:54 PM, Michael B. Smith <mich...@smithcons.com<mailto:mich...@smithcons.com>> wrote: You didn't do it exactly the way I showed. :) You have to create the variable FIRST with an assignment and then assign it further within the if/then/else blocks. Otherwise, scoping rules make the variable disappear. From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com>] On Behalf Of Candee Sent: Thursday, July 11, 2013 1:46 PM To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: Re: [powershell] Re: Create users in AD with multiple if / then conditions I'm having a heck of a time today - I have to stop with the tab button - sorry... You cannot call a method on a null valued expression. $SAM = $givenname.substring <<<< (0,1) + $SN invalidoperation: (Substring:string) [], runtimeException FullyQualifiedErrorId : InvokeMethodonNull On Thu, Jul 11, 2013 at 1:43 PM, Candee <can...@gmail.com<mailto:can...@gmail.com>> wrote: That makes more sense, doesn't it? Thanks Michael. Now I'm getting this error: You cannot call a method on a null-valued expression On Thu, Jul 11, 2013 at 1:22 PM, Michael B. Smith <mich...@smithcons.com<mailto:mich...@smithcons.com>> wrote: $givenName = '' If( -not [String]::IsNullOrEmpty( $_.PreferredFirstName ) ) { $givenName = $_.PreferredFirstName } Else { $givenName = $_.FirstName } Etc.etc.etc. From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com>] On Behalf Of Candee Sent: Thursday, July 11, 2013 1:05 PM To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: Re: [powershell] Re: Create users in AD with multiple if / then conditions Sorry, First name = real first name (ie William) Preferred first name = nickname (ie Bill) Last name = real last name (ie Smith, Jr) Last name preferred = ie Smith (no Jr). So, the two preferreds have to be checked first. if preferred first name is blank, I need to use the real first name If the last name preferred is blank, I need to use the real last name. Once I have those, I can create the display name, email address, etc. (I had the script working with just first name / last name, but these additional preferred columns changed that). Right now, I'm gettng: Unexpected token 'sn' in expression or statement Parser error: (sn:string) [], parentcontainserrorrecordexception On Thu, Jul 11, 2013 at 12:45 PM, Trevor Sullivan <tsul...@gmail.com<mailto:tsul...@gmail.com>> wrote: Can you clarify on "can't seem to get it to work?" What are you trying to achieve? What are the results of your command? What differs between the actual results, and the intended results? Cheers, Trevor Sullivan From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com>] On Behalf Of Candee Sent: Thursday, July 11, 2013 11:40 AM To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: [powershell] Re: Create users in AD with multiple if / then conditions Let's try this again: Import-csv $newusers |foreach { If ($_.preferredfirstname -eq $null -and $_.lastnamepreferred -eq $null) { $givenname = $_.firstname $sn = $_.lastname} elseif (($_.preferredfirstname -ne $null -and $_.lastnamepreferred -eq $null) {$givenname = $_.preferredfirstname $sn = $_.lastname} elseif (($_.preferredfirstname -eq $null -and $_.lastnamepreferred -ne $null) {$givenname = $_.firstname $sn = $_.lastnamepreferred} Etc, through the rest. Thanks all, Candee On Thu, Jul 11, 2013 at 12:35 PM, Candee <can...@gmail.com<mailto:can...@gmail.com>> wrote: Hello, I need to import users from a csv from HR. There are multiple fields for both first name and last name. I can't seem to get it to work. This is what I have so far - if anyone can offer assistance, it's much appreciated. Import-csv $newusers |foreach { ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1