PoshCode Archive  Artifact [ba20f0771b]

Artifact ba20f0771b2058756fbaa8bb120bfa4122978022ca49188dc282d8400fbced43:

  • File Poczta.ps1 — part of check-in [b98b97d219] at 2018-06-10 13:18:36 on branch trunk — Get-OUComputerNames (user: Admin size: 1457)

# encoding: ascii
# api: powershell
# title: Poczta
# description: Get-OUComputerNames
# version: 0.1
# type: function
# author: Admin
# license: CC0
# x-poshcode-id: 3002
# x-archived: 2016-03-23T08:18:20
# x-published: 2012-10-14T03:53: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 
}