Link to home
Start Free TrialLog in
Avatar of cawasaki
cawasaki

asked on

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
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null } | select SamAccountName, msRADIUSFramedIPAddress
Avatar of cawasaki
cawasaki

ASKER

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/
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 ".")
}
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
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

}
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
$result = @()
foreach( $user in $users)
{  
$result += $user.SamAccountName
$result += $val = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)
}

$result| export-csv c:\results.csv
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

instead of this at the end: export-csv c:\results.csv
use the following:

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

i have

username
ipadress
username
ipadress
username
ipadress
....

not possible to get:
username,ipadress

thanks
replace foreach block with the following:

foreach( $user in $users)
{  
$result += "$user.SamAccountName, DigitToStrIPAddress($user.msRADIUSFramedIPAddress)"
}
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)
foreach( $user in $users)
{  
$acc = $user.SamAccountName
$ipadd = DigitToStrIPAddress($user.msRADIUSFramedIPAddress)

$result += "$acc, $ipadd"
}
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

thank you for help :)