Public/Import-ActiveDirectory.ps1
function Import-ActiveDirectory { <# .DESCRIPTION This command is primarily for use in powershell core. It will attempt to import the active directory module into Powershell Core, but if that fails it will fallback to using powershell for the module import. .Example Import-AD .Link Import-Module #> [CmdletBinding()] [Alias('Import-AD')] Param ( ) try { Import-Module ActiveDirectory Write-Host "Import AD module into the current host was successful!" -ForegroundColor Green } catch { try { Import-Module ActiveDirectory -UseWindowsPowerShell Write-Host "Import AD module failed for the current host. Imported by powershell!" -ForegroundColor yellow } catch { Write-Host "Import AD module failed for both methods" -ForegroundColor Red $_.Exception.Message } } } |