1

I have a script which uses a set of cmdlets which are on a Windows 2012 Domain Controller. I am using a Windows 7 machine which does not have these (Get-DHCPServerV4Lease for example).

At first I created a script module and applied it like this:

Invoke-Command -Computername <Server> -scriptblock {Get-ComputerStatus}

I then get an error message stating that the cmdlet is not recognised. Then I just converted it into a straight-forward PS1 script:

icm -cn <server> -FilePath .\ComputerInfo.ps1 -ArgumentList "Computer"

After running this I get an error saying that the various cmdlets I am using in the script are not recognised.

Get-DnsServerResourceRecord : The term 'Get-DnsServerResourceRecord' is not recognized as the name of a cmdlet,......

How can I run my script against a DC using Invoke-Command?

1
  • Do you have a Import-Module DNS* statement in the beginning of the script to import the dnsmodule on the remote computer (DC)? The first script failed because you didn't import the custom module on the remote computer. A remote computer can't use a module that you have imported on your local computer. Commented Apr 28, 2016 at 17:16

1 Answer 1

1

Adding to Frode F's comment, you need to first install the corresponding module on the target machine, which you specify as <server> in your Invoke-Command cmdlet. Then within your script, you need to import that module before you can execute cmdlets which are available via that module.

Invoke-Command -Computername <Server> -scriptblock 
{
    Import-Module  <moduleName> -ErrorAction SilentlyContinue
    Get-ComputerStatus
    #<Any othe cmdlets from the module>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.