Issue
Code backup
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
$app = 'PS - User Catch'
|
||||
$ver = 'v 0.0'
|
||||
|
||||
Write-Host $app, $ver,"`n Sweep Ip start"
|
||||
|
||||
$sweepip = (190..202) | % {
|
||||
$ip="172.16.82.$_";
|
||||
Write-output "$IP `t` $(test-connection -computername "$ip" -quiet -count 1) `t` $(Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost)`n"
|
||||
}
|
||||
|
||||
#$userquery = query user /server:$pippo
|
||||
|
||||
Write-Host $sweepip
|
||||
@@ -0,0 +1,29 @@
|
||||
$app = 'PS - User Catch'
|
||||
$ver = 'v 0.1'
|
||||
|
||||
Write-Host $app, $ver,"`n UserCatch"
|
||||
|
||||
$SweepIp = (193..198) | % {
|
||||
$Ip="172.16.82.$_";
|
||||
$Status=test-connection -computername "$ip" -quiet -count 1;
|
||||
|
||||
$StatusOut = switch ($Status) {
|
||||
'True' {"True"}
|
||||
'False' {"`0"}
|
||||
}
|
||||
|
||||
$GetHostname=Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost;
|
||||
|
||||
$QueryUser=if ($StatusOut -like 'True'){
|
||||
if ($GetHostname -like 'PC*'){
|
||||
(query user /server:$GetHostname) -split "`n" -replace '\s\s+', ';' | convertfrom-csv -Delimiter ';'
|
||||
}
|
||||
}
|
||||
|
||||
Write-output "`n$IP `t $StatusOut `t $GetHostname"
|
||||
if ($GetHostname -like 'PC*'){
|
||||
Write-Output "`n$QueryUser"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $SweepIp
|
||||
@@ -0,0 +1,43 @@
|
||||
$app = "PS - User Catch"
|
||||
$ver = "v 0.2"
|
||||
|
||||
$start = "Stai eseguendo:"
|
||||
$exec = "Lo script $app e' in esecuzione."
|
||||
|
||||
Write-Host $start, $app, $ver, "`n$exec"
|
||||
|
||||
$UserCatch = (173..176) | % {
|
||||
$Ip = "172.16.91.$_";
|
||||
$Status = test-connection -computername "$ip" -quiet -count 1;
|
||||
|
||||
$StatusOut = switch ($Status) {
|
||||
'True' {"True"}
|
||||
'False' {"`0"}
|
||||
}
|
||||
|
||||
$GetHostname = Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost;
|
||||
|
||||
$QueryUser = if ($GetHostname -like 'PC*'){
|
||||
foreach ($s in $GetHostname) #For Each Server
|
||||
{
|
||||
foreach($ServerLine in @(query user /server:$s) -split "\n") #Each Server Line
|
||||
{
|
||||
#USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
|
||||
|
||||
$Parsed_Server = $ServerLine -split "\s+"
|
||||
|
||||
$Parsed_Server[1] #USERNAME
|
||||
$Parsed_Server[4] #STATE
|
||||
$Parsed_Server[6] #LOGON TIME
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-output "`n$IP`t$StatusOut`t$GetHostname"
|
||||
|
||||
if ($GetHostname -like 'PC*'){
|
||||
Write-Output "`n$QueryUser`n"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $UserCatch
|
||||
@@ -0,0 +1,51 @@
|
||||
$app = "PS - User Catch"
|
||||
$ver = "v 0.3"
|
||||
|
||||
$start = "Stai eseguendo:"
|
||||
$exec = "Lo script $app e' in esecuzione."
|
||||
|
||||
Write-Host $start, $app, $ver
|
||||
Write-Host $exec -fore green
|
||||
|
||||
$UserCatch = (180..200) | % {
|
||||
$Ip = "172.16.82.$_";
|
||||
$Status = test-connection -computername "$ip" -quiet -count 1;
|
||||
|
||||
$StatusOut = switch ($Status) {
|
||||
'True' {"True"}
|
||||
'False' {"`0"}
|
||||
}
|
||||
|
||||
if ($Status -like 'True') {
|
||||
|
||||
$GetHostname = Resolve-DnsName $ip -ErrorAction Ignore |select -exp NameHost;
|
||||
|
||||
$QueryUser = if ($GetHostname -like 'PC*') {
|
||||
foreach ($s in $GetHostname){
|
||||
foreach($ServerLine in @(query user /server:$s) -split"\n")
|
||||
{
|
||||
$Parsed_Server = $ServerLine -split"\s+"
|
||||
|
||||
$Parsed_Server[1]
|
||||
$Parsed_Server[4]
|
||||
$Parsed_Server[6]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-output "`n$IP`t$StatusOut`t$GetHostname"
|
||||
|
||||
if ($GetHostname -like 'PC*') {
|
||||
Write-Output "`n$QueryUser`n"
|
||||
}
|
||||
}
|
||||
else {
|
||||
"`0"
|
||||
}
|
||||
}
|
||||
|
||||
Start-Transcript -Path .\testlog.txt
|
||||
|
||||
Write-Host $UserCatch
|
||||
|
||||
Stop-Transcript
|
||||
@@ -0,0 +1,69 @@
|
||||
$app = "PS - UserCatch"
|
||||
$ver = "v 0.4"
|
||||
|
||||
$start = "Stai eseguendo:"
|
||||
$exec = "Lo script $app e' in esecuzione."
|
||||
|
||||
Write-Host $start, $app, $ver
|
||||
Write-Host $exec -fore green
|
||||
|
||||
$UserCatch = (1..254) | % {
|
||||
$Ip = "172.16.94.$_";
|
||||
$Status = test-connection -computername "$ip" -quiet -count 1;
|
||||
|
||||
$StatusOut = switch ($Status) {
|
||||
'True' {"True"}
|
||||
'False' {"`0"}
|
||||
}
|
||||
|
||||
if ($Status -like 'True') {
|
||||
|
||||
$GetHostname = Resolve-DnsName $ip -ErrorAction Ignore | select -exp NameHost;
|
||||
|
||||
$QueryUser = if ($GetHostname -like 'PC*') {
|
||||
foreach ($s in $GetHostname){
|
||||
foreach($ServerLine in @(query user /server:$s) -split"\n")
|
||||
{
|
||||
$Parsed_Server = $ServerLine -split"\s+"
|
||||
|
||||
$Parsed_Server[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$QueryState = if ($GetHostname -like 'PC*') {
|
||||
foreach ($s in $GetHostname){
|
||||
foreach($ServerLine in @(query user /server:$s) -split"\n")
|
||||
{
|
||||
$Parsed_Server = $ServerLine -split"\s+"
|
||||
|
||||
$Parsed_Server[4]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$QueryLogon = if ($GetHostname -like 'PC*') {
|
||||
foreach ($s in $GetHostname){
|
||||
foreach($ServerLine in @(query user /server:$s) -split"\n")
|
||||
{
|
||||
$Parsed_Server = $ServerLine -split"\s+"
|
||||
|
||||
$Parsed_Server[6]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-output "`n$IP`t$GetHostname"
|
||||
|
||||
if ($GetHostname -like 'PC*') {
|
||||
Write-Output "`n`n$QueryUser"
|
||||
Write-Output "`n$QueryState"
|
||||
Write-Output "`n$QueryLogon`n"
|
||||
}
|
||||
}
|
||||
else {
|
||||
"`0"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $UserCatch
|
||||
@@ -0,0 +1,14 @@
|
||||
$Server = "PC284.pal.local"
|
||||
$Sessions = (quser /server:$Server) -replace '\s{2,}', ',' | ConvertFrom-Csv
|
||||
|
||||
$Utente = $Sessions.NOMEUTENTE
|
||||
$Sessione = $Sessions.NOMESESSIONE
|
||||
$Stato = $Sessions.STATO
|
||||
$Tempo = $Sessions."INATTIVITÀ ACCESSO"
|
||||
|
||||
Write-Host "Host: "$Server
|
||||
Write-Host "Utente: "$Utente
|
||||
Write-Host "Sessione: "$Sessione
|
||||
Write-Host "Stato: "$Stato
|
||||
Write-Host "Tempo: "$Tempo
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
$app = "PS - UserCatch"
|
||||
$ver = "v 1.0"
|
||||
|
||||
$start = "Stai eseguendo:"
|
||||
$exec = "Lo script $app e' in esecuzione."
|
||||
|
||||
Write-Host $start, $app, $ver
|
||||
Write-Host $exec -fore Yellow
|
||||
|
||||
(1..254) | % {$IP ="172.16.94.$_"; Write-Output "$(
|
||||
ForEach-Object {Test-Connection -ComputerName $IP -Count 1 -ErrorAction:SilentlyContinue -AsJob} | Get-Job | Receive-Job -Wait -AutoRemoveJob | Where-Object {$_.StatusCode -eq 0} | Select-Object -exp Address
|
||||
)"}
|
||||
@@ -0,0 +1,14 @@
|
||||
PS C:\Users\cbo\Documents\Code\PowerShell\Script> .\UserCatch.ps1
|
||||
Stai eseguendo: PS - User Catch v 0.3
|
||||
Lo script PS - User Catch e' in esecuzione.
|
||||
|
||||
172.16.82.191 True
|
||||
172.16.82.192 True Galaxy-A20e.pal.local
|
||||
172.16.82.193 True NB082.pal.local
|
||||
172.16.82.196 True Galaxy-Tab-S4.pal.local
|
||||
172.16.82.197 True PC213.pal.local
|
||||
NOMEUTENTE STATO ACCESSO dc Attivo 20/05/2021
|
||||
|
||||
172.16.82.198 True PC210.pal.local
|
||||
NOMEUTENTE STATO ACCESSO cbo Attivo 25/05/2021
|
||||
|
||||
Reference in New Issue
Block a user