Solved

PowerShell Script to modify session attributes in user objects

Posted on 2014-10-22
12
276 Views
Last Modified: 2014-10-22
I have a script I have written to modify the '-TsMaxDisconnectionTime' to 15 minutes against a list of users in a csv file. the script runs without any incidents or errors. At the end of my time line and no longer have the time to research... any help would be greatly appreciated...

Import-Module ActiveDirectory

Add-PSSnapin Quest.ActiveRoles.ADManagement

$users = import-csv C:\temp\gisuserscfw.csv | ForEach-Object {Get-QADUser -SamAccountName $_.SamAccountName}
{
Set-QADUser -Identity $User -TsMaxDisconnectionTime "00:15"
}
0
Comment
Question by:TXRhino
[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
  • 7
  • 5
12 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40397002
So what is the question? You said it runs with no errors?
0
 

Author Comment

by:TXRhino
ID: 40397020
Sorry... it runs with no errors but dosent make the change... when I run it per user it correctly changes the attribute to 15 minutes... it has something to do with the way I am calling the csv file...
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40397023
This will work. You just have to make sure your CSV file has a Column Header named SamAccountName

Import-Module ActiveDirectory
Add-PSSnapin Quest.ActiveRoles.ADManagement
$Users = Import-Csv C:\temp\gisuserscfw.csv | ForEach-Object { Set-QADUser -Identity $_.SamAccountName -TsMaxDisconnectionTime '00:15:00' } 

Open in new window

0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:TXRhino
ID: 40397051
I do have the header named 'SamAccountName' here is the error it returns... I also insured that I do have the actual username aka SamAccountName in the csv file.


Set-QADUser : Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
At line:3 char:64
+ $Users = Import-Csv C:\temp\gisuserscfw.csv | ForEach-Object { Set-QADUser -Iden ...
+                                                                ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-QADUser], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.SetUserCmdlet
0
 

Author Comment

by:TXRhino
ID: 40397054
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40397175
Give this a shot. I would make sure that your csv file is a true CSV. Open with Notepad and make sure it is comma separated and not tab separated or any other

Import-Module ActiveDirectory
Add-PSSnapin Quest.ActiveRoles.ADManagement
Import-Csv C:\users.csv | % {
$user = $_.SamAccountName
Set-QADUser $user -TsMaxDisconnectionTime "00:15"}

Open in new window

0
 

Author Comment

by:TXRhino
ID: 40397371
Same result... I even created a new export of the list to ensure the comma separated value was correct. I ran the code against both and both I get the same result...

Set-QADUser : Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
At line:5 char:1
+ Set-QADUser $user -TsMaxDisconnectionTime "00:15"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-QADUser], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.SetUserCmdlet

I wonder if I should save it as a script and run in it with in the ISE?
0
 

Author Comment

by:TXRhino
ID: 40397381
that did it... I wonder why running as a script was successful but not from with in ISE?
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40397385
The script you are trying to run uses Quest commandlets, do you have those installed on your PC?
0
 

Author Closing Comment

by:TXRhino
ID: 40397388
thanks for the assistance... let me know your thoughts on running as a script vs. ISE thanks again...
0
 

Author Comment

by:TXRhino
ID: 40397391
yes... I even included the command in the script to load them into the session  Add-PSSnapin Quest.ActiveRoles.ADManagement
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40397393
hmm, that's interesting.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

635 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