Powershell & C# to check if host available

Hi All,
I have a c# code segment which process a power-shell script. The following is the code segment.
Runspace objRunspace = null;
objRunspace = RunspaceFactory.CreateRunspace();
objRunspace.Open();
PowerShell powershell = PowerShell.Create();
powershell.Runspace = objRunspace;
powershell.AddScript("my powershell script");
Collection<PSObject> objPS1 = powershell.Invoke();
if (objPS1.Count == 0)
//I Assumes that the PC is down
In this case, If the login credentials are wrong or if that particular PC is not available; the ObjPS1.count will be zero. If that count is Zero, I assumes that the host is unavailable. But in accuracy point of view, I want to identify both these (wrong
credentials / host unavailable) situations separate. Is there a better way or different approach to achieve the same.
Thanks in advance
Sebastian

Hi Sebastian,
In addition, these examples may be helpful for you to handle the error when call powershell script in C#:
// invoke execution on the pipeline (collecting output)
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
// check the other output streams (for example, the error stream)
if (PowerShellInstance.Streams.Error.Count > 0)
// error records were written to the error stream.
// do something with the items found.
Reference from:
Executing PowerShell scripts from C#
Handling errors when calling PowerShell using C#
If you have any feedback on our support, please click here.
Best Regards,
Anna
TechNet Community Support

Similar Messages

  • Demo Examples Checking Flight Seat Availibility

    Hallo!
    I have a problem with the demo example 'checking flight seat availability (proxy to proxy Comunikation)
    The XI is installed on a virtual machine (VM-Ware). I can call the BSP on the virtual machine and on the host. But only on the host I can select the radiobutton.
    If I select the airline and a flight number and push the button 'check availability' I get an error message with error type: 'XI system error'
    and error details:
    Error by the determination of the business system.
    (Bei der Ermittlung des Business Systems ist ein Fehler aufgetreten(LD_ERROR))
    Sorry I don't know how to check the BSP. But i read it at the moment.
    Has someone an idea, what I must check!
    Thank you for help
    Thomas

    Hi Thomas,
    Check if this link is useful to fix your issue,
    Re: Cache Refresh does not work
    Regards
    Vishnu

  • Check price and availability shows no data

    Dear Experts,
    In the Check price and availability app, im trying to check the availability of a material on a particular date.
    Issue 1:
    The available stock quantity for material 953 is 260. There is no availability check maintained in material master(KP- no check)
    Say for eg, 29th may and quantity as 10 items for material 953, the app displays data as below. How is the estimated delivery date calculated as i ahve not maintained any planned delivery date in MMR.
    But when i check for this material 953 or 954 or 2390 or any other material for date 27th may or 29th may, it says stock is not available though the
    physical stock is listed for 260 pcs as below.
    Issue 2:
    The available stock of material 953 is only 260. when I check for 1000 quantities on 30th May, the system must say, stock is not available
    But however the app displays stock is available with the estimated delivery date. Im unable to find the cause of this output.
    Please guide me how to sort the issue.
    Please help as this issue is urgent.
    Thanks & Regards
    Dhinesh
    Message was edited by: Michael Appleby

    Hi Dhinesh
    I am Also facing this problem from long back. And we updated all the Patch level but i didnt get the solution.
    Please Share the Info if you find the Solution for this issue.
    Regards
    Prasanth SV

  • Need custom report on Host Availibility

    Hi,
    I want a custom report on Host Availibility can anyone suggest anything...
    regards
    sudip

    Hi,
    I want a custom report on Host Availibility can anyone suggest anything...
    regards
    sudip

  • I want to restore my ipod 4g to ios 6.1.2 but it said error code 3194 i updated itunes and i checked my host file and it won't work Thank you for choosing the Apple Store. If you have any additional questions, please chat us again. You are currently not i

    i want to restore my ipod 4g to ios 6.1.2 but it said error code 3194 i updated itunes and i checked my host file and it won't work and i am running 6.1.5 at the moment

    That's because downgrading is not supported.

  • How to check the host name or rename the host name in Enterprise Manager

    Hello,
    How do i check the host name or rename the host name in Enterprise Manager for Oracle 11g?
    Regards,
    Ming Man

    there is a shell script called chgip or something
    like that is there . I used it for IAS. I beleive the
    same is there for database too
    Rajesh AlexIf there is, I have not been able to find it.
    Off the top of my head, changing the host name involves at least the following (others feel free to add on):
    For listener and connectivity
    - listener.ora
    - tnsnames.ora (on all clients as well)
    - potentially ldap.ora (on all clients as well)
    - init.ora parameter LOCAL_LISTENER
    For admin using Enterprise Manager (starting 10g)
    - the contents of the sysman schema
    - the directory name of the OEM agent directory
    - the directory name of the OEM OC4J config directory
    - various config files in the OEM OC4J config directory
    Oracle provides the emca to handle this last set.
    In addition, the following refer to hosts that are [probably] not local
    - init parameter REMOTE_LISTENER (usually just points to a tnsnames.ora entry naming remote hosts)
    - init parm SMTP_OUT_SERVER
    Again, adding to the list might be interesting.

  • Check Price and Availability: is BAdI a must to fetch customer?

    Hi,
    While running the app Check Price and Availability, the screen (see the attachment) displays. Do I have to implement the BAdI BADI_SRA016_USR_TO_CUSTOMER to fetch customers? At the current stage, the user's access to the customer list are not limited and all customers should be accessible. How can I configure it?
    Best regards,
    ts

    Hi TS,
    You have to follow the Configuration Tasks maintained in APP Implementation.
    Configuration Tasks
    To enable Check Price and Availability, perform these configuration tasks:
    Map 0105 communication type for the employee PERNR to the system user ID.
    Enable the SRA016_PRICE_AVAIL_SRV SICF Services for the Gateway and SD_PRAV_MON SICF Services for UI5.
    Call transaction SIMGH to open the Check Price and Availability node to configure user information with the Sales Order Document type and Price Condition type in the SRA016_T_CONFIG table.
    Implement the following BAdIs:
    BAdI: Fetch CustomersYou can use this BAdI to fetch a list of customers associated with a specific employee.
    BAdI: Retrieve Product ImageYou can use this BAdI to retrieve the image of a product.
    Please double check these Config Tasks.
    You should implement the badi to fetch Customers associated with a specific employee
    You Can check this link for all the fiori Apps related BAdi s to implement
    SAP Fiori - BAdI quick reference
    Regards,
    Venu

  • I recently moved to USA from Canada. I have not changed my apple id but I have changed my phone and computer. Is there a way to retrieve my purchased music via iTunes? I checked what was available to download and only got a few digital booklets.

    I recently moved to USA from Canada. I have not changed my apple id but I have changed my phone and computer. Is there a way to retrieve my purchased music via iTunes? I checked what was available to download and only got a few digital booklets.

    Most Windows users don't.
    Purchase an external hard drive and use the backup software that comes with it to backup files from your computer.
    Buy TouchCopy and install it on your new computer, connect your old iPod and transfer your songs to your computer.

  • [solved] cli tool that repeatedly checks a host on a specified port

    can anyone recommend a command line tool that repeatedly checks a host on a specified tcp port?
    what i do now:
    - I reboot a server
    - I ping the host; when I see it replies, I know its networking is up
    - I use "nmap -PN -p 25 host" from time to time to check when the smtp service comes up
    I'm looking for a tool that does this port check repeatedly, like ping repeatedly checks for icmp echo replies...
    Last edited by zZyXx (2010-03-29 13:56:30)

    thanks. that should provide the desired functionality. I was looking for another tool because for some reason nmap takes a few seconds on this machine. I remembered reading about some tool that provided the functionality I described.
    I found it again: it was nping, a new development related to nmap, still alpha however...
    http://nmap.org/nping/

  • Powershell - Daily Health Check

    Hi all,
    I have a number of different w8k and w12k servers in different sites and I wanted create a daily health check to check services are up. For instance I can write a ps script to check run at 6am daily and check various services on a windows server and then
    generate a html report and mail it to a distribution list. However on some of my servers I only have one service that needs to be checked I wanted a was to check the services and collate all the reports into one place and output just one html report?
    So for example could I output the results to a text file, run an ftp job to send the result to a central location and then run a ps to scrap all the results and output to html, or could the text files be scrapped from an email, this method makes better sense
    for me as some of these servers will have ACLs between then and getting send via smtp will be easier then ftp.
    Would like to know if anyone has any ideas or experience with doing something like this?

    Are the servers on the same domain? If so use "Enter-PSSession" or if your just checking if a service is running use the "-Computer" switch to execute it on the remote server.
    You could also use WMI "Get-WMIObject"
    Using the above methods will let you run it from a central location. 
    My suggestion for performing your health checks is to define in a csv file: Server Name, IP, Heath Check Level
    So have an initial Ping for the host name, if that fails then use the IP as DNS might have an issue (record results into file)
    Heath Ckeck level determines if your just checking full server health or just checking for a specif service is running (ie Full, Service, ect... you define it for your requirements)
    I would use WMI as there could be different versions of powershell installed and take the compatibility issues away when writing the script.
    Below is a good starting script for you to use where it queries via WMI and generates a html report that is emailed out.
    https://gallery.technet.microsoft.com/scriptcenter/Powershell-Script-to-Get-78687c5e  
    Cheers,
    Martin
    Blog:
    http://sustaslog.wordpress.com 
    LinkedIn:
    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  • Executing PowerShell scripts on a remote host

    I need to execute a PopwerShell script on a remote host (i.e. to add or remove Windows features).
    The script uses some Powershell commands to be executed on the remote host (i.e. to add or remove Windows features).
    I made part of the job but I am unable to go on...
    After enabling PSremoting on the target host I run a script with the following commands:
    winrm s winrm/config/client '@{TrustedHosts="remoteserver"}'
    $mysession = new-pssession -computername remoteserver -credential remotedomain\remoteuser
    If I enter the above lines interactiverly I can go on interactively by entering:
    Enter-PSSession $mysession
    and execute all the PowerShell commands I need.
    My problem is that everything must be part of a script.
    I attempted using "Invoke-command" with no success: maybe there is a syntax error or it is not the right command to be used in a script.
    Can anybody please provede a sample of a script containing PowerShell commands to be executed on the remore host?
    Regards
    marius

    You're on the right track.  You can use Invoke-Command with the same credentials (or PSSession from New-PSSession, if you prefer) to execute code remotely.  The tricky thing, unfortunately, will be the credentials.  Right now you're being
    prompted to enter a username and password, but in an unattended script, you'd need to have these credentials saved somehow.  That can open up a can of worms, depending on your requirements.
    The simplest way to do this is to hard-code the password in your script.  No one on the planet recomments actually doing this, because well, you've just exposed an admin password to the world.
    The safest way to do this is to log on as the same account that will be used to run the script, on the same computer where the script will be run, and enter the credentials once manually, and export them to an XML file.  With this approach, the credentials
    in the XML file will be encrypted with the Windows Data Protection API (DPAPI), and the keys necessary to decrypt that data are only available to the current user, on the current computer.
    If you need to be able to securely save the data and have it read by other users, or on other computers, things start to get more complicated.
    Here's an example of the DPAPI approach:
    # to create the credential file
    $cred = Get-Credential
    $cred | Export-Clixml -Path c:\myEncryptedCreds.xml
    # to use it later (on the same computer, by the same user)
    $cred = Import-Clixml -Path c:\myEncryptedCreds.xml
    Invoke-Command -ComputerName SomeComputer -Credential $cred -ScriptBlock {
    Do-Something

  • For Dynamic Credit Check replacing Material Availability date with Delivery date

    Hi All,
    Our client has this requirement, where they want to change the standard SAP functionality which Checks whether a schedule line item in a sales order is with in horizon or not based on "Material Availability Date" VBEP-MBDAT. They want in place of this Delivery date of schedule line should be used i.e. VBEP-EDATU. I did some research and found out that this could be done technically by updating the BADI "BADI_SD_CM".
    Now we are stuck as to what needs to be changed? has anybody worked on this kind of requirement before?
    Please share your past experience.
    Thanks and Regards,
    Prateek Maheshwari.

    As you know, VBELN-Currency-POSNR-ETENR-MBDAT is standard exposure key of sales order but my ex-colleague changed it into VBELN-Currency-POSNR to compress exposure data for certain CCA.
    In this case, of course, that CCA should meet some biz requirements(User-exit. etc) like no partial delivery. etc.... for integrity of exposures..
    This case is different because you want to change value of key....and it's Date!!!!
    Anyway I think it's techinically possible but it's very risky in live system because existing exposures would be not removed even if delivered, changed, deleted or blocked.
    So you have to delete all exposures and rebuild after program changed.
    I'm writing it's possible now but I refused when my customer want to change it because I don't have any way to rebuild huge data in live system.

  • Is a 64-bit Linux RDBMS appliance on a Windows 7 64 bit host available?

    I have Cloudera Hadoop running with no issues. All I have are 32-bit Oracle Linux environments. It appears I need a 64-bit Oracle environment to install the connector because it has to have Hadoop installed atop of it.
    It there a 64-bit Oracle Linux virtual box or VM appliance for a Windows 7 64 host that I can use for testing? Even better, one that has the HADOOP connector and SQL Loader already installed?
    Rob

    We are planning a VM that will have 64 bit Linux with single node Hadoop, connectors and a database. I will post a note when it is available.
    Meanwhile, it is straightforward to have a 64 bit Oracle Database install and then add the Hadoop client that one of the connectors needs. The connectors documentation points to instructions for installing the Hadoop client.

  • I want to update my Mac from 10.6.8 to Mavericks, but every time it says update unavailable for this computer. How do I check for space available or how much space I  have used? Help please, I am new to using Mac computers.

    I am a new Mac user and I bought a refrubished Mac that has Mac OS X VERSION 10.6.8. I have been wanting to upgrade to Mavericks, but every time I go to do that a message comes up saying OS X Mavericks cannot be installed on this computer. Is there anyway I can instal it? Better yet how can I look up how much GB of memory I have and the available storage?

    1. No, but you might be able to upgrade to Lion. Choose About this Mac from the Apple menu, check that the computer has at least a Core 2 Duo(not Core Duo) CPU, and if so, click here.
    2. Check the RAM from the About this Mac window, choose Computer from the Finder's Go menu, control-click the internal drive, and choose Get Info. If the computer has a 32-bit EFI, it can't be upgraded to Mountain Lion or above regardless of the RAM and free drive space.
    (111990)

  • LMS 4.2.4 - report check "end host" list

    Hi All,
         I have a list of 26 "end host" identify by mac-address. I would like to generate every day a report to check that these devices exist on the network.
         If you can help me about this task? do i have to use "user tracking" ?
         Just for precision ...it is not "network device" but "end host" devices (PCs)
    Thanks for your help.
    Regards.

    Still no explanation from the experts?
    Thanks
    Lothar

Maybe you are looking for