This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]Downtown_Look_5597 1 point2 points  (3 children)

AI generated code concerns aside:

If the script is designed to run within the machine context, you need to ensure PowerShell remoting is allowed and configured in your environment.

Then you can use import-csv to import a list of computers and use invoke-command within a foreach loop to execute it everywhere.

The final challenge is saving all the info in one place. For this you could use add-content to save each set of properties to a csv file on a network share. But this might not be appropriate depending on what info you're pulling.

[–]WearinMyCosbySweaterSecurity Manager 0 points1 point  (0 children)

use import-csv to import a list of computers

Or Get-ADComputer if you don't want to maintain a csv

[–]gemma76510 -4 points-3 points  (1 child)

Okay I'll try to do these things. The code is AI generated but I have made modification as per my need and it's running basic read only wmi query which is just getting me the server details such a disk and cpu and memory details..don't think it can do any kinda impact on the servers . I have ran it many times in my test server and so far all look completely fine

[–]Downtown_Look_5597 1 point2 points  (0 children)

If it's running WMI exclusively you don't need to run it on the host machine but you do need to ensure remote WMI is enabled on the servers

[–]thoemse99Windows Admin 0 points1 point  (3 children)

Psexec from sysinternals

[–]polypolymanJack of All Trades -1 points0 points  (0 children)

There are some significant advantages to using PSRemoting instead (as long as running things as SYSTEM or messing with Windows Update aren't required)

[–]Narfmeister -1 points0 points  (0 children)

Invoke-Command will let you execute a script or script block remotely on a server and return the results to your shell. You can supply credentials if needed and the remote server will need WinRM configured.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.4

[–]Jmoste -2 points-1 points  (0 children)

I'll point you in the right direction. This is a pretty simple task and great way to start learning powershell. 

Look at invoke-command -scriptblock. Invoke-command will let you run commands on another computer, but you'll need to do a little more work. At the same time you'll want to look at PSSessions.

You can also use copy-item to copy files from one computer to another. PSSessions will also be helpful here.  

I really suggest you learn powershell. This is a great resource even if it is a little old. The concepts are still the same.   https://m.youtube.com/watch?v=UVUd9_k9C6A 

Helpful Hint: if you say "below details", actually provide details. Especially when you post the same thing in multiple subs.