# Using Invoke-Command to get Website Info

**URL:** <https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895>\
**Category:** PowerShell Help\
**Created:** [January 20, 2017, 4:56pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895 "2017-01-20T16:56:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 4:56pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/1 "2017-01-20T16:56:46Z")

</div>

Invoke-Command -ComputerName SERVERNAME -ScriptBlock {Import-Module ‘WebAdministration’; Get-ChildItem -Path IIS:\Sites}

When I use this command on all Win2012 R2 servers and 90% of Win2008 R2 I get information back from remote servers. But on a couple of Win2008 R2 I don’t get an error I just get the PS\> prompt with no info. What needs to be turned on these Win2008 R2 to get the information. Enable-Remoting -Force is turned on. I did a WinRM Quickconfig but nothing. I’ve compared the Win2008 R2 servers that work with the ones that don’t work and can’t seem to find the difference.

Thanks

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 4:58pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/2 "2017-01-20T16:58:45Z")

</div>

Well… we need to maybe troubleshoot. You’ve run a lot of stuff but I’m not sure if it’s helping or hurting.

On one of the not-working machines, can you just

Invoke-Command -ComputerName WHATEVER -Script { Dir c:\ }

And get results?

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:01pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/3 "2017-01-20T17:01:24Z")

</div>

Yes, I got a directory of info on the remote server.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 5:03pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/4 "2017-01-20T17:03:18Z")

</div>

OK, great. So Remoting is fine. All that Enable-PSRemoting and WSMan Quickconfig was for naught ;).

The problem, then, is with WebAdministration. Are you able to log on to one of those servers’ consoles and run:

Import-Module ‘WebAdministration’  
Get-ChildItem -Path IIS:\Sites

And get anything? Whilst making a note of the user account you use to do this?

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:07pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/5 "2017-01-20T17:07:20Z")

</div>

Import-Module worked with no errors and Get-Childitems returned what I was looking for using the Invoke-Command.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 5:09pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/6 "2017-01-20T17:09:32Z")

</div>

EXCELLENT. Now we’re making progress. The components all work, just not together. I’m assuming that one of the following two are true, but I want you to confirm:

1. When you run Invoke-Command, you’re logged onto your computer as the same user that you just used to log onto the servers’ consoles, and your computer and the servers are all in the same domain or in trusting domains

OR

1. When you run Invoke-Command, you specify -Credential and provide the same username that you just used to log onto the servers’ consoles.

Is one or both of these true?

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:12pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/7 "2017-01-20T17:12:16Z")

</div>

1. Yes
2. I don’t provide -Credentials because my credentials are Admin credentials and I don’t use -Credentials for the 40 servers that work okay.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 5:14pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/8 "2017-01-20T17:14:51Z")

</div>

I know you don’t do this for the ones that are working, but these ones aren’t working, so we take some extra steps to try and pinpoint the problem. One potential problem is credential delegation not working for some reason; were you to try #2 and explicitly provide a credential, it’d eliminate that as a possibility. We’ve already determined that Remoting is fine, and that the WebAdministration module works. So we have to start branching out and testing other things.

Additionally, try using Enter-PSSession to connect to a non-working server, load WebAdministration and try your IIS: drive. Do you get results, or still just a blank prompt, or maybe an error message? You can do this with or without -Credential.

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:17pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/9 "2017-01-20T17:17:40Z")

</div>

Can you give me the Enter-PSSession commands / load WebAdministration command you want me to enter so I can do exactly like you want.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 5:19pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/10 "2017-01-20T17:19:48Z")

</div>

Yup!

```
Enter-PSSession -ComputerName WHATEVER
Import-Module 'WebAdministration'
Get-ChildItem -Path IIS:\Sites
Exit
```

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:23pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/11 "2017-01-20T17:23:04Z")

</div>

Everything worked like a charm and I got results.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 20, 2017, 5:26pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/12 "2017-01-20T17:26:04Z")

</div>

Well. That is odd.

```
Invoke-Command -ComputerName WHATEVER -Script { Import-Module 'WebAdministration'; Start-Sleep 5000; Get-ChildItem -Path IIS:\Sites }
```

How about that? See, Enter-PSSession and Invoke-Command do the exact same thing, in the same way. Enter-PSSession wasn’t supposed to work. The only thing I can think of is some kind of timing in WebAdministration loading, so I’m having you try Start-Sleep.

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 20, 2017, 5:28pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/13 "2017-01-20T17:28:46Z")

</div>

No error… just came back with a Prompt again.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 21, 2017, 1:31am UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/14 "2017-01-21T01:31:14Z")

</div>

Kind of sheepish here, because I’m new, but could you run the following code?

```
Invoke-Commmand -ComputerName Computer -ScriptBlock {([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")}
```

If that returns false, you may be running into a weird UAC issue. Might try running your console as administrator and giving the code above another try. Should return true if you have elevated rights (which is needed to import the WebAdministration Module).

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 23, 2017, 9:48pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/15 "2017-01-23T21:48:16Z")

</div>

I solved half the problem. It must be a firewall issue. I RDP into another server and ran the invoke-command to all the servers that showed just a prompt and it worked fine. I got the results. My PC from home via VPN must be blocking results from these servers.

Derek

---

<div class="post-metadata">

**Author:** ![dgsonic](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dgsonic](https://forums.powershell.org/u/dgsonic)\
**Post date:** [January 23, 2017, 9:49pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/16 "2017-01-23T21:49:24Z")

</div>

I got a TRUE results… as mentioned on another reply …

I solved half the problem. It must be a firewall issue. I RDP into another server and ran the invoke-command to all the servers that showed just a prompt and it worked fine. I got the results. My PC from home via VPN must be blocking results from these servers.

Derek

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/using-invoke-command-to-get-website-info/7895/17 "2024-05-16T20:39:22Z")

</div>


