Как настроить запуск скрипта PowerShell через GPO (только один раз)?

Garett

Почетный гость
Добрый день! У меня такой вопрос - нужно сформировать групповую политику в домене таким образом, чтобы запустить на некоторых рабочих станциях PowerShell-скрипт. Все это я реализовал, при входе в систему автоматически запускается скрипт и устанавливает требуемое ПО. Но мне нужно это делать один раз, чтобы при последующих вхождениях в сеанс скрипт уже не запускался - можно ли это сделать? Как настроено у меня:

User configuration->Policies->Windows settings->Scripts (Logon/Logoff)->вкладка PowerShell scripts:
Script name: \\share.domain.ru\Scripts$\MyPSScript.ps1
Script parameters: -Noninteractive -ExecutionPolicy Bypass -Noprofile

Но в этом параметре нет опций вроде "запускать только один раз" - что можно придумать? Спасибо за помощь.
 
Steps to Configure a One-Time PowerShell Script Execution via GPO:

  • Create or Edit a GPO:
    Open the Group Policy Management Console (GPMC), create a new GPO, or edit an existing one that is linked to the Organizational Unit (OU) containing the target computers or users.
    • Computer Configuration > Preferences > Control Panel Settings > Scheduled Tasks (for computer-based tasks)

    • User Configuration > Preferences > Control Panel Settings > Scheduled Tasks (for user-based tasks)
  • Create a New Scheduled Task:
    Right-click on Scheduled Tasks, select New, and then choose Immediate Task (At least Windows 7) for a task that runs as soon as the GPO is applied and processed.
    • General Tab: Provide a name for the task.

    • Actions Tab: Click New, set the Action to Start a program.
      • For Program/script, enter powershell.exe.

      • For Add arguments (optional), provide the path to your PowerShell script and any necessary execution policy bypass, for example: -ExecutionPolicy Bypass -File "\\YourDomain\SYSVOL\YourDomain\scripts\YourScript.ps1". Ensure the script path is a UNC path accessible by the target machines.
    • Common Tab: Crucially, check the box for "Apply once and do not reapply". This setting ensures the scheduled task is created and executed on the target machine only once.
  • Link and Apply the GPO:
    Link the GPO to the appropriate OU in Active Directory. The GPO will be applied to the target computers or users based on standard Group Policy processing. The scheduled task will then be created and executed one time on each target when the GPO is processed.
 
Назад
Верх