Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. New-EventLog -LogName Talon -Source Monitor -ComputerName localhost -ErrorAction SilentlyContinue
  3. $LogTime =(Get-Date -Format "MM/dd/yyyy hh:mm:ss tt")
  4. $LogFile =  "C:\Program Files\TalonFAST\FASTDebugLogs\FAST_SMBConnections.log"
  5. Function LogWrite
  6. {
  7.    Param ([string]$logstring)
  8.  
  9.    Add-content $Logfile -value "$logTime $logstring"
  10. }
  11.  
  12.    $FileName = "C:\Program Files\TalonFAST\FASTDebugLogs\FAST_SMBConnections*.log"
  13.  function RotateLog($log) {
  14.     $count= (get-childitem $log2 -name).count
  15.     $count
  16.         $threshold = .01
  17.         $threshold2 = .001
  18.         $file = Get-Item "$log" -ErrorAction SilentlyContinue
  19.         $filedir = "C:\Program Files\TalonFAST\FASTDebugLogs\"
  20.         $server = HostName
  21.         $filesize = $file.length/1MB
  22.         $datetime = Get-Date -uformat "%Y%m%d-%H%M"
  23.         $fdatetime = Get-Date -uformat "%B %e, %Y - %H%M hours"
  24.         $arcdir = "C:\Program Files\TalonFAST\FASTDebugLogs\"
  25.        
  26.        if ($filesize -lt $threshold2 )
  27. {  
  28.             $rotationmessage2 = "
  29. # APPLIANCE ID: $env:ComputerName
  30. # LOG FILES ARE ROTATED EVERY 8 HOURS
  31. # (SINCE THE LAST SYSTEM RESTART) OR
  32. # EVERY 1MB, WHICHEVER HAPPENS EARLIER
  33.  
  34. "
  35.             Write-Host "$rotationmessage2"
  36.             echo "$rotationmessage2" | Out-File -FilePath "$log" -Append
  37.             }
  38.  
  39.         if ($filesize -gt $threshold) { #
  40.             $filename = $file.name -replace $file.extension,""
  41.             $newname = "${filename}.${Count}.log"
  42.             Rename-Item -Path $file.fullname -NewName $newname
  43.             #Move-Item $newname -Dest "$arcdir"
  44.             $rotationmessage = "
  45. # APPLIANCE ID: $env:ComputerName
  46. # LOG FILES ARE ROTATED EVERY 8 HOURS
  47. # (SINCE THE LAST SYSTEM RESTART) OR
  48. # EVERY 1MB, WHICHEVER HAPPENS EARLIER
  49.  
  50. "
  51.             Write-Host "$rotationmessage"
  52.             echo "$rotationmessage" | Out-File -FilePath "$log" -Append
  53.         }
  54.     }
  55.    
  56. # Call Function
  57. $log = "C:\Program Files\TalonFAST\FASTDebugLogs\FAST_SMBConnections.log" # Specify Log File
  58. $log2 = "C:\Program Files\TalonFAST\FASTDebugLogs\FAST_SMBConnections*.log"
  59. RotateLog($log) # Call Log Rotation Function
  60.  
  61. function get-shareConnection {
  62. param (
  63. [Parameter(Position=0, Mandatory=$true,HelpMessage="Please enter a server name")]
  64. [string] $Server = ""
  65. ,
  66. [Parameter(Position=1,Mandatory=$false)]
  67. [alias("share")]
  68. [string] $sharename = "all"
  69. )
  70. #the processes the function will complete
  71. process {
  72. $serverconnection = Get-WmiObject -ComputerName $Server -Class Win32_SessionConnection
  73.  
  74. $users = @()
  75. foreach ($connection in $serverconnection){
  76. $conn = "" | select "Ip","User","Share","Connections"
  77. $split = $connection.Dependent.split(",")
  78. $conn.ip = $split[0].replace("Win32_ServerConnection.computername=","").replace('"','')
  79. $conn.user = $split[2].replace("UserName=","").replace('"','')
  80. $conn.share = $split[1].replace("sharename=","").replace('"','')
  81. $conn.connections = $conn.user.count
  82.  
  83. if ($sharename -eq "all"){$users += $conn}
  84. else{if ($conn.share -eq $sharename){$users += $conn}}
  85. }
  86. $sysinfo = Get-WmiObject -Class Win32_ComputerSystem
  87. $fqdn ={0}.{1}-f $sysinfo.Name, $sysinfo.Domain
  88. $users  | Export-Csv -Path C:\results.csv
  89. write-host ("Amount of users connected to FASTData: {0}" -f @($users).Length)
  90. Logwrite ("Amount of users connected to FASTData: {0} " -f @($users).Length)
  91. Write-EventLog –LogName Talon –Source Monitor –EntryType Information –EventID 0 –Message ("{0}",", $fqdn" -f @($users).Length)
  92.  
  93. #Write-EventLog –LogName Talon –Source Monitor –EntryType Information –EventID 0 –Message ("Amount of users connected to FASTData: {0}" -f @($users).Length)
  94.  
  95. return $users
  96. }
  97. }
  98.  
  99.  
  100.  
  101.  
  102. $date = (Get-Date -Format yyyy-mm-dd-hh:mm:ss)
  103. $computer = "LocalHost"
  104. $namespace = "root\CIMV2"
  105. $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace
  106. $Sessions=$usersessions | select UserName
  107. $Sessions=$Sessions.count
  108. $ShareCount= $usersessions | select ShareName -unique
  109. $sharecount= $sharecount.count
  110. $Test = get-shareConnection $computer FASTData
  111. $Sessions2=$usersessions | select ConnectionID -unique
  112. $Sessions2=$Sessions2.count
  113.  
  114. if($userSessions -ne $null)
  115. {
  116.     if($sessions -gt 1)
  117.     {
  118.     Write-Host "The total amount of users is: $Sessions."
  119.    
  120.     LogWrite "The total amount of users is: $sessions"
  121.            #Write-EventLog –LogName Talon –Source Monitor –EntryType Information –EventID 0 –Message "Amount of concurrent sessions: $sessions"
  122.  
  123.  
  124.    }  
  125.     else
  126.     {
  127.     write-host "The current amount of users is 1."
  128.     logwrite "The current amount of users is 1."
  129.                #Write-EventLog –LogName Talon –Source Monitor –EntryType Information –EventID 0 –Message "Amount of concurrent sessions: 1"
  130.     }
  131.  
  132.  
  133.  
  134.     #Write-Host "The following users are connected to this server: "
  135.  
  136.  
  137.    
  138.     LogWrite "$sharecount different shares being accessed."
  139.     LogWrite "$sessions2 total SMB connections."
  140.     #LogWrite "The following users are connected to this server:"
  141.  
  142.     foreach ($userSession in $userSessions)
  143.     {
  144.  
  145.         $userDetails = [string]::Format("User {0} from: {1} on share: {2}", $userSession.UserName, $usersession.ComputerName, $userSession.ShareName)
  146.         #Write-Host $userDetails
  147.         LogWrite $UserDetails
  148.         Write-EventLog –LogName Talon –Source Monitor –EntryType Information –EventID 0 –Message $userdetails
  149.                            
  150.     }    
  151.  Get-EventLog -LogName Talon -Source Monitor -ErrorAction SilentlyContinue |
  152.     Select TimeWritten, @{name='ReplacementStrings';Expression={ $_.ReplacementStrings -join ';'}} |
  153.     where {$_.ReplacementStrings -notmatch '^S-1-5'} | Export-Csv C:\TalonMonitor.csv
  154.     Get-EventLog -LogName Talon -Source Monitor -ErrorAction SilentlyContinue |
  155.     Select TimeWritten, @{name='ReplacementStrings';Expression={ $_.ReplacementStrings -join ';'}} |
  156.     where {$_.ReplacementStrings -notmatch '^S-1-5'} | Export-Csv C:\TalonCounter.csv
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement