FIRST POST IN STACKOVERFLOW! I never asked any questions until now. Please, don't hit me too hard lol.
I am trying to create a powershell script to grab a name entered in a config file and feed it into the script. (Renaming a computer)
It's worked before, I swear it... just as is. But I have recently moved all my files to another test system and now it's showing this... like it cannot read or see anything.
I tried testing it out, seeing if it was reading/gathering from the right place so I put a write-host in to see what it was, it did read correctly.
I put the -TotalCount in to grab the SECOND line, that is correct - right?
Why is this failing. And what is more stupid is that IT WAS JUST WORKING.
CODE:
$password =XXXXXXXX | ConvertTo-SecureString -asPlainText -Force
$username = XXXXXXXX
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$compname = (Get-Content -path .\0CONFIGURATION.txt -TotalCount 2)
Rename-Computer -NewName $compname -LocalCredential $credential -PassThru
Write-Host $compname
ERROR:
Rename-Computer : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter
'NewName'. Specified method is not supported.
At line:6 char:26
+ Rename-Computer -NewName $compname -LocalCredential $credential -Pass ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Rename-Computer], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.RenameComputerCommand