Avatar of Bryant
BryantFlag for United States of America

asked on 

Powershell Script Write-Output

Hello, I want to write-output for the script below. The script is changing local admin passwords and I want it to display the server name and that it was successful after each one is changed. Can you please help or point me in the right direction?

$pass = "password"
$user = "admin"
foreach($_ in (Get-Content C:\script.txt)){
$newpass = [ADSI]"WinNT://$_/$user,user"
$newpass.SetPassword($pass)
$newpass.SetInfo()
}
PowershellVB Script

Avatar of undefined
Last Comment
Bryant
Avatar of Qlemo
Qlemo
Flag of Germany image

$pass = "password"
$user = "admin"
foreach ($_ in Get-Content C:\script.txt) {
  $newpass = [ADSI]"WinNT://$_/$user,user"
  $newpass.SetPassword($pass)
  $result = $newpass.SetInfo()
  New-Object PsObject -Property @{Server = $_; Success = $result -eq 0}
}

Open in new window

Avatar of Bryant
Bryant
Flag of United States of America image

ASKER

@Qlemo,

Thanks, this is the exact output I was looking for with the exception that it tells me that the success rate is false even though it does indeed change the passwords. Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bryant
Bryant
Flag of United States of America image

ASKER

Perfect, thanks! I want to do other things with this script later, so I may be back. Thanks again!
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo