Odd replace issue...


hi all.

i have simple function returns value in turn updates ad attribute getting error , not sure why:

function is_remote {


    $remotemenuarray = ,@(1,"yes")
    $remotemenuarray +=,@(2,"no")


    cls
    write-host "-------------"
    foreach ($a in $remotemenuarray ) {write-host $a}
    write-host "-------------"

    $x = read-host "is user remote?"
    switch ($x)
        {
            1 {return "yes"}
            2 {return "no"}
            default {"you have not selected valid option"; $is_remote = ""; is_remote}
        }
}

$is_remote = is_remote
$computername = "testpsscript"

set-adcomputer -identity $computername -replace @{extensionattribute5=$is_remote}

the error follows:

set-adcomputer : invalid type 'system.management.automation.psobject'.parameter name: extensionattribute5
@ c:\temp\test.ps1:24 char:15
+ set-adcomputer <<<<  -identity $computername -replace @{extensionattribute5=$
is_remote}
    + categoryinfo          : invalidargument: (testpsscript:adcomputer) [set-adcomputer], argumentexception
    + fullyqualifiederrorid : invalid type 'system.management.automation.psobject'.
    parameter name: extensionattribute5,microsoft.activedirectory.management.commands.setadcomputer

if replace function setting the variable, works fine:

$is_remote = "yes"
$computername = "testpsscript"

set-adcomputer -identity $computername -replace @{extensionattribute5=$is_remote}

anyone?


i think there may typo can't bee seen when pasted code here.

display value of $is_remote before applying set-adcomputer , see if has correct value

if it's ok try putting value in quotation evaluate first

set-adcomputer -identity $computername -replace @{extensionattribute5="$is_remote"}



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file