question

Sara925 avatar image
0 Votes"
Sara925 asked RichMatheisen-8856 answered

How to run a command prompt line on multiple servers using powershell

Can we run the below cmd line for multiple servers using powershell, if someone can help on that would be greatly appreciated.

so, the below line needs to be applied on multiple servers to apply the license,

LicenseInfoCmd.exe -l Cxxxx -m "Trial Version" -s

The exe would be in the below path c:\program files\SQL\lite that needs to be updated with the above license.



$serverlist = Get-Content C:\CopiedTo\MyScripts\servers.txt
foreach ($server in $serverlist)
{
$remotesession = New-PSSession -ComputerName $server
Invoke-Command -Session $remotesession {cd c:\program files\SQL\lite}
Enter-PSSession -computername $server
Exit-PSSession

Remove-PSSession -Session $remotesession

}


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

See if this works for you:

 Invoke-Command -ComputerName (Get-Content C:\CopiedTo\MyScripts\servers.txt) {cmd.exe /C 'cd c:\program files\SQL\lite & LicenseInfoCmd.exe -l Cxxxx -m "Trial Version" -s'}

The only thing I'm not entirely sure of is whether the quoting is correct around the "Trial Version".

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.