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 (215k 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

If the user name submitted is "jhon doe" all of the users properties will be lower case. We want it to force it to be "Jhon Doe" even if it was submitted in lower case.

asked Aug 31 by raul.ramirez (50 points)
0 votes
1 answer

Hallo Everyone I've seen the Report for Exchange Mailboxes with OU, Send on Behalf, Full Rights and Send As Rights: https://www.adaxes.com/questions/ ... . Example: User: Peter.Steinmann Identity: Which Mailboxes AccessRights: FullAccess Kind regards,

asked Jul 6 by Sandberg94 (320 points)
0 votes
1 answer

How can I create a script that does these things For internal audit. objective Even removing all groups of a disconnected user, we will still know which groups the ... in the created group (audit)-sAMAccountName-access add the (user)-sAMAccountName in members

asked Jul 2 by alancardoso (20 points)
0 votes
1 answer

We just busted our licence limit of 400, but we are only 320 employees. All the extras are either service accounts, external contractors accounts or old user accounts ... is reinstated on the 'managed accounts' list? Thank you for the guidance, Louis

asked Apr 11 by lw.fa (60 points)
2,807 questions
2,541 answers
6,613 comments
64,595 users