Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12171

Unsure how to get Export-Csv to work for what I need

$
0
0

I have to rename a little over 100 computers in the warehouse where I work. My script is setup to delay the renaming process until a desired time and gets the computer names from a .csv file. The current date listed is just when I was planning on running the next test of the script before the full scale deployment.

$Credential=Get-Credential$ComputerList = Import-Csv -Path '\\Shares\Scripts\computers.csv'$end = Get-Date "2024/06/11 06:00:00"while ((Get-Date) -lt $end) {    start-sleep 3600}foreach ($Computer in $ComputerList){    Rename-Computer -ComputerName $Computer.oldname -NewName $Computer.newname -DomainCredential $Credential -Force -Restart}

What I need help with, is using the Export-Csv function to generate a CSV file with a list of all machines that were offline or otherwise unable to be renamed. I was hoping to use the Write-Warning command to assist, but my understanding of powershell isn't quite high enough to work this out on my own. The computers are spread throughout a rather large warehouse and while I don't mind going out to them, I'd rather not have to touch every single machine to verify if the renaming was successful or not.

I've tested what I have so far, and it will skip over any computer listed in the .csv that is offline and continue down the list. I tested this with two machines while the first machine in the list was offline; hence, why I want to export what computers are offline or any error that's that are thrown if a renaming is unsuccessful. Bonus if I could have it add "Pass" / "Fail" as a third column in my existing .scv file.

Any assistance is greatly welcomed.


Viewing all articles
Browse latest Browse all 12171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>