0 votes

Hi there !

I wan to implement a custom command that will remove a user from all disitribution groups :

Import-Module Adaxes
Get-AdmGroup -Filter { mail -like "*" } | Where { (Get-AdmGroupMember $_.SamAccountName -AdaxesService eumsqres10.eu.loi.net | foreach {$_.SamAccountName -eq "%sAMAccountName%" }) -eq $True } | foreach { Remove-AdmGroupMember $_.SamAccountName -Members "%mailNickname%"}

But it gives me an error : Cannot invoke this function because the current host does not implement it.

I can't see what i'm doing wrong...

Thanks

Stephen

by (800 points)

1 Answer

0 votes
by (18.0k points)

Hello Stephen,

Try the following script:

Import-Module Adaxes
$username = "%username%"
$domainName = $Null

Get-AdmPrincipalGroupMembership $username -server $domainName -adaxesservice localhost | 
  Get-AdmGroup -Properties mail -server $domainName | Where {$_.mail -ne $NULL} | 
  Remove-AdmGroupMember -member $username -server $domainName  -Confirm:$False
0

Wow, pretty optimized :-)

i'd have liked to know why my script, even not optimized, works in interactive mode and not in a custom command.

But thanks anyway ;-)

0

i'd have liked to know why my script, even not optimized, works in interactive mode and not in a custom command.

Because the Remove-AdmGroupMember cmdlet requires a confirmation. To fix it you just need to add the following parameter: -Confirm:$False.

Get-AdmGroup -Filter { mail -like "*" } | Where { (Get-AdmGroupMember $_.SamAccountName -AdaxesService eumsqres10.eu.loi.net | foreach {$_.SamAccountName -eq "%sAMAccountName%" }) -eq $True } | foreach { Remove-AdmGroupMember $_.SamAccountName -Members "%mailNickname%" -Confirm:$False}

Related questions

0 votes
1 answer

I found these codes: http://www.adaxes.com/sdk/SampleScripts ... lFlow.html I created custom command(action is "run powershell script") with the following codes and added ... host does not implement it. Can anyone help me look into this ? Really appreciate!

asked Jul 7, 2015 by tony (50 points)
0 votes
1 answer

Hey guys, First time Adaxes user, and let me say, we absolutely love the product! Quick question though.... As a part of our account de-provisioning process, we ... exact same code in a regular powershell window with no problem. Any thoughts? Any alternatives?

asked Sep 6, 2012 by sco.robinso (20 points)
0 votes
1 answer

I wrote a small script to get Mail Queue stats on all my Exch 2010 Hub Tansport servers. It works in EMS but when I configure as a Custom Command it returns an ... $HubServer) { get-Queue -server $server -EA inquire -SortOrder -messagecount write-output "" }

asked Dec 11, 2012 by mdeflice (350 points)
0 votes
1 answer

I don't understand how you would use this searcher function. Can you show me in this example? Import-Module ImportExcel #set up variables $currentTime = Get-Date ... $Context.BindToObjectByDN($NewU) $U.Put("adm-CustomAttributeBoolean6", $False) $U.SetInfo() }

asked Dec 14, 2023 by mightycabal (1.0k points)
0 votes
1 answer

When will this function/feature be available?

asked Jun 5, 2023 by wintec01 (1.5k points)
3,548 questions
3,239 answers
8,232 comments
547,814 users