![]() ![]() This is a non-PowerShell command but we can still just as easily use it from within PowerShell. There are a few ways to do that but I’ve chosen to use the quser command. We can even log off all users if we so desire.īefore we get too crazy though, we first need to figure out how to find which users are logged into a remote computer. Using PowerShell, we can create a script that reaches out to one or more remote Windows computers, checks to see if anyone is logged in and, if so, logs them out. It seems like every time you’d like to do some maintenance on the computer that requires a user logging out, they don’t seem to do it or the computer is idling with them logged in! Luckily, we can take this into our own hands by forcing a logoff remote from another computer. This is especially useful when you are trying to do maintenance.Įnd users are sometimes logged into their computers for far too long. #Write-Output "Script execution time: $scriptExecutionMin min $scriptExecutionSec sec.Here is a quick and easy way to remotely log off end users who are still logged into their computers. #$scriptExecutionSec = ($endDateTime.Subtract($startDateTime).Seconds) #$scriptExecutionMin = ($endDateTime.Subtract($startDateTime).Minutes) # Optional block to output script execution time: New-RDCManFile -username "useraccount-admin" -outputPath "$outputPath\$filePrefix" -computerArray $sqlservers $sqlservers = Get-ADGroupMember -Identity "sql-servers" | Get-ADComputer | Select-Object -property name,dnshostname | Sort-Object -Property name # Example to output a list of all SQL servers (from an AD security group): New-RDCManFile -username "useraccount2-admin" -outputPath "$outputPath\$filePrefix" -computerArray $allComputers New-RDCManFile -username "useraccount-admin" -outputPath "$outputPath\$filePrefix" -computerArray $allComputers ![]() # Call the function to generate the file: $allComputers = $computerObjects1 + $computerObjects2 | Sort-Object $computerObjects2 = Get-ADComputer -SearchBase "OU=Domain Controllers,DC=lunet,DC=lboro,DC=ac,DC=uk" -LDAPFilter "(operatingsystem=*Windows server*)" | Select-Object -property name,dnshostname $computerObjects1 = Get-ADComputer -SearchBase "OU=MemberServers,DC=lunet,DC=lboro,DC=ac,DC=uk" -LDAPFilter "(operatingsystem=*Windows server*)" | Select-Object -property name,dnshostname ![]() # Example to get a list of MemberServers and Domain Controllers: Remove-Item $home\RDCMan-template.xml -Force $template | Out-File $home\RDCMan-template.xml -encoding UTF8 # Output $template to a temporary XML file: $template = $outputPath + "-$username" + ".rdg" This needs to be indented to the margin so that the output XML file has no indent. Import-Module ActiveDirectory -ErrorAction Stop $EnableEmail = Read-Host("Enable email, 0 = No, 1 = Yes : ") ![]() $DebugPreference = "Continue" # Write-Debug commands. #* Purpose: Why and how you modified the script in brief. Rather than call the script multiple times from Task Scheduler (i.e defining the parameters at the script level) I just schedule it once (on Monday morning) and within the script call the function multiple times for all the users who need a file. Pass the function a username, an array of computer objects and an output path and you get an RDCMan file with the computers of your choice for the user of your choice. Thankfully Jan Egil Ring had done some of the work for me, but I modified it slightly and turned it into a more suitable script for our environment. rdg file produced by RDCMan is actually just an XML file (discovered by dropping the file into Notepad) so I figured that it’d be quite straightforward to automate the production of this using PowerShell, grabbing a list of servers from AD (or. With some 200 servers (at the time) this was a potentially painstaking task, and one that I didn’t want to undertake if there was an easier alternative. The downside to this simple tool though is that you have to add servers manually, one by one. I was very relieved to find RDCMan produced by Microsoft. It made absolutely no sense to have to open multiple unique Remote Desktop / mstsc.exe windows to every server you wanted to work on. I found this utility about 3 years ago when searching for an easier way to manage remote desktop connections to multiple Windows servers. The author had discovered an extremely handy tool for managing multiple remote desktop connections and seemingly puzzled over why it wasn’t more well known my thoughts exactly. When I stumbled across this article on IT Pro in June this year a knowing smile crept across my face. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |