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
1 answer

We've requested a quote for 2500 licenses and plan on downloading a trial. However, I want to be certain of when the 30-day trial starts ticking...upon the initial download of the software, or only after the downloaded software is installed in our environment?

asked Apr 22, 2021 by MRBruce (110 points)
0 votes
1 answer

We are using the below snippet to grab the email of a single custom attribute object. Can I get guidance on the best way to modify this to get all the emails of each ... "The user specified in parameter 'MyParameter' has no email address. ", "Information") }

asked 4 days ago by msheppard (660 points)
0 votes
1 answer

We are wanting to display all values entered into a multi value text attribute in an email sent by Adaxes. What we've found is that only the first entry into the array ... Entry" Is there a way to reference the variable so that it displays all entries? Thanks

asked Dec 12 by msheppard (660 points)
3,589 questions
3,278 answers
8,303 comments
548,153 users