PowerShell - User session managment
I have this PowerShell script that logs off users with IDLE time greater that 1 hour:
#Force script to run.
Set-ExecutionPolicy Unrestricted -force
#Check connected users and save output.
quser|out-file C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Read output with logged in users.
$file = Get-Content C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Obtain IDLE time by using patters.
$pattern = "Disc(.*?)11"
#Obtaons session ID by using patther.
$pattern2 = "adminagora(.*?)Disc"
#Execute query using above patterns.
$result = [regex]::Match($file,$pattern).Groups[1].Value
$result2 = [regex]::Match($file,$pattern2).Groups[1].Value
#Trim file and save both session id and username.
$result = $result -replace(' ','')
$result |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUser.txt
$result2 = $result2 -replace(' ','')
$result2 |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUserID.txt
#If IDLE time is greater than 1 hour user is disconnected.
if ($result -gt '1:00'){
logoff $result2
}
else{
write-host "No users with IDLE time greater than 1 hour found.No users to be logged off."
}
What I want to do is check if a cmd process is running or not, so the user can remain logged on untill this process has ended.
I tought that maybe by running this command get-process | where-object {$_.mainwindowhandle -ne 0} | select-object name, mainwindowtitle
and using regex to get only cmd processes it might do the trick, but it is a very primitive approach.
If you guys have any clue as to how to go about doing this, please let me know.
As requested, here's the output of quser:
Long story short
I need a way to know if something is being executed by CMD other than checking the CPU usage:
Thanks.
powershell session user-management ps1 usersession
|
show 2 more comments
I have this PowerShell script that logs off users with IDLE time greater that 1 hour:
#Force script to run.
Set-ExecutionPolicy Unrestricted -force
#Check connected users and save output.
quser|out-file C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Read output with logged in users.
$file = Get-Content C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Obtain IDLE time by using patters.
$pattern = "Disc(.*?)11"
#Obtaons session ID by using patther.
$pattern2 = "adminagora(.*?)Disc"
#Execute query using above patterns.
$result = [regex]::Match($file,$pattern).Groups[1].Value
$result2 = [regex]::Match($file,$pattern2).Groups[1].Value
#Trim file and save both session id and username.
$result = $result -replace(' ','')
$result |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUser.txt
$result2 = $result2 -replace(' ','')
$result2 |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUserID.txt
#If IDLE time is greater than 1 hour user is disconnected.
if ($result -gt '1:00'){
logoff $result2
}
else{
write-host "No users with IDLE time greater than 1 hour found.No users to be logged off."
}
What I want to do is check if a cmd process is running or not, so the user can remain logged on untill this process has ended.
I tought that maybe by running this command get-process | where-object {$_.mainwindowhandle -ne 0} | select-object name, mainwindowtitle
and using regex to get only cmd processes it might do the trick, but it is a very primitive approach.
If you guys have any clue as to how to go about doing this, please let me know.
As requested, here's the output of quser:
Long story short
I need a way to know if something is being executed by CMD other than checking the CPU usage:
Thanks.
powershell session user-management ps1 usersession
2
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)quser
– LotPings
2 days ago
Why the11
in$pattern
?
– Lieven Keersmaekers
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I executequser
the part that i want to extract is between Disc and the logon time. In this case11
was the day of month.
– Jorge Luís Segura Oñate
2 days ago
|
show 2 more comments
I have this PowerShell script that logs off users with IDLE time greater that 1 hour:
#Force script to run.
Set-ExecutionPolicy Unrestricted -force
#Check connected users and save output.
quser|out-file C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Read output with logged in users.
$file = Get-Content C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Obtain IDLE time by using patters.
$pattern = "Disc(.*?)11"
#Obtaons session ID by using patther.
$pattern2 = "adminagora(.*?)Disc"
#Execute query using above patterns.
$result = [regex]::Match($file,$pattern).Groups[1].Value
$result2 = [regex]::Match($file,$pattern2).Groups[1].Value
#Trim file and save both session id and username.
$result = $result -replace(' ','')
$result |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUser.txt
$result2 = $result2 -replace(' ','')
$result2 |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUserID.txt
#If IDLE time is greater than 1 hour user is disconnected.
if ($result -gt '1:00'){
logoff $result2
}
else{
write-host "No users with IDLE time greater than 1 hour found.No users to be logged off."
}
What I want to do is check if a cmd process is running or not, so the user can remain logged on untill this process has ended.
I tought that maybe by running this command get-process | where-object {$_.mainwindowhandle -ne 0} | select-object name, mainwindowtitle
and using regex to get only cmd processes it might do the trick, but it is a very primitive approach.
If you guys have any clue as to how to go about doing this, please let me know.
As requested, here's the output of quser:
Long story short
I need a way to know if something is being executed by CMD other than checking the CPU usage:
Thanks.
powershell session user-management ps1 usersession
I have this PowerShell script that logs off users with IDLE time greater that 1 hour:
#Force script to run.
Set-ExecutionPolicy Unrestricted -force
#Check connected users and save output.
quser|out-file C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Read output with logged in users.
$file = Get-Content C:UsersAdministratorDocumentsdisconectAgoraquser.txt
#Obtain IDLE time by using patters.
$pattern = "Disc(.*?)11"
#Obtaons session ID by using patther.
$pattern2 = "adminagora(.*?)Disc"
#Execute query using above patterns.
$result = [regex]::Match($file,$pattern).Groups[1].Value
$result2 = [regex]::Match($file,$pattern2).Groups[1].Value
#Trim file and save both session id and username.
$result = $result -replace(' ','')
$result |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUser.txt
$result2 = $result2 -replace(' ','')
$result2 |out-file C:UsersAdministratorDocumentsdisconectAgoragetDCUserID.txt
#If IDLE time is greater than 1 hour user is disconnected.
if ($result -gt '1:00'){
logoff $result2
}
else{
write-host "No users with IDLE time greater than 1 hour found.No users to be logged off."
}
What I want to do is check if a cmd process is running or not, so the user can remain logged on untill this process has ended.
I tought that maybe by running this command get-process | where-object {$_.mainwindowhandle -ne 0} | select-object name, mainwindowtitle
and using regex to get only cmd processes it might do the trick, but it is a very primitive approach.
If you guys have any clue as to how to go about doing this, please let me know.
As requested, here's the output of quser:
Long story short
I need a way to know if something is being executed by CMD other than checking the CPU usage:
Thanks.
powershell session user-management ps1 usersession
powershell session user-management ps1 usersession
edited 2 days ago
asked 2 days ago
Jorge Luís Segura Oñate
125
125
2
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)quser
– LotPings
2 days ago
Why the11
in$pattern
?
– Lieven Keersmaekers
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I executequser
the part that i want to extract is between Disc and the logon time. In this case11
was the day of month.
– Jorge Luís Segura Oñate
2 days ago
|
show 2 more comments
2
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)quser
– LotPings
2 days ago
Why the11
in$pattern
?
– Lieven Keersmaekers
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I executequser
the part that i want to extract is between Disc and the logon time. In this case11
was the day of month.
– Jorge Luís Segura Oñate
2 days ago
2
2
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)
quser
– LotPings
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)
quser
– LotPings
2 days ago
Why the
11
in $pattern
?– Lieven Keersmaekers
2 days ago
Why the
11
in $pattern
?– Lieven Keersmaekers
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I execute
quser
the part that i want to extract is between Disc and the logon time. In this case 11
was the day of month.– Jorge Luís Segura Oñate
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I execute
quser
the part that i want to extract is between Disc and the logon time. In this case 11
was the day of month.– Jorge Luís Segura Oñate
2 days ago
|
show 2 more comments
2 Answers
2
active
oldest
votes
To get cmd processes just run get-process -name cmd
To find any child processes within cmd you could use something like this:
Get-WmiObject win32_process | where {$_.ParentProcessId -eq ((Get-Process -name cmd).id)}
Upd.
As @LievenKeersmaekers has noticed this could not work in case of several cmds running simultaneously. Fixed version:
(Get-Process -name cmd).id | foreach { Get-WmiObject win32_process -filter "ParentProcessId='$_'"}
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or morecmd
processes running and a busy child process on another than the firstcmd
, this will not return a result.
– Lieven Keersmaekers
2 days ago
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
|
show 1 more comment
Following is a bit simplified and returns the users, other than adminagora
, that have disconnected sessions for over an hour
(& quser) -split "`n" | ? {$_ -match "(?<!adminagora).*?Discs+d:d{2}"}
breakdown
(& quser) -split "`n" -- Executes quser
Splits each line on newline to pass through the pipeline
? {$_ -match -- Where the current item matches the regex
(?<!adminagora) -- Use a negative lookbehind to exclude adminagora
.*?Disc -- match any characters as few times as possible up until Disc.
s+d:d{2} -- match any space character followed by
-- a digit, a colon and two digits
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943401%2fpowershell-user-session-managment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To get cmd processes just run get-process -name cmd
To find any child processes within cmd you could use something like this:
Get-WmiObject win32_process | where {$_.ParentProcessId -eq ((Get-Process -name cmd).id)}
Upd.
As @LievenKeersmaekers has noticed this could not work in case of several cmds running simultaneously. Fixed version:
(Get-Process -name cmd).id | foreach { Get-WmiObject win32_process -filter "ParentProcessId='$_'"}
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or morecmd
processes running and a busy child process on another than the firstcmd
, this will not return a result.
– Lieven Keersmaekers
2 days ago
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
|
show 1 more comment
To get cmd processes just run get-process -name cmd
To find any child processes within cmd you could use something like this:
Get-WmiObject win32_process | where {$_.ParentProcessId -eq ((Get-Process -name cmd).id)}
Upd.
As @LievenKeersmaekers has noticed this could not work in case of several cmds running simultaneously. Fixed version:
(Get-Process -name cmd).id | foreach { Get-WmiObject win32_process -filter "ParentProcessId='$_'"}
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or morecmd
processes running and a busy child process on another than the firstcmd
, this will not return a result.
– Lieven Keersmaekers
2 days ago
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
|
show 1 more comment
To get cmd processes just run get-process -name cmd
To find any child processes within cmd you could use something like this:
Get-WmiObject win32_process | where {$_.ParentProcessId -eq ((Get-Process -name cmd).id)}
Upd.
As @LievenKeersmaekers has noticed this could not work in case of several cmds running simultaneously. Fixed version:
(Get-Process -name cmd).id | foreach { Get-WmiObject win32_process -filter "ParentProcessId='$_'"}
To get cmd processes just run get-process -name cmd
To find any child processes within cmd you could use something like this:
Get-WmiObject win32_process | where {$_.ParentProcessId -eq ((Get-Process -name cmd).id)}
Upd.
As @LievenKeersmaekers has noticed this could not work in case of several cmds running simultaneously. Fixed version:
(Get-Process -name cmd).id | foreach { Get-WmiObject win32_process -filter "ParentProcessId='$_'"}
edited 2 days ago
answered 2 days ago
montonero
32616
32616
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or morecmd
processes running and a busy child process on another than the firstcmd
, this will not return a result.
– Lieven Keersmaekers
2 days ago
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
|
show 1 more comment
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or morecmd
processes running and a busy child process on another than the firstcmd
, this will not return a result.
– Lieven Keersmaekers
2 days ago
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
Yes, that helps but in essence what I want is some datathat lets me know if something is running on cmd. I could use the CPU usage as a reference, but I dont think is a reliable marker.
– Jorge Luís Segura Oñate
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
It depends on what is exactly executed within cmd. In a general case it could be only done by a trial and error.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
You could also find child processes of cmd. This could be a slight evidence that something is executing within cmd.
– montonero
2 days ago
Note that this is not foolproof. If you have two or more
cmd
processes running and a busy child process on another than the first cmd
, this will not return a result.– Lieven Keersmaekers
2 days ago
Note that this is not foolproof. If you have two or more
cmd
processes running and a busy child process on another than the first cmd
, this will not return a result.– Lieven Keersmaekers
2 days ago
1
1
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
@LievenKeersmaekers Thanks for noticing, I've made a change that should detect child processes for all running cmds. Regarding some code that is running by cmd itself - there's not much internal cmd commands that could take any significant time.
– montonero
2 days ago
|
show 1 more comment
Following is a bit simplified and returns the users, other than adminagora
, that have disconnected sessions for over an hour
(& quser) -split "`n" | ? {$_ -match "(?<!adminagora).*?Discs+d:d{2}"}
breakdown
(& quser) -split "`n" -- Executes quser
Splits each line on newline to pass through the pipeline
? {$_ -match -- Where the current item matches the regex
(?<!adminagora) -- Use a negative lookbehind to exclude adminagora
.*?Disc -- match any characters as few times as possible up until Disc.
s+d:d{2} -- match any space character followed by
-- a digit, a colon and two digits
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
add a comment |
Following is a bit simplified and returns the users, other than adminagora
, that have disconnected sessions for over an hour
(& quser) -split "`n" | ? {$_ -match "(?<!adminagora).*?Discs+d:d{2}"}
breakdown
(& quser) -split "`n" -- Executes quser
Splits each line on newline to pass through the pipeline
? {$_ -match -- Where the current item matches the regex
(?<!adminagora) -- Use a negative lookbehind to exclude adminagora
.*?Disc -- match any characters as few times as possible up until Disc.
s+d:d{2} -- match any space character followed by
-- a digit, a colon and two digits
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
add a comment |
Following is a bit simplified and returns the users, other than adminagora
, that have disconnected sessions for over an hour
(& quser) -split "`n" | ? {$_ -match "(?<!adminagora).*?Discs+d:d{2}"}
breakdown
(& quser) -split "`n" -- Executes quser
Splits each line on newline to pass through the pipeline
? {$_ -match -- Where the current item matches the regex
(?<!adminagora) -- Use a negative lookbehind to exclude adminagora
.*?Disc -- match any characters as few times as possible up until Disc.
s+d:d{2} -- match any space character followed by
-- a digit, a colon and two digits
Following is a bit simplified and returns the users, other than adminagora
, that have disconnected sessions for over an hour
(& quser) -split "`n" | ? {$_ -match "(?<!adminagora).*?Discs+d:d{2}"}
breakdown
(& quser) -split "`n" -- Executes quser
Splits each line on newline to pass through the pipeline
? {$_ -match -- Where the current item matches the regex
(?<!adminagora) -- Use a negative lookbehind to exclude adminagora
.*?Disc -- match any characters as few times as possible up until Disc.
s+d:d{2} -- match any space character followed by
-- a digit, a colon and two digits
answered 2 days ago
Lieven Keersmaekers
46.8k1186123
46.8k1186123
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
add a comment |
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
Wow, that does indeed simplify my script. But the main thing is how i determine if something is running on cmd, I could guide me thru the CPU usage, but I'm not to keen on that.
– Jorge Luís Segura Oñate
2 days ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943401%2fpowershell-user-session-managment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You should post the actual code instead of screenshots. If someone wants to try it out, they aren't going to sit and re-type it in order to help you.
– boxdog
2 days ago
You are right, thanks
– Jorge Luís Segura Oñate
2 days ago
I think most of your code could be shortened with a RegEx using named capture groups if you show us a sample output of your (presumably localized)
quser
– LotPings
2 days ago
Why the
11
in$pattern
?– Lieven Keersmaekers
2 days ago
@LievenKeersmaekers, it was for testing puropses, when I execute
quser
the part that i want to extract is between Disc and the logon time. In this case11
was the day of month.– Jorge Luís Segura Oñate
2 days ago