Skip to content

Commit ba03a22

Browse files
committed
1.0.22 - Small bugfixes to the new functions to close files or sessions
1 parent 24469a1 commit ba03a22

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

FileShareUtils/FileShareUtils.psd1

32 Bytes
Binary file not shown.

FileShareUtils/FileShareUtils.psm1

+10-10
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public class Netapi
254254
ref Int32 resume_handle);
255255
256256
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
257-
public extern static int NetFileClose(string servername, int fileid);
257+
public extern static int NetFileClose(string servername, uint fileid);
258258
259259
[DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
260260
public static extern bool GetSecurityDescriptorDacl(
@@ -664,7 +664,7 @@ Function Get-NetShares{
664664
}
665665
}
666666

667-
$Shares | Sort-Object Path
667+
$Shares | Sort-Object Path,Name
668668

669669
# Cleanup memory
670670
[Netapi]::NetApiBufferFree($buffer) | Out-Null
@@ -1068,7 +1068,7 @@ Function Set-NetShare{
10681068

10691069
If($PSBoundParameters.ContainsKey('Permissions')){
10701070
If($Permissions){
1071-
# Cenvert and sort given permissions
1071+
# Convert and sort given permissions
10721072
$NewACL = Convert-ACLTextToShareACL $Permissions
10731073
$NewShareACLText = Convert-ShareACLToText $NewACL $True
10741074

@@ -1517,7 +1517,7 @@ Function Close-NetSession{
15171517
Force-closes an open session on a server
15181518
15191519
.DESCRIPTION
1520-
Closes an open session on a local or remote computer by user or client (IP seams to work)
1520+
Closes an open session on a local or remote computer by specifying user AND client IP
15211521
by using the NetAPI32.dll (without WMI)
15221522
15231523
.PARAMETER Server
@@ -1536,19 +1536,19 @@ Function Close-NetSession{
15361536
1.0 //First version 23.03.2020
15371537
15381538
.EXAMPLE
1539-
Close-NetSession -Server 'srv1234' -User 'TestUser'
1539+
Close-NetSession -Server 'srv1234' -User 'TestUser' -ClientIP '11.22.33.44'
15401540
15411541
Description
15421542
-----------
1543-
Closes the open session(s) of user "TestUser" on server srv1234
1543+
Closes the open session(s) of user "TestUser" comming from IP 11.22.33.44 on server srv1234
15441544
#>
15451545
[CmdletBinding()]
15461546
Param (
15471547
[Parameter(Position=0,Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
15481548
[string]$Server = ($env:computername).toLower(),
1549-
[Parameter(Position=1,Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
1549+
[Parameter(Position=1,Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
15501550
[string]$User,
1551-
[Parameter(Position=2,Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
1551+
[Parameter(Position=2,Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
15521552
[string]$ClientIP
15531553
)
15541554
Begin {
@@ -1559,7 +1559,7 @@ Function Close-NetSession{
15591559
$return = [Netapi]::NetSessionDel($Server,$ClientIPUNC,$User)
15601560

15611561
If($return -ne 0){
1562-
Throw ("Error during NetSessionDel for user $User or/and client $ClientIP on $Server : " + (Get-NetAPIReturnInfo $return))
1562+
Throw ("Error during NetSessionDel for user $User and client $ClientIP on $Server : " + (Get-NetAPIReturnInfo $return))
15631563
}
15641564
}
15651565
}
@@ -1712,7 +1712,7 @@ Function Close-NetOpenFiles{
17121712
[Parameter(Position=0,Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
17131713
[string]$Server = ($env:computername).toLower(),
17141714
[Parameter(Position=1,Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
1715-
[Int]$FileID
1715+
[UInt32]$FileID
17161716
)
17171717
Begin {
17181718
$return = [Netapi]::NetFileClose($Server,$FileID)

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ ConnectionType | This can be empty or showing the SMB version used (only with Le
194194

195195
#### Close-NetSession [[-Server] \<string>] [-User] \<string> [-ClientIP] \<string>
196196

197-
Closes an open session on a local or remote computer by user or client (IP seams to work). You have to specify a username or a client IP or both.
197+
Closes an open session on a local or remote computer by user AND client IP.
198198

199199
The following parameters
200200

201201
Property | Description
202202
---------|----------
203203
Server | The machine hosting the sessions, default is the local machine
204-
User | The name of the user
205-
ClientIP | The IP address of the client (find out with Get-NetSessions)
204+
**&#42; User** | The name of the user
205+
**&#42; ClientIP** | The IP address of the client (find out with Get-NetSessions)
206206

207207

208208
This function returns nothing.
@@ -213,7 +213,7 @@ This function returns nothing.
213213

214214
With this command you get a sorted (by path and user) list of all over SMB opened files on the machine or on a specified server.
215215
By specifying the left part of the local path the list is filtered to this path and subfolders.
216-
By adding the option -WithID the returned values contain also a FileID that can be used to use Close-NetSession
216+
By adding the option -WithID the returned values contain also a FileID that can be used to use Close-NetOpenFiles
217217

218218
The returned array of objects will have the following properties:
219219

@@ -229,7 +229,7 @@ FileID | ID of the open file (only with option -WithID)
229229

230230
#### Close-NetOpenFiles [[-Server] \<string>] [-FileID] \<int>
231231

232-
Closes an open session on a local or remote computer by user or client (IP seams to work). You have to specify a username or a client IP or both.
232+
Closes an open file or folder from a local or remote computer.
233233

234234
The following parameters
235235

0 commit comments

Comments
 (0)