0

When I tested this on the remote machine directly, it works perfectly.

Get-ItemProperty 'IIS:\Sites\Default Web Site\MySite' -Name physicalPath

However, when I try using the Invoke-Command syntax from my machine, it fails with

Cannot find drive. A drive with the name 'IIS' does not exist.

Invoke-Command -ComputerName RMMachine -ScriptBlock {
    Get-ItemProperty 'IIS:\Sites\Default Web Site\CIDashboard' -Name physicalPath
}

and if I make a script file with that command, that fails with the same error

Invoke-Command -ComputerName RMMachine -FilePath 'C:\PowerShell\GetSetIISPath.ps1'

As a long-shot, I tried Import-WebAdministration locally but no luck. Note that Copy-Item to that machine from mine works great ruling out any connection issues.

I am running PowerShell in Admin mode on both local and remote machines.

Further observation - I tried to execute the same command after doing a Enter-PSSession RMMACHINE and I am getting the same error! This means that the Get-ItemProperty works only if physically typed at the terminal on that machine. So, what authentication config am I missing? Note that I am logged in as the same AD user on both machines.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user1554876
  • 192
  • 3
  • 19
  • Have the remote code check to verify that the module is loaded in the remote session. – EBGreen Jun 21 '18 at 18:35
  • @EBGreen - It is loaded. I loaded it to get the command to run on the remote machine in the first place. – user1554876 Jun 21 '18 at 18:37
  • 1
    That would have been a different session. – EBGreen Jun 21 '18 at 18:39
  • 1
    Did you run `Import-Module WebAdministration` *inside* the `Invoke-Command` scriptblock? – Ansgar Wiechers Jun 21 '18 at 20:40
  • 1
    Just because you import a module on your LOCAL COMPUTER doesn't mean that module becomes available in a REMOTE SESSION. Import the module in the REMOTE SESSION. – Ansgar Wiechers Jun 21 '18 at 20:41
  • @EBGreen - Worked ! Thanks. I made the (wrong) assumption that once I imported the module on both machines, that would be sufficient. Ansgar - Thanks for your comment, I had imported on both machines but not before invoking the failed command every time. Still feeling my way around Powershell .... – user1554876 Jun 21 '18 at 21:37

0 Answers0