none
PowerShell Script activity basic Query

    Question

  • Hello,

            Before asking my question, Let me introduce myself. I'm really Poor @ Scripting and PowerShell related stuffs. I have a very basic Query in PowerShell, I have to execute some of the PowerShell command (Hyper-V, Lync etc..) in target machine using Runbook activity.

    Commands:

    1.   Get-VM (Hyper-V)
    2.   Get-CSwindowsservice (Lync)

    When I'm executing the below Command from local PowerShell windows its listing all the services & VM's along with the status.

    Questions:

    01.How do I use the same commands within PowerShell activity - I need the Format

    02. How to get the Service & VM status for next activity

    03. Which is the best activity for this requirement (Run program, .Net script or Powershell IP)

    Regards,
    Julie

    Monday, December 23, 2013 4:59 AM

Answers

  • 01.How do I use the same commands within PowerShell activity - I need the Format

    $password =convertTo-secureString -string "Password" -asPlainText -force;  

    $credential = new-object System.Management.automation.Pscredential ("UserName" , $password);

    $session = New-PSSession -computername [COmputerName] -credential $credential -port 5985 -Authentication Default;

    Try{

    $cmd=invoke-command -session $session -scriptblock{Get-cswindowsservice } | fl | out-string

        }

    Remove-PSSession -Session $Session;

    }

    Catch

    {

       $RetVal = "Error23: " + $error[0].Exception.toString()

    $cmd

    }

    02. How to get the Service & VM status for next activity

    By Publishing $cmd from above activity we can get the Service status and VMstatus can be checked using Get-VM activity

    03. Which is the best activity for this requirement (Run program, .Net script or Powershell IP)

    .Net script

    • Marked as answer by Juliesmiley Sunday, January 05, 2014 5:50 PM
    Sunday, January 05, 2014 5:50 PM

All replies

  • Can someone please help me on this Query?

    Regards,
    Julie

    Monday, December 23, 2013 4:51 PM
  • No One is ready to Help me :( so sad

    Regards,
    Julie

    Tuesday, December 24, 2013 7:40 AM
  • 01.How do I use the same commands within PowerShell activity - I need the Format

    $password =convertTo-secureString -string "Password" -asPlainText -force;  

    $credential = new-object System.Management.automation.Pscredential ("UserName" , $password);

    $session = New-PSSession -computername [COmputerName] -credential $credential -port 5985 -Authentication Default;

    Try{

    $cmd=invoke-command -session $session -scriptblock{Get-cswindowsservice } | fl | out-string

        }

    Remove-PSSession -Session $Session;

    }

    Catch

    {

       $RetVal = "Error23: " + $error[0].Exception.toString()

    $cmd

    }

    02. How to get the Service & VM status for next activity

    By Publishing $cmd from above activity we can get the Service status and VMstatus can be checked using Get-VM activity

    03. Which is the best activity for this requirement (Run program, .Net script or Powershell IP)

    .Net script

    • Marked as answer by Juliesmiley Sunday, January 05, 2014 5:50 PM
    Sunday, January 05, 2014 5:50 PM