Skip to content

Instantly share code, notes, and snippets.

@technion
Created April 12, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/e3cb627b010c49bd6517609d726b0204 to your computer and use it in GitHub Desktop.
Save technion/e3cb627b010c49bd6517609d726b0204 to your computer and use it in GitHub Desktop.
Param(
[Parameter(Mandatory=$true)]
[string]$FileOwner,
[string]$Unlock
)
$Shares = Get-WmiObject -Class win32_share -filter "type=0 and not name like 'PRINT$' and not name like 'SYSVOL' and not name like 'NETLOGON'"
if ($Unlock) {
ForEach ($Share in $Shares) {
UnBlock-SmbShareAccess -Name $Share.Name -AccountName $FileOwner -force
}
}
else {
ForEach ($Share in $Shares) {
Block-SmbShareAccess -Name $Share.Name -AccountName $FileOwner -force
}
$SMBsession = get-smbsession | where {$_.ClientUserName -like "*$FileOwner*"}
ForEach ($Session in $SMBsession) {
Close-smbsession -SessionId $Session.SessionId -force
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment