none
Disable User from Workstation RRS feed

  • Question

  • $Credential = Get-Credential
    $dc = New-PSSession -ComputerName Server -Credential $Credential
    Invoke-Command -Session $dc-script { Import-Module ActiveDirectory }
    Enter-PSSession $dcprime
    $user = Read-Host -Prompt "Please input username"
    Disable-ADAccount -Identity $user

    If I run this from a .ps1 it comes back with the error:

    Disable-ADAccount : The term 'Disable-ADAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    If I run it manually (copy and paste into existing PS window) it works just fine.

    Ideas?


    • Edited by ydde Friday, March 3, 2017 7:53 PM
    Friday, March 3, 2017 7:33 PM

Answers

  • $Credential = Get-Credential
    $dc = 'Server'
    $sb = {
    	Import-Module ActiveDirectory
    	$user = Read-Host -Prompt "Please input username"
    	Disable-ADAccount -Identity $user
    }
    Invoke-Command -Computer $dc -script $sb -Credential $cred


    \_(ツ)_/

    • Marked as answer by ydde Friday, March 3, 2017 9:56 PM
    Friday, March 3, 2017 8:04 PM

All replies

  • What is the exact error message? (Please copy and paste. Don't put your guess as to what the error was.)

    -- Bill Stewart [Bill_Stewart]

    Friday, March 3, 2017 7:34 PM
    Moderator
  • The AD module is not installed on the remote system or the remote is PS2.


    \_(ツ)_/

    Friday, March 3, 2017 8:00 PM
  • $Credential = Get-Credential
    $dc = 'Server'
    $sb = {
    	Import-Module ActiveDirectory
    	$user = Read-Host -Prompt "Please input username"
    	Disable-ADAccount -Identity $user
    }
    Invoke-Command -Computer $dc -script $sb -Credential $cred


    \_(ツ)_/

    • Marked as answer by ydde Friday, March 3, 2017 9:56 PM
    Friday, March 3, 2017 8:04 PM
  • Thanks!
    Friday, March 3, 2017 9:56 PM