powershell scripts for gpo - info users logons
#by alex
#powershell script for write logon info
$domainname = (Get-WmiObject Win32_ComputerSystem).Domain
$dirtowrite = "\\fileservername\log$"
$log = $dirtowrite + "\-worklog.log"
$logfile = $dirtowrite + "\-worklog.log"
function log([string]$txt)
{
add-content $LOGFILE $txt
}
$clienthostinfo = ""
function mainproc()
{
#if terminal server role installed, get client name too
if((gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).TerminalServerMode -eq 1){
Import-Module PSTerminalServices
$clienthostinfo = "from:"+(Get-TSSession -Filter {$_.Username -like [Environment]::Username} | Select-Object ClientName).ClientName}
"Logon event at " + $(Get-Date -UFormat "%d-%m-%Y %T") + " for $env:Username on $env:Computername" + " $clienthostinfo" | Out-file -Append -FilePath $("$dirtowrite\$env:Computername-AT-$env:Username@$domainname.log")
}#endof mainproc
try{
mainproc
$retcode = 0}
catch{
$ErrorMessage = $_.Exception.Message
$invocation = $PSItem.InvocationInfo
log("Exception detected!`nError message:$ErrorMessage")
log("invocation:`n$invocation")
$retcode = -1
}
return $retcode
#by alex
#powershell script for write logon info
$domainname = (Get-WmiObject Win32_ComputerSystem).Domain
$dirtowrite = "\\fileservername\log$"
$log = $dirtowrite + "\-worklog.log"
$logfile = $dirtowrite + "\-worklog.log"
function log([string]$txt)
{
add-content $LOGFILE $txt
}
$clienthostinfo = ""
function mainproc()
{
#if terminal server role installed, get client name too
if((gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).TerminalServerMode -eq 1){
Import-Module PSTerminalServices
$clienthostinfo = "from:"+(Get-TSSession -Filter {$_.Username -like [Environment]::Username} | Select-Object ClientName).ClientName}
}#endof mainproc
try{
mainproc
$retcode = 0}
catch{
$ErrorMessage = $_.Exception.Message
$invocation = $PSItem.InvocationInfo
log("Exception detected!`nError message:$ErrorMessage")
log("invocation:`n$invocation")
$retcode = -1
}
return $retcode
Комментариев нет:
Отправить комментарий