Hello @Anonymous ,
I just tried running in a separate CMD window and it went past.
- Open the command window in Admin Mode
- Browse to the path where the script is placed
- Run the script
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I was wondering how can I rerun or close this script? tried multiple ways but keep on failing :/. Your help is greatly appreciated
$CredAuth = "No"
Do {
$Cred = $null
$Domain = $null
$Root = $null
$userName = $null
$Password = $null
$Cred = $Host.UI.PromptForCredential("Need Credentials", "Please enter your A- Account username and password. Example: domain\a-jdoe", "","NetBiosUserName")
if(!$Cred)
{
return
}
Try
{
$userName = $Cred.username
$Password = $Cred.GetNetworkCredential().password
$Root = "LDAP://" + ([ADSI]'').DistinguishedName
$Domain = New-Object System.DirectoryServices.DirectoryEntry($Root,$Username,$Password)
}
Catch
{
Continue
}
If(!$Domain)
{
}
Else
{
If ($domain.Name -ne $null)
{
$CredAuth ="Yes"
}
}
} While ($CredAuth -eq "No")
$ComputerName = Read-Host -Prompt 'Computer Name to Process'
if ($ComputerName) {
Write-Host "We can now use the computer name [$ComputerName] in our code"
} else {
Write-Warning -Message "No Compouter Name Input"
}
foreach ($computer in $ComputerName.Split(" "))
{
if (Test-Connection -ComputerName $Computer -ErrorAction SilentlyContinue)
{
Write-host ("About to clean : "+$computer)
$disk = ([wmi]"\$Computer\root\cimv2:Win32_logicalDisk.DeviceID='c:'")
"$Computer C: has {0:#.00} GB free of {1:#.00} GB Total - Before Cleaning" -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output
Write-output "Cleaning is in progress, Please wait"
Remove-Item -Force -erroraction 'silentlycontinue' \$ComputerName\c$\Windows\Temp* -Recurse
Remove-Item -Force \$computername\c$\windows\ccmcache* -Recurse
Remove-Item -Force \$computername\C$\$Recycle.Bin*
Invoke-Command -computername $computername -ScriptBlock {Clear-RecycleBin -DriveLetter C -force -ErrorAction SilentlyContinue}
$disk = ([wmi]"\$Computer\root\cimv2:Win32_logicalDisk.DeviceID='c:'")
"$Computer C: has {0:#.00} GB free of {1:#.00} GB Total - After Cleaning" -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output
""
"_________________________________________________________________"
}
}
Hello @Anonymous ,
I just tried running in a separate CMD window and it went past.
Hello
Thank you for your question and reaching out.
I can understand you are having some issues \ queries related to rerun or close a scripts after executed.
Using Exit will exit PowerShell too. If you wish to "break" out of just the current function or script - use Break.
For Example :
Write-Host " Please Read this before the PowerShell session closes!!"
Start-Sleep -Seconds 10
Exit
--If the reply is helpful, please Upvote and Accept as answer--