我编写了一个脚本,该脚本允许使用WinRM连接到Windows Server计算机,以便以高特权运行Windows Server计算机PS_Block_Access_Internet_GPO.ps1上存在的脚本。制作精良。
Enable-PSRemoting
Enter-PSSession -ComputerName Server.Admin.6NLG-AD -ScriptBlock {
$TaskName = "RunPSScript"
$User = "Admin\Server"
$Scriptpath="C:Users\Administrateur\Desktop\PS_Block_Internet_Access_GPO.ps1"
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-
executionpolicy bypass -noprofile -file $Scriptpath"
Register-ScheduledTask -TaskName $TaskName -User $User -Action $Action -
RunLevel Highest -Force}