PoshCode Archive  Artifact Content

Artifact d913c29d69ad84abe73a5a244f8e12ebd8a8194f3f8b77c8a6c1e30c96eb7bdd:

  • File Set-LocalPassword.ps1 — part of check-in [03c3cd0443] at 2018-06-10 12:56:34 on branch trunk — Get-OUComputerNames (user: Admin size: 1432)

# encoding: ascii
# api: powershell
# title: Set-LocalPassword
# description: Get-OUComputerNames
# version: 0.1
# type: function
# author: Admin
# license: CC0
# x-poshcode-id: 1164
# x-archived: 2009-06-27T20:29:16
#
# usage   : [computerName1,computerName2,... | ] ./Set-LocalPassword.ps1 [-user] <userName> [-password] <password> [[-computers] computerName1,computerName2,...]
# returns : Sets local account passwords on one or more computers
#
param(
	[switch]$Help
	, [string] $User
	, [string] $Password
    , [string[]] $ComputerNames = @()
)
$usage = @'
Get-OUComputerNames
usage   : [computerName1,computerName2,... | ] ./Set-LocalPassword.ps1 [-user] <userName> [-password] <password> [[-computers] computerName1,computerName2,...]
returns : Sets local account passwords on one or more computers
author  : Nathan Hartley
'@
if ($help) {Write-Host $usage;break}

$ComputerNames += @($input)

if (! $ComputerNames)
{
    $ComputerNames = $env:computername
}

function ChangePassword ([string] $ChangeComputer, [string] $ChangeUser, [string] $ChangePassword) {
	"*** Setting password for $ChangeComputer/$ChangeUser"
	& {
	$ErrorActionPreference="silentlycontinue"
	([ADSI] "WinNT://$computer/$user").SetPassword($password)
	if ($?) { " Success" }
	else { " Failed: $($error[0])" }
	}

}

ForEach ($computer in $ComputerNames) { 
	ChangePassword $computer $user $password 
}