Adding info to Notes field in AD account problem

Hello everyone, hopefully I can describe this correctly, as I’m new to PowerShell and learning on the run here.

So I have a script, that pulls from a .csv file. The file in its first column is usernames(User_Name). The second column is IP address(Framed_IP_Address).

So the script should populate the Notes field in their AD account, Telephone tab, with an IP address. Here’s the script:

Import-module ActiveDirectory
$userlist=Import-Csv C:\PS\newIP2.csv
foreach ($user in $userlist) {write-host "Set-ADUser -Identity $($user.User_Name) -Replace @{info=`"$($user.Framed_IP_Address)`"}"}

When its run, it will show on the console:

Set-ADUser -Identity ExampleUserName -Replace @{info=“”}
Set-ADUser -Identity ExampleUserName -Replace @{info=“”}

So the output looks correct… but the Notes field isn’t populated. Now whats weird is, if I run each of the above commands on their own, just copy/paste and run each individually it will work. The IP will end up in the Notes field.

Any ideas?

Thank you!

Your not running the command. Your just telling PowerShell to write “Set-ADUser -Identity ExampleUserName -Replace @{info=“”}”
Try something like:

Import-module ActiveDirectory
 $userlist=Import-Csv C:\PS\newIP2.csv
 foreach ($user in $userlist) {write-host "Starting to replace info" 
"Set-ADUser -Identity $($user.User_Name) -Replace @{info=`"$($user.Framed_IP_Address)`"}"}

What version of PS are you running?

Version 5 from my client, but I’ve also tried running from a DC running version 4.

Thanks for the tip, tried it. Still not showing up in the AD account Notes field…

The output on the console looks like this now:

Starting to replace info
Set-ADUser -Identity ExampleName -Replace @{info=“”}
Starting to replace info
Set-ADUser -Identity ExampleName -Replace @{info=“”}

Ok, so I’m just telling Powershell to write the command… how do I get it to execute the command?

Also I took out the write-host. I’m at:

Import-module ActiveDirectory
 $userlist=Import-Csv C:\Scripts\newIP2.csv
 foreach ($user in $userlist) 
 {"Set-ADUser -Identity $($user.User_Name) -Replace @{info=`"$($user.Framed_IP_Address)`"}"}

I tested the script and it worked.

$userlist = Import-Csv C:\Test\testinfo.csv
foreach ($user in $userlist){
Write-Host "Setting info"
Set-ADUser -Identity $user.User_name -Replace @{info = $user.Framed_IP_Address}

Remove the quotes around your command,they are turning it into a string.

Alternatively, you could replace white-hot in the first iteration of your code with invoke-expression, I suppose. Whichever you find easier.

Thank you Wilfredo Perez and James Sudbury! Working now.