Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerShell Script to modify session attributes in user objects

Posted on 2014-10-22
12
Medium Priority
?
297 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

661 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