| description | Avoid Using ComputerName Hardcoded |
|---|---|
| ms.date | 06/01/2026 |
| ms.topic | reference |
| title | AvoidUsingComputerNameHardcoded |
Severity Level: Error
Hard-coded computer names can expose sensitive information and reduce script portability. The
ComputerName parameter should always be parameterized or dynamically assigned to ensure scripts
are flexible and secure. Use parameters, environment variables, or dynamic values instead of
hard-coded computer names.
Function Invoke-MyRemoteCommand ()
{
Invoke-Command -Port 343 -ComputerName HardcodedRemoteHostname
}Function Invoke-MyCommand ($ComputerName)
{
Invoke-Command -Port 343 -ComputerName $ComputerName
}Function Invoke-MyLocalCommand ()
{
Invoke-Command -Port 343 -ComputerName HardcodedLocalHostname
}Function Invoke-MyLocalCommand ()
{
Invoke-Command -Port 343 -ComputerName $env:COMPUTERNAME
}