Documentation Index
Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt
Use this file to discover all available pages before exploring further.
powershell/PSAvoidUsingComputerNameHardcoded is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
| Property | Value |
|---|
| Severity | Error |
| Category | PSScriptAnalyzer |
| Auto-fix | No |
Description
The names of computers should never be hard coded as this will expose sensitive information. The
ComputerName parameter should never have a hard coded value.
How
Remove hard coded computer names.
Example 1
Problematic code
Function Invoke-MyRemoteCommand ()
{
Invoke-Command -Port 343 -ComputerName hardcoderemotehostname
}
Correct code
Function Invoke-MyCommand ($ComputerName)
{
Invoke-Command -Port 343 -ComputerName $ComputerName
}
Example 2
Problematic code
Function Invoke-MyLocalCommand ()
{
Invoke-Command -Port 343 -ComputerName hardcodelocalhostname
}
Correct code
Function Invoke-MyLocalCommand ()
{
Invoke-Command -Port 343 -ComputerName $env:COMPUTERNAME
}
Source
This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for
AvoidUsingComputerNameHardcoded,
licensed under CC BY 4.0.