@@ -254,7 +254,7 @@ public class Netapi
254
254
ref Int32 resume_handle);
255
255
256
256
[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);
258
258
259
259
[DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
260
260
public static extern bool GetSecurityDescriptorDacl(
@@ -664,7 +664,7 @@ Function Get-NetShares{
664
664
}
665
665
}
666
666
667
- $Shares | Sort-Object Path
667
+ $Shares | Sort-Object Path, Name
668
668
669
669
# Cleanup memory
670
670
[Netapi ]::NetApiBufferFree($buffer ) | Out-Null
@@ -1068,7 +1068,7 @@ Function Set-NetShare{
1068
1068
1069
1069
If ($PSBoundParameters.ContainsKey (' Permissions' )){
1070
1070
If ($Permissions ){
1071
- # Cenvert and sort given permissions
1071
+ # Convert and sort given permissions
1072
1072
$NewACL = Convert-ACLTextToShareACL $Permissions
1073
1073
$NewShareACLText = Convert-ShareACLToText $NewACL $True
1074
1074
@@ -1517,7 +1517,7 @@ Function Close-NetSession{
1517
1517
Force-closes an open session on a server
1518
1518
1519
1519
. 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
1521
1521
by using the NetAPI32.dll (without WMI)
1522
1522
1523
1523
. PARAMETER Server
@@ -1536,19 +1536,19 @@ Function Close-NetSession{
1536
1536
1.0 //First version 23.03.2020
1537
1537
1538
1538
. EXAMPLE
1539
- Close-NetSession -Server 'srv1234' -User 'TestUser'
1539
+ Close-NetSession -Server 'srv1234' -User 'TestUser' -ClientIP '11.22.33.44'
1540
1540
1541
1541
Description
1542
1542
-----------
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
1544
1544
#>
1545
1545
[CmdletBinding ()]
1546
1546
Param (
1547
1547
[Parameter (Position = 0 , Mandatory = $False , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
1548
1548
[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 )]
1550
1550
[string ]$User ,
1551
- [Parameter (Position = 2 , Mandatory = $False , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
1551
+ [Parameter (Position = 2 , Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
1552
1552
[string ]$ClientIP
1553
1553
)
1554
1554
Begin {
@@ -1559,7 +1559,7 @@ Function Close-NetSession{
1559
1559
$return = [Netapi ]::NetSessionDel($Server , $ClientIPUNC , $User )
1560
1560
1561
1561
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 ))
1563
1563
}
1564
1564
}
1565
1565
}
@@ -1712,7 +1712,7 @@ Function Close-NetOpenFiles{
1712
1712
[Parameter (Position = 0 , Mandatory = $False , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
1713
1713
[string ]$Server = ($env: computername ).toLower(),
1714
1714
[Parameter (Position = 1 , Mandatory = $True , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
1715
- [Int ]$FileID
1715
+ [UInt32 ]$FileID
1716
1716
)
1717
1717
Begin {
1718
1718
$return = [Netapi ]::NetFileClose($Server , $FileID )
0 commit comments