Link to home
Start Free TrialLog in
Avatar of yaknour
yaknour

asked on

PowerShell Output to Text File

So I am fairly new to Powershell and need to create a script to rename the computers in our office. That portion of the script works. The part i am having trouble with is the output.

I have this set in task scheduler but when it runs i do not see if the rename was successful. Below is my script and below that is the what goes into the text file.

start-transcript -path C:\Users\abhagwandin.SENECA\Desktop\RenameResults.txt
$CSV = Import-Csv "C:\Users\abhagwandin.SENECA\Desktop\Computer Desktop Names Test.csv" -Header OldName, NewName
Foreach ($name in $CSV)


{
write-output $name

netdom renamecomputer $name.OldName /newname: $name.NewName /userd: admin /passwordd: pass /usero: admin /passwordo: pass /reboot /force
}



stop-transcript

Open in new window


Text File Output

-------------------------------------------------------------------------------
**********************
Windows PowerShell Transcript Start
Start time: 20150520154216
Username  :
Machine   :  (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is C:\Users\abhagwandin.SENECA\Desktop\RenameRe
sults.txt
OldName                                 NewName                                
-------                                 -------                                
JFLAHNYCD1                              JFLAHERTY                              
**********************
Windows PowerShell Transcript End
End time: 20150520154218
**********************
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this :

$CSV = Import-Csv "C:\Users\abhagwandin.SENECA\Desktop\Computer Desktop Names Test.csv" -Header OldName, NewName
$output = Foreach ($name in $CSV)


{
write-output $name

netdom renamecomputer $name.OldName /newname: $name.NewName /userd: admin /passwordd: pass /usero: admin /passwordo: pass /reboot /force
}

$output | Out-File C:\Users\manojkumar.rane\Desktop\output.csv
Avatar of yaknour
yaknour

ASKER

Thank you, this is exactly what i was looking for.