Set-Item not working.


so have script that connects domain , find servers puts servers array called $servers.  want add servers trusted hosts list (yeah yeah know there's more secure ways of doing this...)  next run foreach so:

foreach ($machine in $servers) {set-item wsman:\localhost\client\trustedhosts -value $machine -concatenate -force}

but following error:

set-item : cannot convert 'system.object[]' type 'system.string' required parameter. specified method not supported.  @ line:2 char:9  +         set-item wsman:\localhost\client\trustedhosts -value $machine ...  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~      + categoryinfo          : notspecified: (:) [set-item], invalidoperationexception      + fullyqualifiederrorid : system.invalidoperationexception,microsoft.powershell.commands.setitemcommand

its got me stumped because had working fine before cant work out whats wrong.  when create array , pipe object in get-member system.string objects, set-item throws this.

anyone?


mcp, mcts, mcitp, mcsa.. gunning mcse cloud | please visit www.deploymentshare.com | invite follow me on twitter:@deploymentshare | if solve issue please mark reply answer.

$servers = invoke-command -computername $dc -credential $credential -script {import-module activedirectory;get-adcomputer -ldapfilter "(&(objectcategory=computer)(operatingsystem=*server*))"} # -erroraction silentlycontinue $allservers = $allservers + $servers.name foreach ($machine in $allservers) {set-item wsman:\localhost\client\trustedhosts -value $machine -concatenate -force} # close foreach

this code got working me.  help!

jonathan.


mcp, mcts, mcitp, mcsa.. gunning mcse cloud | please visit www.deploymentshare.com | invite follow me on twitter:@deploymentshare | if solve issue please mark reply answer.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client