powershell script to export msRADIUSFramedIPAddress attribute

hello,

i need a powershell script to export the msRADIUSFramedIPAddress attribute from Active directory user.

this attribute contain a static IP address, but i think its in binary format!.

the script must get user from specific OU

the script must export only user from AD have the msRADIUSFramedIPAddress atribute ON (not empty).

thanks for help
cawasakiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null } | select SamAccountName, msRADIUSFramedIPAddress
0
cawasakiAuthor Commented:
hi,

ok but i get the value on this form:  169090600

like this link, i think we need a function or other script to modify the value???

http://calumpowell.com/2012/05/02/allow-dial-in-and-assign-static-ip-addresses-in-active-directory-with-powershell/
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Use this function:
Function DigitToStrIPAddress($Digit9IPAddress) {
 $bin=[convert]::ToString([int32]$Digit9IPAddress,2).PadLeft(32,'0').ToCharArray()
 $A=[convert]::ToByte($bin[0..7] -join "",2)
 $B=[convert]::ToByte($bin[8..15] -join "",2)
 $C=[convert]::ToByte($bin[16..23] -join "",2)
 $D=[convert]::ToByte($bin[24..31] -join "",2)
 return $($A,$B,$C,$D -join ".")
}
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

cawasakiAuthor Commented:
yes but what i can use it with my export, i have 500 account with msRADIUSFramedIPAddress value, i need it directly on csv exported file.

thanks for help
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Function DigitToStrIPAddress($Digit9IPAddress) {
 $bin=[convert]::ToString([int32]$Digit9IPAddress,2).PadLeft(32,'0').ToCharArray()
 $A=[convert]::ToByte($bin[0..7] -join "",2)
 $B=[convert]::ToByte($bin[8..15] -join "",2)
 $C=[convert]::ToByte($bin[16..23] -join "",2)
 $D=[convert]::ToByte($bin[24..31] -join "",2)
 return $($A,$B,$C,$D -join ".")
}

$users = get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null }

foreach( $user in $users)
{  
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Name -value $user.SamAccountName
$obj | Add-Member -type NoteProperty -name IPAddr -value DigitToStrIPAddress($user.msRADIUSFramedIPAddress)

    $output += $obj

}

$output | export-csv c:\results.csv
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cawasakiAuthor Commented:
i have error:

Add-Member : The SecondValue parameter is not necessary for a member of type "NoteProperty" and should not be specified. Do not specify the SecondValue paramete
ding members of this type.
At C:\scripts\get\get.ps1:16 char:18
+ $obj | Add-Member <<<<  -type NoteProperty -name IPAddr -value DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
    + CategoryInfo          : InvalidOperation: (:) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand

Method invocation failed because [System.Object] doesn't contain a method named 'op_Addition'.
At C:\scripts\get\get.ps1:18 char:15
+     $output += <<<<  $obj
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Open in new window

0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Replace the foreach block with the following block and test:
-----------------------------------
foreach( $user in $users)
{  
$val = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Name -value $user.SamAccountName
$obj | Add-Member -type NoteProperty -name IPAddr -value $val

    $output += $obj

}
0
cawasakiAuthor Commented:
new error code:

Method invocation failed because [System.Object] doesn't contain a method named 'op_Addition'.
At C:\scripts\get\ff.ps1:10 char:15
+     $output += <<<<  $obj
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Object] doesn't contain a method named 'op_Addition'.
At C:\scripts\get\ff.ps1:10 char:15
+     $output += <<<<  $obj
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Open in new window


and on csv file i have only one entry user with correct IP
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
$result = @()
foreach( $user in $users)
{  
$result += $user.SamAccountName
$result += $val = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
}

$result| export-csv c:\results.csv
0
cawasakiAuthor Commented:
you mean like this:
$result = @()
$users = get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null }
foreach( $user in $users)
{  
$result += $user.SamAccountName
$result += $val = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
}

$result| export-csv c:\results.csv

Open in new window



no error but on result.csv i have this:

#TYPE System.String
"Length"
"17"
"13"
"15"
"13"
"13"
"12"
"16"

Open in new window

0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
instead of this at the end: export-csv c:\results.csv
use the following:

out-file c:\results.csv
0
cawasakiAuthor Commented:
now is good, but the format is not,

i have

username
ipadress
username
ipadress
username
ipadress
....

not possible to get:
username,ipadress

thanks
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
replace foreach block with the following:

foreach( $user in $users)
{  
$result += "$user.SamAccountName, DigitToStrIPAddress($user.msRADIUSFramedIPAddress)"
}
0
cawasakiAuthor Commented:
still not good, now i have this form:

CN=user,OU=test,OU=test1,DC=domain,DC=com.SamAccountName, DigitToStrIPAddress(CN=user,OU=test,OU=test1,DC=domain,DC=com.msRADIUSFramedIPAddress)
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
foreach( $user in $users)
{  
$acc = $user.SamAccountName
$ipadd = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)

$result += "$acc, $ipadd"
}
0
cawasakiAuthor Commented:
i have resolved the problem with modify the script little:

$all = @()
$time = 0


$users = get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null }
foreach( $user in $users)
{

$IP = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
$result = new-object psobject
$result | add-member noteproperty sAMAccountName $user.SamAccountName
$result | add-member noteproperty IP $IP

$all += $result

}


$all | export-csv c:\resultsssss.csv -encoding UTF8

Open in new window

0
cawasakiAuthor Commented:
thank you for help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.