Awesome - thanks for your help guys. I am pretty sure I can get this to do exactly what I need. The last line with the find and replace inside the config file was a stumbling block for me that you have solved.
Carl From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Murray, Mike Sent: Wednesday, July 27, 2016 10:24 AM To: mssms@lists.myitforum.com Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Good point! Also, I was thinking about this last night (yeah, I'm a dork). You could easily just replace the extension value in the existing file (instead of creating a completely new one) with something like this: # Get Active Directory information for current user (Thanks Freddy!) $UserName = $env:username $Filter = "(&(objectCategory=User)(samAccountName=$UserName))" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.Filter = $Filter $ADUserPath = $Searcher.FindOne() $ADUser = $ADUserPath.GetDirectoryEntry() $ADTelePhoneNumber = $ADUser.telephoneNumber #Replace value in config file (Get-Content c:\scripts\test.txt) -replace '\[EXTENSION\]', $ADTelePhoneNumber | Set-Content c:\scripts\test.txt From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Freddy Grande Sent: Tuesday, July 26, 2016 5:45 PM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Does that not require RSAT being installed on each client computer? You might be better off replacing the first two lines with something like this: # Get Active Directory information for current user $UserName = $env:username $Filter = "(&(objectCategory=User)(samAccountName=$UserName))" $Searcher = New-Object System.DirectoryServices.DirectorySearcher $Searcher.Filter = $Filter $ADUserPath = $Searcher.FindOne() $ADUser = $ADUserPath.GetDirectoryEntry() $ADTelePhoneNumber = $ADUser.telephoneNumber You can clean that up and change variables to fit with your script. Just grabbed this off my Outlook Signatures script that runs on each client computer as users to build their signatures from AD attributes. Regards, Freddy From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Murray, Mike Sent: Wednesday, 27 July 2016 9:56 AM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Here's some more. I'm just tinkering, I'm sure there's a PowerShell expert or 50 on this list that could come up with something better. But this would let you build the config file on the fly. Import-Module ActiveDirectory $phone = Get-ADUser -Identity $env:USERNAME -Properties * | Select-Object -ExpandProperty TelephoneNumber $text = "First Line: Settings Here" $text = $text + "`r`n" $text = $text + "Second Line: Settings Here" $text = $text + "`r`n" $text = $text + "Extenstion: " $text = $text + $phone $text | Out-File C:\Scripts\test.txt The "`r`n" is a CR-LF. From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Murray, Mike Sent: Tuesday, July 26, 2016 4:03 PM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Here's some basic stuff to get you started. You could read the logged in user and search their AD user record: Import-Module ActiveDirectory Get-ADUser -Identity $env:USERNAME -Properties * | Select-Object -ExpandProperty TelephoneNumber | Out-File C:\Scripts\Config.txt This writes the phone number to a text file. I'm sure you could manipulate this to create the config file you want. Mike From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Enley, Carl Sent: Tuesday, July 26, 2016 2:22 PM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Perhaps I am not being clear - I have a package built already, I have the user settings and the system settings already worked out. When the application is launched the user is prompted to enter their phone extension. I know where this information is stored in the config file but I do not know how to query Active Directory attribute to retrieve phone extension and then insert this value into my config file. Thanks Carl From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Andrew Craig Sent: Tuesday, July 26, 2016 3:28 PM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Sorry, I didn't read your email properly. You want to separate the system installation from the user settings,(config file). Powershell app deployment toolkit might be your friend here... From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Enley, Carl Sent: 26 July 2016 15:27 To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes I am not sure? So I can query AD and get a phone extension and update a configuration file using GPP? I know I can use it to copy the files to the user directory but I already have that worked out, I need a way to export the AD information and write it to the configuration file. I think the delivery method of that file to the users machine can be either GPP or SCCM etc... From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Andrew Craig Sent: Tuesday, July 26, 2016 9:01 AM To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] RE: Scripting - Pwr Shell AD Attributes Could you not use Group Policy Preferences for this? From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Enley, Carl Sent: 26 July 2016 14:30 To: mssms@lists.myitforum.com<mailto:mssms@lists.myitforum.com> Subject: [mssms] Scripting - Pwr Shell AD Attributes I am posting to see if any of you folks have done what I am trying to do and can offer any tips or advice. - Deploying Avaya soft phone package to my end users - package, install etc...everything is fine and works great no problem there. There is a config file in %username%\appdata\Roaming\Avaya\etc... that stores the server name, sip information and a few other static values. I have no problem updating that file and copying it to that location during the package deployment but there is one user configured setting that is not static and I cannot set it during deployment and that is the users phone extension. Obviously every user has a unique phone extension so the information is different for each user that installs the package, it is easy enough to have them fill in the information when the application is launched BUT I like to automate stuff if at all possible. :) So here is my question...is it possible that during the install of the package maybe as a dependency (this is how I am copying the config files to the user directory - package installs as "system" file copy as "user") I could have a PowerShell script that queries AD for the phone extension of the logged on user and inserts it into the config file? Has anyone written a script to query AD attributes and insert them into a text file replacing a current value? Thanks for any tips / advice. NOTICE: This email is confidential. If you are not the nominated recipient, please immediately delete this email, destroy all copies and inform the sender. Australian Maritime Systems Ltd. (AMS) prohibits the unauthorised copying or distribution of this email. This email does not necessarily express the views of AMS. AMS does not warrant nor guarantee that this email communication is free from errors, virus, interception or interference.