A bit confused on doing remote reports

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #5695

    by AevnsGrandpa at 2013-03-20 07:26:56

    I have downloaded and read through the Creating HTML Reports in Powershell ebook and am trying to put in place the concept in my environment. A few question for my better understanding;

    1. I am going into servers behind a firewall which I have opened ports 5985 and 5986. I am able to establish a remote PSSession and do remote commands through Invoke-Command. Am I correct is saying that Invoke-Command runs the script on the remote machine?

    2. If #1 is true then say I am doing the same convertto-html -fragment and then an out-string, how do I get that back to my client machine to assemble the strings into the final HTML report? Right now I am outputing it to that particular server as a html file

    3. I see to need to use the Invoke-Command when doing get-Wmiobject calls because if I don't I get RPC errors, this is normal?

    4. Lastly and this is more of how do I do it. I tried to run the NewEnhancedHTMLDemo and it failed on trying to import the EnhancedHTML module. Do I nede to copy that PSM1 file to a speicific location?

    Thanks,

    Jeff

    by Typeo at 2013-03-20 07:36:54

    I cant help you on all this, so hopefully somebody else might be able to jump in and give you more information.

    1. Invoke-Command is used to run commands on the remote machine you are connecting to. However, I am under the impression that depending on how you setup the command, some of them could be possibly trying to run on your local machine. However, once the information gets back to your local machine there is only a limited about of things you can do with it since it will be in a limited format. I am rather new myself, so hopefully, somebody with more knowledge can jump in here and add / correct me if I am wrong.

    4. Depending on where you are wanting to user the module / cmdlets you will need to put it on either the server or your local machine. Either way it will need to be placed in the following place 'C:\Users\UserName\Documents\WindowsPowerShell\Modules'. If the files paths don't exist you will need to create them.

    by mjolinor at 2013-03-20 08:05:44

    [quote]3. I see to need to use the Invoke-Command when doing get-Wmiobject calls because if I don't I get RPC errors, this is normal?
    [/quote]

    This is normal for a firewalled environment. Using GWMI to a remote computer uses RPC. RPC's run on arbitrary ports (negotiated by the RPC Port Mapper service). The only way to alow RPC thorugh a firewall is to allow the entire range of ports it might choose, so this is something that's not normally allowed by a firewall.

    By using invoke-command, you're sending the command to the remote machine to execute there, and getting the results back over a predictable port that's been allowed in the firewall rules.

    by MasterOfTheHat at 2013-03-20 12:06:39

    [quote]2. If #1 is true then say I am doing the same convertto-html -fragment and then an out-string, how do I get that back to my client machine to assemble the strings into the final HTML report? Right now I am outputing it to that particular server as a html file[/quote]
    Invoke-Command will execute on the remote machine whatever commands you tell it to, and it will return to you whatever you tell it to return. I know that sounds really RTFM, but hear me out...
    When you create an Invoke-Command command, you tell it which computer or list of computers you want to run something on, and you give it a script block or a script file that contains the commands you want to run on that computer. When it runs, Invoke-Command is going to return whatever the code in the script block would return to the console if you were running it locally on that machine, (almost). For example, if you structure the command like this:
    Invoke-Command -ComputerName computer01 -ScriptBlock { Get-Service IIS* }
    You are going to get back an object that contains all of the properties that would be included if you ran the "Get-Service IIS*" command at the console on computer01. You'll notice, though, that all of the methods that would normally be accessible to the returned object are not there, and there are few NoteProperty properties that Invoke-Command tags onto the returned object. See the difference below:
    PS > Invoke-Command -ComputerName computer01 -ScriptBlock { Get-Service IIS*} | Get-Member

    TypeName: Deserialized.System.ServiceProcess.ServiceController

    Name MemberType Definition
    ---- ---------- ----------
    ToString Method string ToString(), string ToString(string format, System.IFormatProvider formatProv...
    Name NoteProperty System.String Name=IISADMIN
    PSComputerName NoteProperty System.String PSComputerName=computer01
    PSShowComputerName NoteProperty System.Boolean PSShowComputerName=True
    RequiredServices NoteProperty Deserialized.System.ServiceProcess.ServiceController[] RequiredServices=SamSS HTTP ...
    RunspaceId NoteProperty System.Guid RunspaceId=c7db8c9b-565f-4f5a-99a6-167a8aa22415
    CanPauseAndContinue Property System.Boolean {get;set;}
    CanShutdown Property System.Boolean {get;set;}
    CanStop Property System.Boolean {get;set;}
    Container Property {get;set;}
    DependentServices Property Deserialized.System.ServiceProcess.ServiceController[] {get;set;}
    DisplayName Property System.String {get;set;}
    MachineName Property System.String {get;set;}
    ServiceHandle Property System.String {get;set;}
    ServiceName Property System.String {get;set;}
    ServicesDependedOn Property Deserialized.System.ServiceProcess.ServiceController[] {get;set;}
    ServiceType Property System.String {get;set;}
    Site Property {get;set;}
    Status Property System.String {get;set;}

    PS > get-service iis* | gm

    TypeName: System.ServiceProcess.ServiceController

    Name MemberType Definition
    ---- ---------- ----------
    Name AliasProperty Name = ServiceName
    RequiredServices AliasProperty RequiredServices = ServicesDependedOn
    Disposed Event System.EventHandler Disposed(System.Object, System.EventArgs)
    Close Method void Close()
    Continue Method void Continue()
    CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
    Dispose Method void Dispose(), void IDisposable.Dispose()
    Equals Method bool Equals(System.Object obj)
    ExecuteCommand Method void ExecuteCommand(int command)
    GetHashCode Method int GetHashCode()
    GetLifetimeService Method System.Object GetLifetimeService()
    GetType Method type GetType()
    InitializeLifetimeService Method System.Object InitializeLifetimeService()
    Pause Method void Pause()
    Refresh Method void Refresh()
    Start Method void Start(), void Start(string[] args)
    Stop Method void Stop()
    WaitForStatus Method void WaitForStatus(System.ServiceProcess.ServiceControllerStatus desiredStat...
    CanPauseAndContinue Property bool CanPauseAndContinue {get;}
    CanShutdown Property bool CanShutdown {get;}
    CanStop Property bool CanStop {get;}
    Container Property System.ComponentModel.IContainer Container {get;}
    DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;}
    DisplayName Property string DisplayName {get;set;}
    MachineName Property string MachineName {get;set;}
    ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;}
    ServiceName Property string ServiceName {get;set;}
    ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;}
    ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;}
    Site Property System.ComponentModel.ISite Site {get;set;}
    Status Property System.ServiceProcess.ServiceControllerStatus Status {get;}
    ToString ScriptMethod System.Object ToString();

    If you structure the command like this, though:
    PS > Invoke-Command -ComputerName computer01 -ScriptBlock { Get-Service IIS* | Export-Csv c:\temp\services.csv }
    You aren't going to get anything back because you wrote the output to a csv file on computer01.

You must be logged in to reply to this topic.