Solved

Using a csv file to edit users dialin settings

Posted on 2013-01-23
15
918 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
 

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now