Solved

Using a csv file to edit users dialin settings

Posted on 2013-01-23
15
916 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes you are right.. you need to use the header of column from csv..
0
 

Author Comment

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

Author Comment

by:Kasper Katzmann
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

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

Expert Comment

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

Author Comment

by:Kasper Katzmann
Comment Utility
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
Comment Utility
It returns the two users in my sample
0
 

Author Comment

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

Expert Comment

by:Subsun
Comment Utility
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
Comment Utility
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
Comment Utility
No problem.. I'm glad I could help.. :-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

9 Experts available now in Live!

Get 1:1 Help Now