Hi,
why is “Add-Type” flooding my windows temp folder with empty folders? take a look at my sample script, it creates 5 empty folders inside the temp folder. (when running as admin)
# Loop to run the job 5 times
for ($i = 1; $i -le 5; $i++) {
# Start a background job (script block)
$job = Start-Job -ScriptBlock {
# .Net methods for hiding/showing the console in the background (running in background job)
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
function Show-Console {
$consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 4) # Show the console window
}
function Hide-Console {
$consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 0) # Hide the console window
}
# Hide the console window in the background job
Hide-Console
# Simulate some work
Start-Sleep -Seconds 1
# Show the console window again
Show-Console
}
# wait for each job to complete before starting the next one
Wait-Job -Job $job
Receive-Job -Job $job
# Clean up the background job after each iteration
Remove-Job -Job $job
# Pause between job executions
Start-Sleep -Seconds 1
}
Write-Host "All jobs have been executed."