Ying Li at myITforum.com

PowerShell & System Center

Powershell script to manipulate string.

Sometime you get a list of hostname with fully qualified domain name but you might just need the computer name part.

Here is a powershell script to loop through the list and remove everything after “.” and create a new list with only computer name.

$PreSecond = get-content PreSecond.txt
New-Item "C:\Myworkplace\ps\Second.txt" -Type file
foreach ($Hostname in $PreSecond)
{
 $second = $Hostname.split('.')[0]
 Add-content "C:\Myworkplace\ps\Second.txt" $second
}

Posted: May 07 2007, 02:27 PM by yli628 | with no comments
Filed under:

Comments

No Comments