From 0e6e0e67127be8796547d884dd96833b918e20c5 Mon Sep 17 00:00:00 2001 From: Mahmoud149 Date: Sun, 12 Sep 2021 17:32:50 +0200 Subject: [PATCH] Check if the folder exists. --- ManageWECRegistry.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ManageWECRegistry.ps1 b/ManageWECRegistry.ps1 index adf5fff..8193f78 100644 --- a/ManageWECRegistry.ps1 +++ b/ManageWECRegistry.ps1 @@ -1,4 +1,10 @@ $subscription = 'Default' +$Folder = 'C:\scripts' +"Test to see if folder [$Folder] exists" +if (Test-Path -Path $Folder) { +} else { + md $Folder > $null +} if(Test-Path -Path C:\scripts\ManageWECRegistry.log){ Move-Item C:\scripts\ManageWECRegistry.log C:\scripts\ManageWECRegistry.log.bak -Force } @@ -19,4 +25,4 @@ $subscribed_computers | Where-Object { $computers -notcontains $_ } | ForEach-Ob "Removing computer $computer_name from WEC registry" | Out-File -FilePath C:\scripts\ManageWECRegistry.log -Append -Encoding ascii Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions\$subscription\EventSources\$computer_name" -Force -Verbose } -Get-Date | Out-File -FilePath C:\scripts\ManageWECRegistry.log -Append -Encoding ascii \ No newline at end of file +Get-Date | Out-File -FilePath C:\scripts\ManageWECRegistry.log -Append -Encoding ascii