PoshCode Archive  Artifact [5a12d455b0]

Artifact 5a12d455b0bdcc4ff8130d965eddbfe43b8724aab312e95ad2e62b314f3b029d:

  • File Set-LocalPassword.ps1 — part of check-in [113cae981a] at 2018-06-10 14:00:50 on branch trunk — Get-OUComputerNames (user: Nathan Hartley size: 1476)

# encoding: ascii
# api: powershell
# title: Set-LocalPassword
# description: Get-OUComputerNames
# version: 0.1
# type: function
# author: Nathan Hartley
# license: CC0
# x-poshcode-id: 576
# x-archived: 2016-06-21T10:39:54
# x-published: 2009-09-10T07:54:00
#
# 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 
}