Search code examples
powershellgroup-policytranscription

Powershell script - Transcript - How I disable it


I have got powershell script. Over scheduler I run bat file which run PS1 file.

BAT file

Powershell.exe -executionpolicy remotesigned -File script.PS1

PS1 file

$path = "D:\data";
$limit = (Get-Date).AddHours(-3);
Get-ChildItem -Path $path -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force;

In the same directory the powershell creates directories in format YYYYMMDD with files PowerShell_transcript.SERVER.t7eh07Gy.20230914031500.txt. Here is the entire script run.

For example: D:\data\20230914\PowerShell_transcript.SERVER.t7eh07Gy.20230914031500.txt D:\data\20230915\PowerShell_transcript.SERVER.t7eh07Gy.20230914031500.txt etc.

How do I disable it?

I have tried stop-transcript, and etc.

I need to stop transcript.


Solution

  • The start of transcription can be determined by group policy and executed independently of your script. Check the policy for example here:

    HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription
    

    If there is a EnableTranscripting value in this key and it isn't equal to zero, then transcription is enabled.