i have largish set of windows 10 workstations need renamed. i've tried running script below, errors beyond current ps level.
$computers = import-csv "c:\rename-computers\computers.csv" foreach ($oldname in $computers){ #write-host "empid=" + $computers.newname rename-computer -computername $computers.oldname -newname $computers.newname -domaincredential hole\inwall -force -restart }
produces:
rename-computer : cannot convert 'system.object[]' type 'system.string' required parameter 'computername'. specified method not supported. @ \siat-ds0\appdeploy\labpacks\rename-computers\rename-siat.ps1:4 char:35 + rename-computer -computername $computers.oldname -newname $computers.newname ... + ~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidargument: (:) [rename-computer], parameterbindingexception + fullyqualifiederrorid : cannotconvertargument,microsoft.powershell.commands.renamecomputercommand
i've seen similar closed threads on topic elsewhere without mention of error i'm receiving.
you mistakenly used collection variable $computers
instead of loop-iteration variable $oldname
inside loop, , since $computers.newname
expanded array of names rather single one, got error saw.
that said, you don't need loop @ all - single pipeline do:
import-csv "c:\rename-computers\computers.csv" | rename-computer -computername { $_.oldname } -domaincredential hole\inwall -force -restart
rename-computer
implicitly bind newname
property of each input object -newname
parameter.
the -computername
parameter, contrast, must told property on input objects access, given input objects have no computername
property.
script block { $_.oldname }
does, inside automatic variable $_
represents input object @ hand.
to see parameters accept pipeline input, examine output from
get-help -full rename-computer
; details , programmatic alternative, see this answer of mine.
Comments
Post a Comment