none
Extraction of Account Expiration to Telephone's Notes (AD) RRS feed

  • Question

  • Good day all,

    My objective for the following powershell script needs to satisfy the following requirements,

    1) Get-ADUser from an OU

    2) Foreach Users whose Accounts are not disabled

    3) Replace the "info" attribute, otherwise known as Telephone's Notes with the Accounts' AccountExpirationDate

    My powershell script is as follows,

    Import-Module ActiveDirectory
    
    Get-ADUser -Filter * -Properties * -Searchbase "OU....DC..." | ForEach { 
    if ($_.Enabled -eq "True") {Set-ADUser -Identity $_.SamAccountName -Replace @{Info="Account extended till $_.AccountExpirationDate"}
    }
    

    Although the script passes and there are values entered to the "info" attribute, a.k.a Telephone's notes, it does not input the value in AccountExpirationDate into the Notes.

    The result shown in the Telephone's Notes is as follows,

    "Account extended till "

    >.< please help.

    Best regards,

    KY

    Friday, September 19, 2014 9:36 AM

Answers

  • Change to this:

    ="Account extended till $($_.AccountExpirationDate)"}


    ¯\_(ツ)_/¯

    • Marked as answer by chiaky Monday, September 22, 2014 3:46 AM
    Friday, September 19, 2014 9:50 AM
  • This would be much faster:

    $search='OU....DC...'
    Get-ADUser -Filter 'Enabled -eq $true' -Properties AccountExpirationDate -Searchbase $search  | 
         ForEach-Object{ 
              Set-ADUser $_ -Replace @{Info="Account extended till $($_.AccountExpirationDate)"}
         }


    ¯\_(ツ)_/¯

    Friday, September 19, 2014 10:05 AM

All replies

  • Change to this:

    ="Account extended till $($_.AccountExpirationDate)"}


    ¯\_(ツ)_/¯

    • Marked as answer by chiaky Monday, September 22, 2014 3:46 AM
    Friday, September 19, 2014 9:50 AM
  • This would be much faster:

    $search='OU....DC...'
    Get-ADUser -Filter 'Enabled -eq $true' -Properties AccountExpirationDate -Searchbase $search  | 
         ForEach-Object{ 
              Set-ADUser $_ -Replace @{Info="Account extended till $($_.AccountExpirationDate)"}
         }


    ¯\_(ツ)_/¯

    Friday, September 19, 2014 10:05 AM
  • Thank you, it was very helpful and the values did appear =).

    I still have a long way to learn.

    Monday, September 22, 2014 3:47 AM
  • Thank you Richard, it was very helpful of the script, it made things cleaner.

    Monday, September 22, 2014 3:48 AM