Topics - Stoic Joker [ switch to compact view ]

Pages: [1] 2 3 4 5 6 ... 23next
1
Greetings,
   I'm trying to create a report using the Windows Event Logs that displays the RD Gateway logon history of users with PowerShell, but I'm stuck at how to get the length (or Duration in the code) of their session to show up in a string inside of a switch statement.


Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-TerminalServices-Gateway/Operational'; ID=300,302,303 } | %{

(new-object -Type PSObject -Property @{
TimeCreated = $_.TimeCreated

evId = $_.ID -replace '\s',''

ClientIP = $_.Message -replace '(?smi).*on client computer\s\"+([^\s]+)\",\s+.*','$1'

UserName = $_.Message -replace '(?smi).*The user\s\"+([^\s]+)\",\s+.*','$1'

Duration = $_.Message -replace '(?smi).*\ssession duration was\s+([^\s]+)\s+.*','$1'
})

} | sort UserName, TimeCreated -Descending | Select TimeCreated, ClientIP `
, @{N='Username';E={'{0}' -f $_.UserName}} `
, @{N='evID - User Action Made';E={
switch ($_.evId) {
300 {'300 - Requested Resource Access Authorized'}
302 {'302 - Full Resource Machine Connection'}
303 {"303 - User Disconnected From Resource: 'Duration'"}
default {'This should be unreachable...'}
} Format-Table -AutoSize
}}


No matter what I try, nothing will put the number of seconds number that should be stored in the Duration array into that string for output to the screen. And I need to have it displayed conditionally for only the 303 events - Otherwise it doesn't exist and dumps the whole event message text.

Anybody know the right answer that I can't seem to find?

Thanks in Advance

Stoic Joker

2
Living Room / Looking for Raspberry Pi with Pass-Through Power
« on: August 16, 2023, 09:18 AM »
Okay, this could be a Unicorn, but...

Has anyone ever come across a Raspberry Pi that has a pass-through power port, similar to the powerline networking devices?

Powerline Networking Adapter.jpg
So something that looks like this, but with a Raspberry Pi in it.

I can't give a lot of detail about what I'm up to, but I'd be needing something that is not a kit/homebuilt for the application in mind.

Thanks in Advance,

Stoic Joker

3
Developer's Corner / PowerShell Pickle with Registry Updates
« on: September 15, 2022, 03:35 PM »
Greetings,
    So I'm in a bit of a pickle trying to update the registry with PowerShell. I need to go into a key, list it's sub keys, and update a value in all of the subkeys on local machine. Reason this is being done with PowerShell, is it has to be pushed out to 80 machines...so nobody wants to do it manually 80 times  :D

   The script (scrounged off the internet) I've been beating on all afternoon is below, it will open the key and list the values I'm after … But I cannot get it to update them. Note: the updated value is/will be based on the current value. So I'm looking for a get/replace/set type of operation on the HostName entry's value which is an IP address.

Code: PowerShell [Select]
  1. $registry = Get-ChildItem "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" -Recurse
  2.  
  3. foreach ($a in $registry) {
  4.     ($a | Get-ItemProperty).Psobject.Properties |
  5.     #Exclude powershell-properties in the object
  6.     Where-Object { $_.Name -like 'HostName' } |
  7.     Select-Object Name, Value
  8. }

So instead of displaying the HostName entry's value, I need it to change the third octet of the IP address to a 4 so that 192.168.1.152 becomes 192.168.4.152

Anybody smarter than I am got a bit of mercy handy for a tired old fool?

TIA
-Stoic Joker

4
So from what I'm reading, this is supposed to be simple - I'm just screwing it up somehow.

Issue I'm having is that if I use the full [path][filename] in the code it works fine. But if I try to store the path in a string - so I don't have to edit it 5 times if there is a change - logging fails and the script locks up.

I've tried every variation I could either find, or think of … But have as of yet, not found the correct answer.

Snippet of problem code below:
Code: PowerShell [Select]
  1. $logline = "$(Get-Date), $ChangeType, $FullPath"
  2.     Add-content "C:\Users\Me\Them\NPM Change Log.txt" -value $logline

Now ^that^ works fine, but what I need is something more like this:
Code: PowerShell [Select]
  1. $LogFile = "C:\Users\Me\Them\NPM Change Log.txt"
  2.    
  3.     $logline = "$(Get-Date), $ChangeType, $FullPath"
  4.     Add-content "$LogFile -value $logline

But I can't get it to work; double quotes, single quotes, with/without the -path parameter identifier - everything fails and locks the script.

Any Ideas on what I might be missing?

TIA

Stoic Joker

5
General Software Discussion / Opera Start Page Question
« on: October 30, 2021, 02:30 PM »
So I decided to give the Opera browser a shot, since IE is rather long dead - Yes I'm still using it (hush..).

Is there any way of getting Google Search off of the default Opera Start Page?? I've seen many suggestions that don't work … Does anyone know of one that does?

I'm actually kinda liking this thing...just don't wanna see no 'G' world crap.

Pages: [1] 2 3 4 5 6 ... 23next
Go to full version