powershell - "Access denied" error when trying to enumerate drives on remote computers -
i trying run powershell command total disk space of drives our remote servers. when run command getting error below. have text file has names of servers , have confirmed winrm configured , running.
$servers = get-content "c:\users\anorris\desktop\dr\servers1.txt" foreach ($s in $servers) { invoke-command -computername $s {get-psdrive} }
error:
[ahv-a2acortst02] connecting remote server failed following error message : access denied. more information, see about_remote_troubleshooting topic. + categoryinfo : openerror: (:) [], psremotingtransportexception + fullyqualifiederrorid : pssessionstatebroken
agreed message 'access denied' dead giveaway don't have access.
i create credential variable , make sure credential has rights remote system. $creds = get-credential change code following (i added -scriptblock , bolded text
$servers = get-content "c:\users\anorris\desktop\dr\servers1.txt" foreach ($s in $servers) { invoke-command -computername $s -scriptblock {get-psdrive} -credential $creds }
Comments
Post a Comment