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
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
get-aduser -filter * -Properties 'msRADIUSFramedIPAddress' | ? { $_.msRADIUSFramedIPAddress -ne $null } | select SamAccountName, msRADIUSFramedIPAddress
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/
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($Digit 9IPAddress ) {
$bin=[convert]::ToString([ int32]$Dig it9IPAddre ss,2).PadL eft(32,'0' ).ToCharAr ray()
$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 ".")
}
Function DigitToStrIPAddress($Digit
$bin=[convert]::ToString([
$A=[convert]::ToByte($bin[
$B=[convert]::ToByte($bin[
$C=[convert]::ToByte($bin[
$D=[convert]::ToByte($bin[
return $($A,$B,$C,$D -join ".")
}
ASKER
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
thanks for help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Replace the foreach block with the following block and test:
-------------------------- ---------
foreach( $user in $users)
{
$val = DigitToStrIPAddress($user. msRADIUSFr amedIPAddr ess)
$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
}
--------------------------
foreach( $user in $users)
{
$val = DigitToStrIPAddress($user.
$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
}
ASKER
new error code:
and on csv file i have only one entry user with correct IP
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
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. msRADIUSFr amedIPAddr ess)
}
$result| export-csv c:\results.csv
foreach( $user in $users)
{
$result += $user.SamAccountName
$result += $val = DigitToStrIPAddress($user.
}
$result| export-csv c:\results.csv
ASKER
you mean like this:
no error but on result.csv i have 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
no error but on result.csv i have this:
#TYPE System.String
"Length"
"17"
"13"
"15"
"13"
"13"
"12"
"16"
instead of this at the end: export-csv c:\results.csv
use the following:
out-file c:\results.csv
use the following:
out-file c:\results.csv
ASKER
now is good, but the format is not,
i have
username
ipadress
username
ipadress
username
ipadress
....
not possible to get:
username,ipadress
thanks
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. msRADIUSFr amedIPAddr ess)"
}
foreach( $user in $users)
{
$result += "$user.SamAccountName, DigitToStrIPAddress($user.
}
ASKER
still not good, now i have this form:
CN=user,OU=test,OU=test1,D C=domain,D C=com.SamA ccountName , DigitToStrIPAddress(CN=use r,OU=test, OU=test1,D C=domain,D C=com.msRA DIUSFramed IPAddress)
CN=user,OU=test,OU=test1,D
foreach( $user in $users)
{
$acc = $user.SamAccountName
$ipadd = DigitToStrIPAddress($user. msRADIUSFr amedIPAddr ess)
$result += "$acc, $ipadd"
}
{
$acc = $user.SamAccountName
$ipadd = DigitToStrIPAddress($user.
$result += "$acc, $ipadd"
}
ASKER
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
ASKER
thank you for help :)