Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PowerShell Script to modify session attributes in user objects

Posted on 2014-10-22
12
Medium Priority
?
311 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
  • 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
Technology Partners: 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: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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 …
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

916 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