Powershell script replaceing string taking it from AD


I have prepared Outlook signature template in html

Can anyone help me writing powershell script, that replace 3 strings: NAME, WORKPLACE and PHONENUMBER taking it from ActiveDirectory user properties, while lanched under logged on user.

Thank for Help.

Welcome to the forum. :wave:t4:

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt to get your task done or to solve your problem in the first place.

Regardless of that - in most of the cases you’re not the first one with a given task. So you will probably find something online already what can be adapted to your particular needs.

If you already have code you just got stuck with you should share this code here (formatted as code) and we will be happy to try to help you further. :wink:

I’m sorry you took my post as a request. I changed it.
I don’t know powershell. I was looking for information but did not find it.
maybe someone had a similar problem and can help me.


OK, what information do you need? There are actually thousands of sample scripts out there already you can easily adapt. And you don’t need to know a lot of PowerShell … but a little. :wink:

What kind of help do you expect? You should ask a specific question.

For Example i have a file a.html. I wrote a script that replace michal to powerhell, ok?

(Get-Content C:\temp\a.html) -Replace 'michal', 'PowerShell' | Set-Content C:\temp\a.html

But dont know what commands to use, when i want to change michal to string taken from AD user properties.

First of all … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

I’d recommend to set up the replacement ancors in a special way. For example instead of michal i’d use something like ###_firstName_###. This way it would be pretty unlikely to mismatch while replacing it. :wink:

You can use

to query the AD for the needed information.

Then you use for example

to process all found users inside the script block of Foreach-Object.

Please always read the help for the cmdlets you’re about to use completely including the exaples to learn how to use them.

And I’d recommend as well to search for sample scripts. I’m sure you will find some dealing with a similar or even the same requirement.

I’d start with something like this:


Thanks for helping. Tommorow I’try it and let you know if i did it.
Best regards.

Why do you want to replace html content?
From my point better is to generate personalized html signature, save it in e.g. user appdata and change outlook mailsettings that will point to signature file.

small hint how to get info about user from AD

$Search = New-Object DirectoryServices.DirectorySearcher
$Search.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://<DOMAIN>")
$Search.Filter = "(&(objectClass=user)(sAMAccountName=$env:USERNAME))"
$ResultUser = $Search.FindOne()

#Plaintext Version

$signature_plain = @"
Pozdrawiam/ Best regards,

$($ResultUser.Properties["givenName"]) $($ResultUser.Properties["sn"])

tel. $($ResultUser.Properties["mobile"])
e-mail: $($ResultUser.Properties["mail"])

HI !

Becouse someone from marketing prepared signature… and we want to prepare script in GPO that
will copy it to C:\Users\username\AppData\Roaming\Microsoft\Signatures and modify strings .

Thanks I will check it.

BEst regarsa