variable not expanding in command, unsure why


hello, have relatively straightforward problem in script making, has variable not expanding unsure why , not sure else can further debug issue, advise appreciated.

basically have variable containing pc name:

$pcname="mypc"

and want use in script pc:

get-adcomputer -filter {name -like "$pcname"} -properties lastlogondate 

however, command returns nothing if manually put in name:

get-adcomputer -filter {name -like "mypc"} -properties lastlogondate 

it work properly.

what doing wrong?

i have tried:

get-adcomputer -filter {name -like "$($pcname)"} -properties lastlogondate 

which not work, me looks problem shell not expanding variable inside filter block, i'm not sure why happen.

edit:

i have found out doing:

get-adcomputer -filter {name -like $pcname} -properties lastlogondate 

does work, not me completely, search "$pcname*" continues fail, realize can append * variable before line, still figure out whats going on here why not expand string expected in filter block.


try:

get-adcomputer -filter "name -like `"$pcname*`""



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Azure MFA with Azure AD and RDS

Failed to setup initiator portal. Error status is given in the dump data.

Invalid pointer on gpresult /h gpreport.html