![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | copy files with AD attributes in name?? I have a folder full of employee pictures. The name format is from active directory, as "sn, givenname.JPG" Now I have a web app that can not access the first and last name to display the picture. It only knows the SAMAccountName. Does anyone have a clue where to start with a script to copy these files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? -- -- Steven http://www.glimasoutheast.org |
My System Specs![]() |
| | #2 (permalink) |
| | Re: copy files with AD attributes in name?? # use -recurse (on get-childitem) to traverse sub dirs get-childitem *.jpg | foreach { # parse jpg file name to extract sn and givenname $regex = ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) $sn = $regex[0].groups['sn'].value $gn = $regex[0].groups['gn'].value # cant test it right now, place here the code to # search AD for users that match $sn and $gn, get its samaccountname $samaccountname = "shaylevi" # testing rename-item $_ -newname "$samaccountname.jpg" } Shay http://scriptolog.blogspot.com Quote: > I have a folder full of employee pictures. > The name format is from active directory, as > "sn, givenname.JPG" > Now I have a web app that can not access the first and last name to > display the picture. It only knows the SAMAccountName. > > Does anyone have a clue where to start with a script to copy these > files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? > > http://www.glimasoutheast.org > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: copy files with AD attributes in name?? Here is a function to find a AD user with sn and GivenName function Find-ADUserwithSN{ param($sn,$givenName) $root = [ADSI]"LDAP://192.168.0.10" $filter = "(&(objectcategory=user)(sn=$sn))" $props = "sn","givenName","sAMAccountName" $ds = new-Object system.DirectoryServices.DirectorySearcher($root,$filter,$props) $ds.findall() | ?{$_.properties.givenname -match $givenName} | %{$_.properties.samaccountname} } "Shay Levi" <no@xxxxxx> wrote in message news:8766a94473e48c9c54a78b4b1a8@xxxxxx Quote: ># use -recurse (on get-childitem) to traverse sub dirs > > get-childitem *.jpg | foreach { > > # parse jpg file name to extract sn and givenname > $regex = ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) > > $sn = $regex[0].groups['sn'].value > $gn = $regex[0].groups['gn'].value > > # cant test it right now, place here the code to # search AD > for users that match $sn and $gn, get its samaccountname > $samaccountname = "shaylevi" # testing > > rename-item $_ -newname "$samaccountname.jpg" > } > > > > > > Shay > http://scriptolog.blogspot.com > > > Quote: >> I have a folder full of employee pictures. >> The name format is from active directory, as >> "sn, givenname.JPG" >> Now I have a web app that can not access the first and last name to >> display the picture. It only knows the SAMAccountName. >> >> Does anyone have a clue where to start with a script to copy these >> files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? >> >> http://www.glimasoutheast.org >> > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: copy files with AD attributes in name?? btw.. I did a match instead of an equal so it maybe possible to get more than one return... I did that so you can determine the error case on your own. You may want to write those to a file or what have you. "Brandon Shell" <tshell.mask@xxxxxx> wrote in message news:%23kz9W309HHA.600@xxxxxx Quote: > Here is a function to find a AD user with sn and GivenName > function Find-ADUserwithSN{ > param($sn,$givenName) > $root = [ADSI]"LDAP://192.168.0.10" > $filter = "(&(objectcategory=user)(sn=$sn))" > $props = "sn","givenName","sAMAccountName" > $ds = new-Object > system.DirectoryServices.DirectorySearcher($root,$filter,$props) > $ds.findall() | ?{$_.properties.givenname -match $givenName} | > %{$_.properties.samaccountname} > } > > "Shay Levi" <no@xxxxxx> wrote in message > news:8766a94473e48c9c54a78b4b1a8@xxxxxx Quote: >># use -recurse (on get-childitem) to traverse sub dirs >> >> get-childitem *.jpg | foreach { >> >> # parse jpg file name to extract sn and givenname >> $regex = ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) >> >> $sn = $regex[0].groups['sn'].value >> $gn = $regex[0].groups['gn'].value >> >> # cant test it right now, place here the code to # search AD >> for users that match $sn and $gn, get its samaccountname >> $samaccountname = "shaylevi" # testing >> >> rename-item $_ -newname "$samaccountname.jpg" >> } >> >> >> >> >> >> Shay >> http://scriptolog.blogspot.com >> >> >> Quote: >>> I have a folder full of employee pictures. >>> The name format is from active directory, as >>> "sn, givenname.JPG" >>> Now I have a web app that can not access the first and last name to >>> display the picture. It only knows the SAMAccountName. >>> >>> Does anyone have a clue where to start with a script to copy these >>> files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? >>> >>> http://www.glimasoutheast.org >>> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: copy files with AD attributes in name?? Thanks for the regex. I cheaped out and just used the following: ----------------- # use -recurse (on get-childitem) to traverse sub dirs get-childitem \\tg16\EmployeePhotos\@all\*.jpg | foreach { $sn = "" $gn = "" # parse jpg file name to extract sn and givenname $regex = ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.[Jj][Pp][Gg]$').matches($_.name) $sn = $regex[0].groups['sn'].value $gn = $regex[0].groups['gn'].value copy-item $_ "\\tg16\EmployeePhotos\@firstlast\$gn$sn.jpg" } ----------------------- It was sufficient, since our AD login naming convention is "FirstName""LastName". The more I use PowerShell, the more I like it. It seems much more intuitive to me than VBS, of course, my Unix background has a little to do with it. -- -- Steven http://www.glimasoutheast.org "Shay Levi" <no@xxxxxx> wrote in message news:8766a94473e48c9c54a78b4b1a8@xxxxxx Quote: ># use -recurse (on get-childitem) to traverse sub dirs > > get-childitem *.jpg | foreach { > > # parse jpg file name to extract sn and givenname > $regex = ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) > > $sn = $regex[0].groups['sn'].value > $gn = $regex[0].groups['gn'].value > > # cant test it right now, place here the code to # search AD for users that match $sn and $gn, get its samaccountname > $samaccountname = "shaylevi" # testing > > rename-item $_ -newname "$samaccountname.jpg" > } > > > > > > Shay > http://scriptolog.blogspot.com > > > Quote: >> I have a folder full of employee pictures. >> The name format is from active directory, as >> "sn, givenname.JPG" >> Now I have a web app that can not access the first and last name to >> display the picture. It only knows the SAMAccountName. >> >> Does anyone have a clue where to start with a script to copy these >> files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? >> >> http://www.glimasoutheast.org >> > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: copy files with AD attributes in name?? BTW, the regex is not case sensitive so "jpg" is much more understanable ![]() Shay http://scriptolog.blogspot.com Quote: > Thanks for the regex. > > I cheaped out and just used the following: > ----------------- > # use -recurse (on get-childitem) to traverse sub dirs > get-childitem \\tg16\EmployeePhotos\@all\*.jpg | foreach { > $sn = "" > $gn = "" > # parse jpg file name to extract sn and givenname > $regex = > ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.[Jj][Pp][Gg]$').matches($_.name > ) > $sn = $regex[0].groups['sn'].value > $gn = $regex[0].groups['gn'].value > copy-item $_ "\\tg16\EmployeePhotos\@firstlast\$gn$sn.jpg" > } > ----------------------- > It was sufficient, since our AD login naming convention is > "FirstName""LastName". > > The more I use PowerShell, the more I like it. > It seems much more intuitive to me than VBS, of course, my Unix > background has a little to do with it. > http://www.glimasoutheast.org > > "Shay Levi" <no@xxxxxx> wrote in message > news:8766a94473e48c9c54a78b4b1a8@xxxxxx > Quote: >> # use -recurse (on get-childitem) to traverse sub dirs >> >> get-childitem *.jpg | foreach { >> >> # parse jpg file name to extract sn and givenname >> $regex = >> ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) >> $sn = $regex[0].groups['sn'].value >> $gn = $regex[0].groups['gn'].value >> # cant test it right now, place here the code to # search AD for >> users that match $sn and $gn, get its samaccountname >> >> $samaccountname = "shaylevi" # testing >> >> rename-item $_ -newname "$samaccountname.jpg" >> } >> Shay >> http://scriptolog.blogspot.com Quote: >>> I have a folder full of employee pictures. >>> The name format is from active directory, as >>> "sn, givenname.JPG" >>> Now I have a web app that can not access the first and last name to >>> display the picture. It only knows the SAMAccountName. >>> Does anyone have a clue where to start with a script to copy these >>> files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? >>> >>> http://www.glimasoutheast.org >>> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: copy files with AD attributes in name?? Sorry, I was wrong. It is case sensetive. Shay http://scriptolog.blogspot.com Quote: > BTW, the regex is not case sensitive so "jpg" is much more > understanable ![]() > > Shay > http://scriptolog.blogspot.com Quote: >> Thanks for the regex. >> >> I cheaped out and just used the following: >> ----------------- >> # use -recurse (on get-childitem) to traverse sub dirs >> get-childitem \\tg16\EmployeePhotos\@all\*.jpg | foreach { >> $sn = "" >> $gn = "" >> # parse jpg file name to extract sn and givenname >> $regex = >> ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.[Jj][Pp][Gg]$').matches($_.nam >> e >> ) >> $sn = $regex[0].groups['sn'].value >> $gn = $regex[0].groups['gn'].value >> copy-item $_ "\\tg16\EmployeePhotos\@firstlast\$gn$sn.jpg" >> } >> ----------------------- >> It was sufficient, since our AD login naming convention is >> "FirstName""LastName". >> The more I use PowerShell, the more I like it. >> It seems much more intuitive to me than VBS, of course, my Unix >> background has a little to do with it. >> http://www.glimasoutheast.org >> "Shay Levi" <no@xxxxxx> wrote in message >> news:8766a94473e48c9c54a78b4b1a8@xxxxxx Quote: >>> # use -recurse (on get-childitem) to traverse sub dirs >>> >>> get-childitem *.jpg | foreach { >>> >>> # parse jpg file name to extract sn and givenname >>> $regex = >>> ([regex]'^(?<sn>[^,]*),\s(?<gn>[^.]*)\.jpg$').matches($_.name) >>> $sn = $regex[0].groups['sn'].value >>> $gn = $regex[0].groups['gn'].value >>> # cant test it right now, place here the code to # search AD for >>> users that match $sn and $gn, get its samaccountname >>> $samaccountname = "shaylevi" # testing >>> >>> rename-item $_ -newname "$samaccountname.jpg" >>> } >>> Shay >>> http://scriptolog.blogspot.com >>>> I have a folder full of employee pictures. >>>> The name format is from active directory, as >>>> "sn, givenname.JPG" >>>> Now I have a web app that can not access the first and last name to >>>> display the picture. It only knows the SAMAccountName. >>>> Does anyone have a clue where to start with a script to copy these >>>> files from "sn, givenname.JPG" to "SAMAccountName.jpg" ?? >>>> http://www.glimasoutheast.org >>>> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| 'Recent Files' on Start Menu has lost special attributes | Vista installation & setup | |||
| Files attributes Read Only in Program files | Vista file management | |||
| Searching for files by attributes | Vista file management | |||
| copy-item changing files attributes on network copy failures | PowerShell | |||
| Searching, sorting, and excluding files by attributes | Vista file management | |||