Using localhost

When creating functions that accept a computer name as a parameter you will often see this syntax

param (

[string]$computername = ‘localhost’


This is designed to give a default value in the event of a value not being passed.  That’s a good idea if there is a sensible, safe, value you can use and you aren’t making the parameter mandatory.

The only objection I have is to using ‘localhost’

I have seen this break down  – for instance if you try to use the System.DirectoryServices.AccountManagement classes against accounts on the local machine. On the other hand you have to use it when dealing with the WSMAN provider.

Just be aware that ‘localhost’ can cause issues

This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s