Author Posts

August 3, 2017 at 8:26 am

Guys, you helped me so much this week. Last question to complete everything

I've got on every server (+-150) my reboot schedule task. but every month i would like to restart the servers after patching.

I created the following:

$servers = Get-Content C:\temp\servers.txt
$DateTime = Read-Host "Date and Time (MM/DD/YY)"
$User = Read-host "Admin username"
$Password = Read-Host "Enter Password" -AsSecureString

foreach ($server in $servers)
{
Enter-PSSession $server
$Time = New-ScheduledTaskTrigger -At $DateTime -Once
Set-ScheduledTask -TaskName "Rebootserver" -Trigger $Time -User nbdbiblion\$user -Password $password
Exit-PSSession
}

I works, but i creates only locally on my computer but i would like to create it on the servers. I think inovke-command wil not work because of the variables that are needed.

Thanks again.

August 3, 2017 at 9:08 am

Thanks simon but that not what i am looking for because i have already deployment other scripts on my severs. There has to be a way to do it like i posted above?

August 3, 2017 at 9:12 am

Are your servers in the same OU ?

August 3, 2017 at 9:19 am

Yes they are, but i would like to manage which servers are about to restart so not all servers in the OU

August 3, 2017 at 11:26 am

Enter-PSSession for interactive use only

you should use Invoke-Command with $using: variable prefix

look at example 9 for Invoke-Command