Avatar of llarava
Flag for Afghanistan

asked on 

Powershell - Prompt for server name to run script -

Can someone let me know how to change the script in order to be able to prompt for server name instead of having to put it in the script.

$server = "SERVERA"

get-service -ComputerName $server -Name Winmgmt | Stop-Service -Force

if (Test-Path "\\$server\c$\Windows\System32\wbem\Repository\Objects.Data")
    Remove-Item "\\$server\c$\Windows\System32\wbem\Repository\Objects.Data"
if (Test-Path "\\$server\c$\Windows\SoftwareDistribution\DataStore\Datastore.edb")
    Remove-Item "\\$server\c$\Windows\SoftwareDistribution\DataStore\Datastore.edb"
if (Test-Path "\\$server\c$\Windows\System32\wbem\Repository\Index.btr")
    Remove-Item "\\$server\c$\Windows\System32\wbem\Repository\Index.btr"

get-service -ComputerName $server -Name Winmgmt | Start-Service
PowershellVB ScriptShell Scripting

Avatar of undefined
Last Comment

8/22/2022 - Mon