0

how I can run this command in powershell to all users in the server?

powerShell -sta -file 'E:\Script-Popup\Popup-Message - Done.ps1'

that on every user who is currently connected to the server, this command will run.

vfdsabvdasvd
  • 35
  • 1
  • 6

2 Answers2

0

Option 1:

Get connected users:

query user /server:SERVERNAME

For each user run:

$username = "username"
$password = "password"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, 
$securePassword
Start-Process powershell.exe -Credential $credential -ArgumentList "-file 
$script"

Option 2:

Configure a logon script using a GPO (the script will run when the users login)

Rusty cole
  • 90
  • 9
  • It's never a good practice to put plain text credentials in a script. Ask for the using ```Get-Credential```, then code for their use. Option 2 is the better approach, but if the user is already logged on, then use a scheduled task. Yet, it looks like you've asked the same question here multiple times and have yet to respond to any submission already provided in your other posts. For example, you other post here: https://stackoverflow.com/questions/74552186/powershell-message-to-all-server-users – postanote Nov 24 '22 at 07:51
0

You don't need PowerShell for that (but you can use it with PowerShell)

msg * 'This will be shown to all users as a pop up'

MS Learn - Terminal Server commands: MSG

Dennis
  • 871
  • 9
  • 29