locked
Adding to wWWHomePage field in AD RRS feed

  • Question

  • I am trying to figure out why when adding a date to the wWWHomePage field in it works on some accounts and not others. Tested on win 7 and 10, some users when running script won't enter in information. The error is :

    Set-ADUser :</g> Invalid type 'System.Management.Automation.PSObject'.
    Parameter name: wWWHomePage
    At C:\Users\Public\Desktop\offboarding.ps1:16 char:11
    + Set-ADUser <<<<  $Username -Replace @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}
        + CategoryInfo          : InvalidArgument: (Phil.test:ADUser) [Set-ADUser], ArgumentException
        + FullyQualifiedErrorId : Invalid type 'System.Management.Automation.PSObject'.
    Parameter name: wWWHomePage,Microsoft.ActiveDirectory.Management.Commands.SetADUser
     

    I have also tried the use -Add instead of -Replace (line 16) still the same error for some users<g class="gr_ gr_13 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" data-gr-id="13" id="13">.Below</g> is the script being used.

    import-module activedirectory
    Start-Sleep -Seconds 10
    $username = Read-Host 'Please enter Username!'
    Get-ADPrincipalGroupMembership $username | Get-ADGroup -Properties * | select name, description | export-csv Network shared drive\$username.csv
    Start-Sleep -Seconds 10
    Set-aduser -Identity $Username -Replace @{msExchHideFromAddressLists= $true}
    $users = (Get-ADUser $username -properties memberof).memberof
    $users | Remove-ADGroupMember -Members $username -Confirm:$false
    Start-Sleep -Seconds 5
    Disable-ADAccount -Identity $username
    Start-Sleep -Seconds 2
    Get-ADUser $username | Move-ADObject -TargetPath 'OU for termed users'
    Start-Sleep -Seconds 10
    Invoke-Command -ComputerName Run AD sync command
    Start-Sleep -Seconds 5
    Set-ADUser $Username -ADD @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}

    If someone might be able assits in explaining why this is happening or possible solution.



    • Edited by Phl2 Thursday, November 1, 2018 5:36 PM
    Thursday, November 1, 2018 5:32 PM

Answers

  • As jrv noted, this is wrong:

    Set-ADUser $Username -ADD @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}

    and should be replaced with

    $now = Get-Date -format dd-MMM-yyyy
    Set-ADUser $Username  -HomePage $now


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by Phl2 Thursday, December 27, 2018 6:23 PM
    Thursday, December 27, 2018 2:31 PM

All replies

  • I would make the assignment of the $now variable a separate statement, then use -Replace @{wWWHomePage=$($now)}. $($now) should convert the datetime into a string. The different results for different users could be PowerShell or .NET versions.

    Edit: Also, you can use the -HomePage PowerShell parameter to assign the string value to the wWWHomePage AD attribute. The help for Set-ADUser has an example:

    https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee617215(v=technet.10)


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)



    • Edited by Richard MuellerMVP Thursday, November 1, 2018 6:09 PM
    • Proposed as answer by jrv Thursday, November 1, 2018 7:47 PM
    Thursday, November 1, 2018 5:59 PM
  • Changed to to the $($now) and still having the same issue. Some users when they run it puts it in and others doesn't, errors out. I think its the computer
    Thursday, November 1, 2018 7:18 PM
  • This line is wrong:

    Set-ADUser $Username -ADD @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}

    should be:

    $now = Get-Date -format dd-MMM-yyyy
    Set-ADUser $Username  -HomePage $now


    \_(ツ)_/

    Thursday, November 1, 2018 7:46 PM
  • Set-ADUser $Username -Replace @{wWWHomePage=$($now)} does work, its seems to be more an issue with the computer that is being used.
    Thursday, November 1, 2018 9:09 PM
  • Hi,

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    Best Regards,

    Lee


    Just do it.

    Friday, November 2, 2018 7:33 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, November 9, 2018 7:48 AM
  • I still have not been able to figure out the solution or the problem. 

    I have built a vm for few helpdesk people to use, Win 7(64b), admin tools, and few other things

    I run vm, win 10(64b), admin tools and a lot of other tools. 

    The issue seems to be on the Win 7 VM, on Win10 it works with no issues. 

    I have been trying to see what else could cause it other than just a different os. I would not think that adding to specific AD field would be OS dependent. I am pretty sure there is an update or something that is missing. 

    Tuesday, November 27, 2018 7:38 PM
  • Without your exact code and the complete error message there is no way for us to guess at the issue.

    \_(ツ)_/

    Tuesday, November 27, 2018 7:50 PM
  • Below is the error and script

    ------------------------------

    Set-ADUser : Invalid type 'System.Management.Automation.PSObject'.
    Parameter name: wWWHomePage
    At C:\Users\administrator\Desktop\offboarding.ps1:16 char:1
    + Set-ADUser $Username -Replace @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (phil.test:ADUser) [Set-ADUser], ArgumentException
        + FullyQualifiedErrorId : Invalid type 'System.Management.Automation.PSObject'.
    Parameter name: wWWHomePage,Microsoft.ActiveDirectory.Management.Commands.SetADUser

    ----------------------------------------------------------------------------

    below is script being used - side note works on my pc (win 10) does not work on win 7. By not working I mean - it does not input the date into the wWWHomePage. Completes all the other things in the script but that part. I have even tried to move it the top to see if was issue with order, didn't work.

    --------------------

    import-module activedirectory
    Start-Sleep -Seconds 10
    $username = Read-Host 'Please enter Username!'
    Get-ADPrincipalGroupMembership $username | Get-ADGroup -Properties * | select name, description | export-csv Network shared drive\$username.csv
    Start-Sleep -Seconds 10
    Set-aduser -Identity $Username -Replace @{msExchHideFromAddressLists= $true}
    $users = (Get-ADUser $username -properties memberof).memberof
    $users | Remove-ADGroupMember -Members $username -Confirm:$false
    Start-Sleep -Seconds 5
    Disable-ADAccount -Identity $username
    Start-Sleep -Seconds 2
    Get-ADUser $username | Move-ADObject -TargetPath 'OU for termed users'
    Start-Sleep -Seconds 10
    Invoke-Command -ComputerName Run AD sync command
    Start-Sleep -Seconds 5
    Set-ADUser $Username -ADD @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}

    Thursday, December 27, 2018 1:42 PM
  • As jrv noted, this is wrong:

    Set-ADUser $Username -ADD @{wWWHomePage=$now=Get-Date -format "dd-MMM-yyyy"}

    and should be replaced with

    $now = Get-Date -format dd-MMM-yyyy
    Set-ADUser $Username  -HomePage $now


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by Phl2 Thursday, December 27, 2018 6:23 PM
    Thursday, December 27, 2018 2:31 PM
  • checking - seems like it might have worked.
    Thursday, December 27, 2018 4:47 PM
  • Is there a reason why this worked over the other way?
    Thursday, December 27, 2018 6:35 PM
  • First, regarding the use of the -Add parameter. The -Add parameter can only be used to add a value if the attribute is multi-valued. Or it can set a value where none exists if the attribute is single valued. The -Replace parameter can be used to update a single valued attribute whether an old value exists or not. The help does not make this clear. In this case, using the -HomePage parameter avoids the hash table required with -Add.

    Also, the -Add parameter accepts a hash table of entries, similar to the following.

    -Add @{otherTelephone='555-222-1111'; otherMobile='555-222-9999'}

    Entries in the table are separated by semicolons. For each entry in the table, the key is the LDAPDisplayName of an attribute, the value is the value to be assigned to the attribute. The key and value are separated by the equal, "=". PowerShell cannot parse the key and value if there are two equals.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, December 27, 2018 10:49 PM