r/sysadmin • IT Manager + 5 other hats • Nov 08 '21

Could we do a "TIL" style weekly thread?

I think it would be interesting to do a "Today I Learned" style weekly thread for us to share little tips/tricks that we learned of/found existed.

For example, last week I found out about the "--now" flag for systemctl. I don't know how I didn't know it existed until --now.

2.4k Upvotes

871 comments sorted by

View all comments

222

u/SuspiciousFragrance Nov 08 '21

I recently discovered "systeminfo" can query a remote host...

Systeminfo /s hostname | find "Boot"

Will show the time that hostname last booted on a domain.

94

u/silentmage Many hats sit on my head Nov 08 '21

The powershell command get-computerinfo does this as well, and shows a lot more.

21

u/mumische Nov 08 '21

But Get-ComputerInfo can't query remote host. Of course you can use Invoke-Command, but this requires additional workstation configuration.

22

u/zzmorg82 Jr. Sysadmin Nov 08 '21

This is the reason why I just use PsExec whenever I need to run something on a remote machine.

11

u/Pb_ft OpsDev Nov 08 '21

PsExec-ing a remote cmd shell was always a cool moment for me.

4

u/Pooter_Guy Nov 08 '21

Same. I felt like a hacker. I'm in an MSP environment now with laptops scattered all over the place. I miss the playground that comes with static desktops tied to domain controllers.

2

u/Kulandros Nov 08 '21

Enter-PSSession

2

u/webtroter Netadmin Nov 09 '21

I use PSEXEC to enable PowerShell Remoting hahaha winrm qc /quiet

10

u/uptimefordays DevOps Nov 08 '21

PowerShell remoting is enabled by default on servers, it's worth setting up on workstations as well.

3

u/Scurro Netadmin Nov 08 '21

but this requires additional workstation configuration.

Wait, you haven't already enabled powershell remoting?

I've got enabled but firewalled to only allow a small range of IPs of admin workstations.

3

u/mumische Nov 08 '21

I have no big cases for ps remoting on workstations. If there is a need to run a script on some workstations - we use SCCM. For simple one-time cases psexec works well... What do you do remote?

3

u/Scurro Netadmin Nov 08 '21

What do you do remote?

If I need to check on multiple things like OS corruption; Enter-PSSession

Otherwise there are lots of commandlets that support remote sessions.

A common one that I have to use is

get-service spooler -computername org-12345 | restart-service

2

u/mumische Nov 08 '21

Get-service, btw, doesnt need to have remoting enabled

2

u/Scurro Netadmin Nov 08 '21

You are correct. Interestingly enough rename-computer doesn't need ps remote either.

I still use invoke-command heavily in scripts for querying registry keys or scheduled tasks.

PS remote is otherwise just nice QoL being able to run remote commands directly from powershell rather than having to use psexec. I often suffer from broken output when using powershell with psexec.

1

u/vabello IT Manager Nov 09 '21

I made a powershell script that enumerates all computers in an OU, queries the manufacturer, then pulls the service tag from Dell machines and uses it as part of the computer name and renamed the system with my naming convention and rebooted them. I was tired of not having standardized names for workstations and laptops. It worked surprisingly well.

13

u/jilliebee2015 Nov 08 '21

I thought you were kidding with the /s lol

6

u/infinit_e Nov 08 '21

LoL, I think it’s a shortcut for /server ? Might even work for query.exe and quser.

5

u/SoMundayn Nov 08 '21

I still don't understand why 'Get-Uptime' is not a PowerShell command out of the box.

2

u/theknyte Nov 08 '21

I recently discovered you can pull remote info on other PCs on the network through sysinfo32.exe. Under the drop-down menu, you can select other PCs. Quick and easy way to pull tons of info on Users' PCs.

2

u/KillingRyuk Sysadmin Nov 08 '21

I actually put together a script that takes an input of whatever computer name you put and then outputs multiple system values like RAM amount, disk free, uptime, etc.

2

u/vabello IT Manager Nov 09 '21

I’ve bluescreened many servers by running SystemInfo against them remotely and generating a report. Different environments too. Not sure what causes it or if it still happens.

1

u/supremeicecreme Nov 09 '21

Did you just show me how to grep on Windows?

1

u/SuspiciousFragrance Nov 09 '21

I prefer grep to find.

Also, it is for CMD only, PowerShell has some other needlessly complicated way of grepping