ADScripts/Nuke-Process.ps1

71 lines
1.3 KiB
PowerShell
Raw Normal View History

2023-09-14 11:13:58 -06:00
##Make a script that nukes open file sessions ____SMB file session with a filepath as a input. that displays a list of who has the file open with the type of open(read, write) and then ask yes or no to nuke the open file session
##Script used to nuke open sessions on any file server
##Server Name: Lbsf01
##Ask what server you want to use in the future
##
Import-Module SMBShare
if(!$creds){
$creds = Get-Credential
}
$serverName = Read-Host "What is the server name?"
Enter-PSSession -Credential $creds -ComputerName $servername
##$FilePath = Read-Host "Enter the file path"
$Sessions = Get-SmbOpenFile -server lbfs01.mpe.ca
<#
if ($Sessions) {
Write-Host "The following users have the file open:"
foreach ($Session in $Sessions) {
Write-Host "User: $($Session.UserName) Open Mode: $($Session.OpenMode)"
}
$Confirm = Read-Host "Do you want to nuke the open file sessions? (Y/N)"
if ($Confirm -eq "Y") {
foreach ($Session in $Sessions) {
Close-SmbOpenFile -Path $FilePath -SessionId $Session.SessionId
}
Write-Host "The open file sessions have been nuked."
} else {
Write-Host "The open file sessions have not been nuked."
}
} else {
Write-Host "No open file sessions found for the specified file."
}
Exit-PSSession
#>