raandree / NTFSSecurity

Managing permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap.
MIT License
431 stars 61 forks source link

Compatiblity with Powershell v5.1 #32

Closed thomasschuiki closed 6 years ago

thomasschuiki commented 6 years ago

Hi,

I'm experiencing the following problem. I can successfully install the module via install-module but after that get-module ntfssecurity does not return anything and import-module ntfssecurity shows that only very few cmdlets are beeing loaded.

My powershell version:

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.165
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.165
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

My OS version:

> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      17134  0

How i installed the module:

> find-module ntfssecurity | install-module -scope allusers

Nicht vertrauenswürdiges Repository
Sie installieren die Module aus einem nicht vertrauenswürdigen Repository. Wenn Sie diesem Repository vertrauen, ändern
 Sie dessen InstallationPolicy-Wert, indem Sie das Set-PSRepository-Cmdlet ausführen. Möchten Sie die Module von
'https://www.powershellgallery.com/api/v2/' wirklich installieren?
[J] Ja  [A] Ja, alle  [N] Nein  [K] Nein, keine  [H] Anhalten  [?] Hilfe (Standard ist "N"): A

Ouput of import-module:

>  import-module ntfssecurity -Verbose
AUSFÜHRLICH: Modul wird aus Pfad "C:\Program Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\ntfssecurity.psd1"
geladen.
AUSFÜHRLICH: "TypesToProcess" wird aus Pfad "C:\Program
Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\NTFSSecurity.types.ps1xml" geladen.
AUSFÜHRLICH: Die RepositorySourceLocation-Eigenschaft für das Modul ntfssecurity wird aufgefüllt.
AUSFÜHRLICH: Modul wird aus Pfad "C:\Program Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\NTFSSecurity.Init.ps1"
geladen.
AUSFÜHRLICH: DOT-Quellentnahme der Skriptdatei "C:\Program
Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\NTFSSecurity.Init.ps1".
AUSFÜHRLICH: Modul wird aus Pfad "C:\Program Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\NTFSSecurity.dll"
geladen.
AUSFÜHRLICH: Modul wird aus Pfad "C:\Program Files\WindowsPowerShell\Modules\ntfssecurity\4.2.3\NTFSSecurity.psm1"
geladen.
AUSFÜHRLICH: Alias "del2" wird importiert.
AUSFÜHRLICH: Alias "dir2" wird importiert.
AUSFÜHRLICH: Alias "gi2" wird importiert.
AUSFÜHRLICH: Alias "rm2" wird importiert.

After importing get-module reports back:

> get-module ntfssecurity

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     4.2.3      ntfssecurity                        {del2, dir2, gi2, rm2}

If I'm trying to use get-ntfsaccess I get the following error:

> get-ntfsaccess
get-ntfsaccess : Die Benennung "get-ntfsaccess" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei
oder eines ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist
(sofern enthalten), und wiederholen Sie den Vorgang.
In Zeile:1 Zeichen:1
+ get-ntfsaccess
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-ntfsaccess:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

This basically means that the cmdlet was not recognized.

The following returns nothing: > Get-Command -Module NTFSSecurity -Noun NTFSAccess

I am aware of the workaround of starting powershell with the -version parameter. Unfortunately that is not an option for me, as my scripts are depending on the newer version of posh.

Sorry for the german outputs I couldn't figure out how to completely change my powershell language yet.

Please let me know if you need any clarification or how I can help with any testing. Thanks for looking into this!

Best Regards, Thomas

raandree commented 6 years ago

Everything looks fine on one of my test machines running the same version of PowerShell:

PS C:\> Install-Module -Name NTFSSecurity -Force

PS C:\> Get-Command -Module NTFSSecurity

CommandType     Name                                               Version    Source                                                                      
-----------     ----                                               -------    ------                                                                      
Cmdlet          Add-NTFSAccess                                     4.2.3      NTFSSecurity                                                                
Cmdlet          Add-NTFSAudit                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Clear-NTFSAccess                                   4.2.3      NTFSSecurity                                                                
Cmdlet          Clear-NTFSAudit                                    4.2.3      NTFSSecurity                                                                
Cmdlet          Copy-Item2                                         4.2.3      NTFSSecurity                                                                
Cmdlet          Disable-NTFSAccessInheritance                      4.2.3      NTFSSecurity                                                                
Cmdlet          Disable-NTFSAuditInheritance                       4.2.3      NTFSSecurity                                                                
Cmdlet          Disable-Privileges                                 4.2.3      NTFSSecurity                                                                
Cmdlet          Enable-NTFSAccessInheritance                       4.2.3      NTFSSecurity                                                                
Cmdlet          Enable-NTFSAuditInheritance                        4.2.3      NTFSSecurity                                                                
Cmdlet          Enable-Privileges                                  4.2.3      NTFSSecurity                                                                
Cmdlet          Get-ChildItem2                                     4.2.3      NTFSSecurity                                                                
Cmdlet          Get-DiskSpace                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Get-FileHash2                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Get-Item2                                          4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSAccess                                     4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSAudit                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSEffectiveAccess                            4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSHardLink                                   4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSInheritance                                4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSOrphanedAccess                             4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSOrphanedAudit                              4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSOwner                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSSecurityDescriptor                         4.2.3      NTFSSecurity                                                                
Cmdlet          Get-NTFSSimpleAccess                               4.2.3      NTFSSecurity                                                                
Cmdlet          Get-Privileges                                     4.2.3      NTFSSecurity                                                                
Cmdlet          Move-Item2                                         4.2.3      NTFSSecurity                                                                
Cmdlet          New-NTFSHardLink                                   4.2.3      NTFSSecurity                                                                
Cmdlet          New-NTFSSymbolicLink                               4.2.3      NTFSSecurity                                                                
Cmdlet          Remove-Item2                                       4.2.3      NTFSSecurity                                                                
Cmdlet          Remove-NTFSAccess                                  4.2.3      NTFSSecurity                                                                
Cmdlet          Remove-NTFSAudit                                   4.2.3      NTFSSecurity                                                                
Cmdlet          Set-NTFSInheritance                                4.2.3      NTFSSecurity                                                                
Cmdlet          Set-NTFSOwner                                      4.2.3      NTFSSecurity                                                                
Cmdlet          Set-NTFSSecurityDescriptor                         4.2.3      NTFSSecurity                                                                
Cmdlet          Test-Path2                                         4.2.3      NTFSSecurity 

Is the execution policy restricted on that machine?

Importing the module with verose output looks like this:

PS C:\> Install-Module -Name NTFSSecurity -Force

PS C:\> Import-Module -Name NTFSSecurity -Verbose
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.psd1'.
VERBOSE: Loading 'TypesToProcess' from path 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.types.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module NTFSSecurity.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.Init.ps1'.
VERBOSE: Dot-sourcing the script file 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.Init.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.dll'.
VERBOSE: Importing cmdlet 'Add-NTFSAccess'.
VERBOSE: Importing cmdlet 'Clear-NTFSAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSEffectiveAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSOrphanedAccess'.
VERBOSE: Importing cmdlet 'Remove-NTFSAccess'.
VERBOSE: Importing cmdlet 'Add-NTFSAudit'.
VERBOSE: Importing cmdlet 'Clear-NTFSAudit'.
VERBOSE: Importing cmdlet 'Get-NTFSAudit'.
VERBOSE: Importing cmdlet 'Remove-NTFSAudit'.
VERBOSE: Importing cmdlet 'Set-NTFSInheritance'.
VERBOSE: Importing cmdlet 'Disable-NTFSAccessInheritance'.
VERBOSE: Importing cmdlet 'Disable-NTFSAuditInheritance'.
VERBOSE: Importing cmdlet 'Enable-NTFSAccessInheritance'.
VERBOSE: Importing cmdlet 'Enable-NTFSAuditInheritance'.
VERBOSE: Importing cmdlet 'Get-NTFSInheritance'.
VERBOSE: Importing cmdlet 'Get-ChildItem2'.
VERBOSE: Importing cmdlet 'Get-DiskSpace'.
VERBOSE: Importing cmdlet 'Get-Item2'.
VERBOSE: Importing cmdlet 'Copy-Item2'.
VERBOSE: Importing cmdlet 'Move-Item2'.
VERBOSE: Importing cmdlet 'Remove-Item2'.
VERBOSE: Importing cmdlet 'New-NTFSSymbolicLink'.
VERBOSE: Importing cmdlet 'New-NTFSHardLink'.
VERBOSE: Importing cmdlet 'Get-NTFSHardLink'.
VERBOSE: Importing cmdlet 'Get-FileHash2'.
VERBOSE: Importing cmdlet 'Enable-Privileges'.
VERBOSE: Importing cmdlet 'Disable-Privileges'.
VERBOSE: Importing cmdlet 'Get-Privileges'.
VERBOSE: Importing cmdlet 'Set-NTFSOwner'.
VERBOSE: Importing cmdlet 'Test-Path2'.
VERBOSE: Importing cmdlet 'Get-NTFSSecurityDescriptor'.
VERBOSE: Importing cmdlet 'Set-NTFSSecurityDescriptor'.
VERBOSE: Importing cmdlet 'Get-NTFSSimpleAccess'.
VERBOSE: Importing cmdlet 'Show-SimpleAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSOwner'.
VERBOSE: Importing cmdlet 'Get-NTFSOrphanedAudit'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.psm1'.
VERBOSE: Importing cmdlet 'Add-NTFSAccess'.
VERBOSE: Importing cmdlet 'Add-NTFSAudit'.
VERBOSE: Importing cmdlet 'Clear-NTFSAccess'.
VERBOSE: Importing cmdlet 'Clear-NTFSAudit'.
VERBOSE: Importing cmdlet 'Copy-Item2'.
VERBOSE: Importing cmdlet 'Disable-NTFSAccessInheritance'.
VERBOSE: Importing cmdlet 'Disable-NTFSAuditInheritance'.
VERBOSE: Importing cmdlet 'Disable-Privileges'.
VERBOSE: Importing cmdlet 'Enable-NTFSAccessInheritance'.
VERBOSE: Importing cmdlet 'Enable-NTFSAuditInheritance'.
VERBOSE: Importing cmdlet 'Enable-Privileges'.
VERBOSE: Importing cmdlet 'Get-ChildItem2'.
VERBOSE: Importing cmdlet 'Get-DiskSpace'.
VERBOSE: Importing cmdlet 'Get-FileHash2'.
VERBOSE: Importing cmdlet 'Get-Item2'.
VERBOSE: Importing cmdlet 'Get-NTFSAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSAudit'.
VERBOSE: Importing cmdlet 'Get-NTFSEffectiveAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSHardLink'.
VERBOSE: Importing cmdlet 'Get-NTFSInheritance'.
VERBOSE: Importing cmdlet 'Get-NTFSOrphanedAccess'.
VERBOSE: Importing cmdlet 'Get-NTFSOrphanedAudit'.
VERBOSE: Importing cmdlet 'Get-NTFSOwner'.
VERBOSE: Importing cmdlet 'Get-NTFSSecurityDescriptor'.
VERBOSE: Importing cmdlet 'Get-NTFSSimpleAccess'.
VERBOSE: Importing cmdlet 'Get-Privileges'.
VERBOSE: Importing cmdlet 'Move-Item2'.
VERBOSE: Importing cmdlet 'New-NTFSHardLink'.
VERBOSE: Importing cmdlet 'New-NTFSSymbolicLink'.
VERBOSE: Importing cmdlet 'Remove-Item2'.
VERBOSE: Importing cmdlet 'Remove-NTFSAccess'.
VERBOSE: Importing cmdlet 'Remove-NTFSAudit'.
VERBOSE: Importing cmdlet 'Set-NTFSInheritance'.
VERBOSE: Importing cmdlet 'Set-NTFSOwner'.
VERBOSE: Importing cmdlet 'Set-NTFSSecurityDescriptor'.
VERBOSE: Importing cmdlet 'Test-Path2'.
VERBOSE: Importing alias 'del2'.
VERBOSE: Importing alias 'dir2'.
VERBOSE: Importing alias 'gi2'.
VERBOSE: Importing alias 'rm2'.
raandree commented 6 years ago

When comparing the output it looks like the DLL is not processed correctly. Do you have any restrictions on using DLLs?

What happens if you try to import the DLL directly?

Import-Module 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.dll'
thomasschuiki commented 6 years ago

Hi,

thanks for the swift reply. Unfortunately the problem seems to be isolted to my machine.

I tried your commands on my machine and on a second one. The most obvious difference is the Windows Version Update 1803 vs 1709.

1803: not working 1709: working

I was not able to test with another 1803 machine.

The frustrating part is that there are no error messages while loading the module. Even the autocomplete for the commands works.

Some outputs:

[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 12:07:05 :
> Install-Module -Name NTFSSecurity -Force
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 12:07:21 :
> Get-Command -Module NTFSSecurity
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 12:07:29 :
> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy    Unrestricted
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 13:16:59 :
> Import-Module -Name NTFSSecurity -Verbose
AUSFÜHRLICH: Modul wird aus Pfad "C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.psd1"
geladen.
AUSFÜHRLICH: Alias "del2" wird importiert.
AUSFÜHRLICH: Alias "dir2" wird importiert.
AUSFÜHRLICH: Alias "gi2" wird importiert.
AUSFÜHRLICH: Alias "rm2" wird importiert.
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 13:17:12 :
> Import-Module 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.dll'
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 13:17:21 :
> Import-Module 'C:\Program Files\WindowsPowerShell\Modules\NTFSSecurity\4.2.3\NTFSSecurity.dll' -verbose
[Admin] (Elevated) adm_teitler@LCD11 C:\WINDOWS\system32 : 26.07.2018 13:17:26 :

Thanks again for helping me!

raandree commented 6 years ago

The big difference is that if you try to import the DLL directly, Import-Module does not list a single cmdlet exported by the DLL.

Can you verify if the DLL is blocked? Does the machine apply any policies from the domain that could explain the behaviour?

thomasschuiki commented 6 years ago

Hi,

sorry for the delay. I tried to use the module again today and installed version 4.2.4 and my issues are gone. Unfortunately I'm not able to tell you what changed exactly.

Thanks again for trying to debug my issues!