Multiple $arg

Welcome Forums General PowerShell Q&A Multiple $arg

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 8 months ago.

  • Author
  • #79670

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    I'm trying to write a PS file that will up ADusers and their various fields, or leave them out if not needed. Relatively new to scripting so sorry about the brutal code. But am i on the right tracks?

    So when i ps adupdate firstname.surname 12345 i am hoping that AD will update that account with the telephone number 12345. or update if department or organization is seleted.

    ---- Begin script ADUpdate.ps1 ----
    $arg4 = "firstname.surname"
    $arg5 = "officephone"
    $arg6 = " Department"
    $arg7 = "Organization"
    $allArgs = @($arg4, $arg5, $arg6, $arg6)
    Get-ADUser -Identity "$Arg4" | Set-ADUser -Officephone "$Arg5", 
    if "$arg5" = null then,
    	Get-ADUser -Identity "$Arg4" | Set-ADUser -Department "$Arg6",
    		if "$arg6" = null then,
    	Get-ADUser -Identity "$Arg4" | Set-ADUser -Organization "$Arg7",
    ----  End script ADUpdate.ps1  ----
  • #80110

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Not sure the right track, no. I'd declare a Param() block and lay out your parameters, optional and mandatory. It's much more in keeping with native patterns. "Learn PowerShell Scripting in a Month of Lunches" covers this in detail if you have access to a copy, but happy to try and answer questions here too.

The topic ‘Multiple $arg’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort