> ## 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

> Avoid Using ComputerName Hardcoded

`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

```powershell theme={null}
Function Invoke-MyRemoteCommand ()
{
    Invoke-Command -Port 343 -ComputerName hardcoderemotehostname
}
```

### Correct code

```powershell theme={null}
Function Invoke-MyCommand ($ComputerName)
{
    Invoke-Command -Port 343 -ComputerName $ComputerName
}
```

## Example 2

### Problematic code

```powershell theme={null}
Function Invoke-MyLocalCommand ()
{
    Invoke-Command -Port 343 -ComputerName hardcodelocalhostname
}
```

### Correct code

```powershell theme={null}
Function Invoke-MyLocalCommand ()
{
    Invoke-Command -Port 343 -ComputerName $env:COMPUTERNAME
}
```

## Source

This rule documentation is adapted from Microsoft's PSScriptAnalyzer documentation for
[AvoidUsingComputerNameHardcoded](https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/blob/main/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingComputerNameHardcoded.md),
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
