PowerShell for Windows Admins

Jun 30 2013   1:52PM GMT

Using localhost

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: