VMware Cloud Community
RobMokkink
Expert
Expert

remove-vmhostaccount

After seeing the post for add localuser, i decided it would be nice to dich my bash script for adding local users to the esx hosts. This is done by enumerating a security group in AD.

The script to add users works, but now i want to remove users as well. But it looks like there is a bug in the remove-vmhostaccount cmd-let:

For exameple:

get-vmhostaccount -id test | remove-vmhostaccount

Remove-VMHostAccount : Pipeline input cannot be processed because the default v

alue of parameter 'HostAccount' cannot be retrieved. Cannot set property value

because "HostAccount" is a write-only property.

I also tried:

get-vmhostaccount -id test | remove-vmhostaccount -hostaccount test

Same error. What is wrong here?

0 Kudos
3 Replies
admin
Immortal
Immortal

Looks like a pipeline issue. To work around it try

remove-vmhostaccount -hostaccount (get-vmhostaccount accountname)

RobMokkink
Expert
Expert

Carter,

Thanks. I already figured that out :smileygrin: But i wasn't in the oppurtunity to respond.

Everything works.

I do:

remove-vmhostaccount -hostaccount(get-vmhostaccount -d $USER) -confirm:$False

One thing i noticed is that /home doesn't get cleaned up after issuing remove-vmhostaccount.

I almost have the script ready to dynamically add or remove usersaccounts to esx host how belong to a particular security group.

0 Kudos
hharold
Enthusiast
Enthusiast

Hi Rob,

Did you ever worked around the issue that /home doesn't get cleaned up after issuing remove-vmhostaccount ?

Regards,

Harold

0 Kudos