Solved

Using a csv file to edit users dialin settings

Posted on 2013-01-23
15
922 Views
Last Modified: 2013-01-24
I have a csv file (dialin.csv) that contains users who must have their dialin properties set in Active Directory. The list is formated like this (user;ip):
akr;10.3.86.34
lgt;10.3.86.76
jrv;10.3.86.23
and so on...


I have found this script (http://calumpowell.com/tag/dial-in/) and now I would like to use the csv file in combination with the script to update all the users in one operation.
function Convert-IP {  
param(  
	[Parameter(ValueFromPipeline=$true)]  
	[String]$IPAddress = "127.0.0.1" )  

	$octetsDecimal = $IPAddress -split "\." 

	$octetsBinary = $octetsDecimal | % { [convert]::ToString($_, 2) }  

	$octetsBinary = $octetsBinary | % { ("0" * (8 - $_.length)) + $_ }  

	$octetsBinary | % { $binaryIP += $_ }  

	$integerIP = [convert]::ToInt32($binaryIP, 2)  

	return $integerIP 
} 

$IP = Convert-IP $staticip
Set-QADUser -Identity "Testuser" -IncludedProperties @("msNPAllowDialin", "msRADIUSFramedIPAddress", "msRASSave

Open in new window

Can anyone help me with this?

Regards
Kasper
0
Comment
Question by:Kasper Katzmann
  • 9
  • 6
15 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 38810865
What is the value you want to update for "msNPAllowDialin" in AD?
Also i think the code you posted is incomplete, what is the correct attribute name of "msRASSave" and the value you want to update?
0
 

Author Comment

by:Kasper Katzmann
ID: 38810935
Oops - Copy/Paste has failed. The last part (after the function) should be:
$IP = Convert-IP "10.20.30.40"
Set-QADUser -Identity "Testuser" -IncludedProperties @("msNPAllowDialin", "msRADIUSFramedIPAddress", "msRASSavedFramedIPAddress") -ObjectAttributes @{msNPAllowDialin=$true;msRADIUSFramedIPAddress=$IP;msRASSavedFramedIPAddress=$IP}

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38811030
Try
function Convert-IP {  
param(  
	[Parameter(ValueFromPipeline=$true)]  
	[String]$IPAddress = "127.0.0.1" )  

	$octetsDecimal = $IPAddress -split "\." 

	$octetsBinary = $octetsDecimal | % { [convert]::ToString($_, 2) }  

	$octetsBinary = $octetsBinary | % { ("0" * (8 - $_.length)) + $_ }  

	$octetsBinary | % { $binaryIP += $_ }  

	$integerIP = [convert]::ToInt32($binaryIP, 2)  

	return $integerIP 
} 

Import-Csv "dialin.csv" | %{
$IP = Convert-IP $_.ip
Set-QADUser -Identity $_.user -IncludedProperties @("msNPAllowDialin", "msRADIUSFramedIPAddress", "msRASSavedFramedIPAddress") -ObjectAttributes @{msNPAllowDialin=$true;msRADIUSFramedIPAddress=$IP;msRASSavedFramedIPAddress=$IP}
}

Open in new window

CSV format
user,ip
akr,10.3.86.34
lgt,10.3.86.76
jrv,10.3.86.23

Open in new window

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:Kasper Katzmann
ID: 38811228
As far as I understand, I have to used titles in the first row? Not that it is a problem, just so I can understand.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38811248
Yes you are right.. you need to use the header of column from csv..
0
 

Author Comment

by:Kasper Katzmann
ID: 38811351
Great. I test it first time tomorrow, when I get to work.
0
 

Author Comment

by:Kasper Katzmann
ID: 38813443
I get this error when i try to run it:
Set-QADUser : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Supply an argument that
is not null or empty and then try the command again.
At C:\scripts\UpdateDialInBasedOnCSV.ps1:21 char:22
+ Set-QADUser -Identity <<<<  $_.user -IncludedProperties @("msNPAllowDialin", "msRADIUSFramedIPAddress", "msRASSavedFr
amedIPAddress") -ObjectAttributes @{msNPAllowDialin=$true;msRADIUSFramedIPAddress=$IP;msRASSavedFramedIPAddress=$IP}
    + CategoryInfo          : InvalidData: (:) [Set-QADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlet
   s.SetUserCmdlet

Open in new window

0
 

Author Comment

by:Kasper Katzmann
ID: 38813445
I have verified that I'm able to read the csv file
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38813460
What is the result for Import-Csv "dialin.csv" | % {$_.User}
0
 

Author Comment

by:Kasper Katzmann
ID: 38813464
Changed the ;'s with ,'s and now it almost works. I have made a sample csv containing my self and one other user. It changes the settings for my profile, but not for the other one. Here's the error returned:
Set-QADUser : Adgang nægtet.
At C:\scripts\UpdateDialInBasedOnCSV.ps1:21 char:12
+ Set-QADUser <<<<  -Identity $_.user -IncludedProperties @("msNPAllowDialin", "msRADIUSFramedIPAddress", "msRASSavedFr
amedIPAddress") -ObjectAttributes @{msNPAllowDialin=$true;msRADIUSFramedIPAddress=$IP;msRASSavedFramedIPAddress=$IP}
    + CategoryInfo          : NotSpecified: (:) [Set-QADUser], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdl
   ets.SetUserCmdlet

Open in new window

0
 

Author Comment

by:Kasper Katzmann
ID: 38813466
It returns the two users in my sample
0
 

Author Comment

by:Kasper Katzmann
ID: 38813469
Ohh, and by the way. Set-QADUser : Adgang nægtet. means Set-QADUser : Access Denied.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38813480
UnauthorizedAccessException looks like permission error.. Did you try running PowerShell console with Run as administrator? Also make sure the account which you are using have permission to edit the attribute..
0
 

Author Comment

by:Kasper Katzmann
ID: 38813500
It works. First I ran it as administrator. But I have to run it as Domain Admin, not just Local Admin - DOH! Maybe I should have stayed in bed...

Thanks a lot for takeing time to help.

/Kasper
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38813530
No problem.. I'm glad I could help.. :-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Set OWA language and time zone in Exchange for individuals, all users or per database.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question