Powershell question
Does anyone use powershell and if so how can in fix this script to auto login and not prompt for credentials?
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
$computer = Get-ADComputer -server MYSERVERNAME -searchbase "DC=Domain,DC=com" -Filter {passwordlastset -lt $time -and Name -like "*"}
$credential = New-Object System.Management.Automation.PsCredential ("OREILLY2\svc-account", (ConvertTo-SecureString "password" -AsPlainText -Force))
Invoke-Command -computername $computer.name -scriptblock { Reset-ComputermachinePassword -server server.domain.com -Credential $credential }
I still get prompted for creds even though they are in there perhaps i need to add enter-pssession?
0 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
isudothings
6 years ago
Invoke-Command won't lake locally scoped variables and apply them to a remote session.
Try it this way instead:
$DaysInactive = 90$time = (Get-Date).Adddays(-($DaysInactive))$computer = Get-ADComputer -server MYSERVERNAME -searchbase "DC=Domain,DC=com" -Filter {passwordlastset -lt $time -and Name -like "*"}Invoke-Command -computername $computer.name -scriptblock {$credential = New-Object System.Management.Automation.PsCredential ("OREILLY2\svc-account", (ConvertTo-SecureString "password" -AsPlainText -Force))Reset-ComputermachinePassword -server server.domain.com -Credential $credential}