Solved

Using a csv file to edit users dialin settings

Posted on 2013-01-23
15
936 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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