0 votes

We need to use two attributes for our new Cisco phone implementation. The ipphone attribute is being set with a 11 digit number that always starts with 91, but we need to present this number with the 91 stripped off in another attribute for an application that works with the phones. I tried to set a business rule to run a powershell script after the user is created and when ipphone is not empty

import-module adaxes

    $ipphone = %ipPhone%
    $BOCMatching = $ipphone.trimstart("91")

    set-admuser %distinguishedName% -add @{otherIpPhone = $BCOMMatching}

So nothing fancy, but when I test this I receive

Method invocation failed because [System.Int64] doesn't contain a method named 'trimstart'

But I am able to use trimstart in a powershell cmd window without issue

Can I make my script work or is there a better way to strip the 91 off of the ipphone attribute and set it to otheripphone?

Thanks

by (1.2k points)
0

I have a similar script - this PS snippet strips the first 5 characters from a variable (in this case the name of a server, where the first characters in the naming syntax aren't needed in the script object):-

$ServerObject = "%cn%".Substring(5)

Rgds

1 Answer

0 votes
by (216k points)

Hello,

First of all, firegoblin, thanks for your active participation on our forum! :)

As to the initial question, the thing is that since the IP phone consists of numbers only, PowerShell automatically converts the value from the String type to the Integer type, and the TrimStart method is not supported for integers. To remedy the issue, you need to enclose the %ipPhone% value reference in double quotes.

Also, you can set the trimmed value with the help of Adaxes ADSI API without the need to use Adaxes cmdlets. This will make the script work faster and avoid unnecessary loads of Adaxes PowerShell Module. The resulting script will be:

$ipphone = "%ipPhone%"
$BOCMatching = $ipphone.TrimStart("91")
$Context.TargetObject.Put("otherIpPhone", $BCOMMatching)
$Context.TargetObject.SetInfo()
0

Bingo Bango!!

That worked. Thanks for everyone's posts

0

Hello

Another question regarding "Method invocation failed....."

Example, where I'm trying to get the index of a Foreach loop:

Import-Module Adaxes

$GroupsToCheck = "A", "B", "C", "D"
Foreach ($TargetGroup in $GroupsToCheck) 
{
    $TargetGroupIndex = $GroupsToCheck.IndexOf($TargetGroup)
}

Adaxes do not like ".IndexOf", throwing a "Method invocation failed....."

Why is that ? The code works fine in Windows Powershell ISE ?

Thanks

0

Would explictily defining the variable as an array help i.e. $GroupsToCheck = @("A", "B", "C", "D")

Maybe your real AD group names are causing an issue (believe me, I'm no expert on this, but I always explicitly define my arrays as I have had issues in the past with 'auto' detection of things going screwy!).

0

@firegoblin

Thanks for replying.

However - it is the method ".IndexOf" that causes an error in Adaxes.

Maybe something in Adaxes I did not install ?

Best regards

0

No worries!

If it's of interest:-

http://stackoverflow.com/questions/1899 ... ion-failed

When they talk about this being a method of a string variable only (and seeing different behaviour based on how it's invoked etc) that's exactly the sort of thing that I have trouble with when I try to do things to variables and get the wrong types!

0

It would be a great help, if Adaxes Script editor had intellisense on these methods.

0

Hello,

Example, where I'm trying to get the index of a Foreach loop:

...

Adaxes do not like ".IndexOf", throwing a "Method invocation failed....."
Why is that ? The code works fine in Windows Powershell ISE ?

IndexOf is a static method of System.Array, and you need to use a bit different syntax to call it. It looks like PowerShell 3.0 or higher that is most probably used by the ISE allows more flexibility in syntax. To achieve what you want, use the following code:

$array = "A", "B", "C", "D"

Foreach ($string in $array)
{
    $index = [System.Array]::IndexOf($array, $string)
}

It would be a great help, if Adaxes Script editor had intellisense on these methods.

Thanks for the suggestion, but currently we are not planning that.

Related questions

0 votes
1 answer

As part of our (legacy) deprovisioning script (run by hand / not part of Adaxes), the user's home folder is moved to a folder tree of the format: !disabled\< ... have to resort to a PS script for that rather than allowing Adaxes to handle it internally.

asked Oct 6, 2014 by bradenmcg (260 points)
0 votes
1 answer

I often need to step through a script in the ISE debugger to troubleshoot or verify its operation. My problem is that I haven't been able to find a way to do ... way to interactively run a script uses the $Context variable so you can step through/debug it?

asked Dec 18, 2016 by rbeu (100 points)
0 votes
0 answers

We've uninstalled the previous version via the "add/Remove Programs" feature in Windows 10, but we still get an error saying that another version of the client is still installed and won't allow us to run the .MSI installer. How can we get around this?

asked Feb 15 by MShep (80 points)
0 votes
1 answer

I am trying to use this script from the script repository: https://www.adaxes.com/script-repository/enable-mfa-with-phone-number-for-a-user-in-microsoft-365-s686.htm I ... if I just didn't install it correctly because Adaxes Powershell doesn't recognize it.

asked Oct 10, 2023 by ocanizales (40 points)
0 votes
1 answer

On the last working day of a user I should always lock (disable) his account at 5pm local time. Since our company is worldwide, I need a good idea how to easily find out when it is 5pm for this user (always local time). Is there a simple solution in adaxes ?

asked Jun 13, 2023 by Beat Ott (40 points)
3,326 questions
3,026 answers
7,727 comments
544,681 users