#生成10到30的数组
$a=(10..30);
#初始化空的数组
$pcname=@();
#给数组赋值
$a | %{$pc = "shoa"+ $_; $pcname += "$pc"; };
$pcname | %{
    $computername = $_
        #先删掉已有的psdrive,防止报错
    Remove-PSDrive -Name "remotepcpath" -Confirm:$false;
        #生成新的psdrive,用于拷贝文件到目的服务器的指定位置
    New-PSDrive -name "remotepcpath" -PSProvider "FileSystem" -root "\\$computername\c$"
    Copy-Item -Path C:\Scripts -Destination remotepcpath: -Recurse
    #远程执行创建计划任务
    Invoke-Command -ComputerName $computername -ScriptBlock {
        $Action = New-ScheduledTaskAction -Execute ‘powershell.exe‘ -Argument ‘-NonInteractive -NoLogo -NoProfile -File "C:\Scripts\reboot.ps1"‘
        $trigger = New-ScheduledTaskTrigger -Daily  -At 3am
        $settings = New-ScheduledTaskSettingsSet
        $task = New-ScheduledTask -Action $Action -Trigger $trigger -Settings $settings
        Register-ScheduledTask -TaskName ‘reboot‘ -InputObject $task
    }   
}原文:https://blog.51cto.com/sampsondotqiu/2469967