SOAP Example

This is a bit of example code for connecting to a SOAP API that uses an auth call and cookies for logging into the API. For more complex type like xml you will have to handle the output.

# Connection vars
$HostName = ''
$UserName = ''
$Password = ''
$SoapUrl = "http://$HostName/soap3/api.wsdl";
$Client = New-WebServiceProxy -Uri $SoapUrl
$Client.CookieContainer = New-Object System.Net.CookieContainer
if(!$Client.authenticate($UserName, $Password))
{
    Write-Host -BackgroundColor black -ForegroundColor red "Unable to connect to $HostName"
}
$Client.getAuthenticatedLevel()
$a = $Client.core_getDevices()
$a.getType()
$a

EVE PI

This is a script i wrote to see if i was making ISK in eve by importing PI basic or refined commodities and making Specialized commodities.  At some point I want to make this script do all PI commodities but for now its setup for robots.  If you know your item IDs you can edit it for your commodities.

param([switch]$Debug)
if($Debug){$DebugPreference = 'Continue'}
Write-Debug "ON"

$ItemIDs = @{
    "ReactiveMetals" = 2398
    "PreciousMetals" = 2399
    "ToxicMetals" = 2400
    "ChiralStructures" = 2401
    "MechanicalParts" = 3689
    "ConsumerElectronics" = 9836
    "Robotics" = 9848
}

$Items = @{
    2398 = "ReactiveMetals"
    2399 = "PreciousMetals"
    2400 = "ToxicMetals"
    2401 = "ChiralStructures"
    3689 = "MechanicalParts"
    9836 = "ConsumerElectronics"
    9848 = "Robotics"
}

function GetPriceData
{

    param
    (
        $IDs,
        $Region = 10000002 #the forge
    )

    $IDString = ''
    $IDs | %{$IDString += "typeid="+"$_"+'&'}
    
    $XMLString = "http://api.eve-central.com/api/marketstat?"+"$IDString"+"regionlimit=$Region"
    $XML = New-Object system.xml.xmldocument
    $XML.load($XMLString)
    
    Write-Debug $XMLString
    
    #$BaseNode = "/evec_api/marketstat"
    
    $Returns = @{}
    $Root = $XML.evec_api.marketstat
    foreach($Node in $Root.ChildNodes)
    {
        [int32]$TypeID = $Node.id
        $Buy = $Node.buy
        $Sell = $Node.sell

        Write-Debug $ItemsIDs[$TypeID]

        $Returns[$Items[$TypeID]] = New-Object -TypeName PSObject -Property (@{
        'ID' = $TypeID
        'SellPrice' = [double]$Sell.min
        'BuyPrice' = [double]$Buy.max})
    }
       
    return $Returns

}

$BasicQuantity = 80
$RefinedQuantity = 10
$SpecializedQuantity = 3
$BasicTax = 2000 # per 80
$RefinedTax = 4500 # per 10
$SpecializedTax = 21000 # per 3
$SalesTax = 0.01 # lv5 sales tax

$PriceData = GetPriceData (
    $ItemIDs.ReactiveMetals,
    $ItemIDs.PreciousMetals,
    $ItemIDs.ToxicMetals,
    $ItemIDs.ChiralStructures,
    $ItemIDs.MechanicalParts,
    $ItemIDs.ConsumerElectronics,
    $ItemIDs.Robotics
    )


if(!$PriceData){Write-Debug 'Nothing returned'}

$Sales = $PriceData.Robotics.BuyPrice * $SpecializedQuantity * (1 - $SalesTax)

#this bit needs to be a function for things other then robotics

$Costs = ($PriceData.ReactiveMetals.SellPrice * $BasicQuantity`
    + $PriceData.PreciousMetals.SellPrice * $BasicQuantity`
    + $PriceData.ToxicMetals.SellPrice * $BasicQuantity`
    + $PriceData.ChiralStructures.SellPrice * $BasicQuantity)`
    * (1 + $SalesTax)
    
$Tax = 4 * $BasicTax + $SpecializedTax

$Profits = ($Sales - $Costs) - $Tax

if($Profits -ge 0){$Color = "Green"}
else{$Color = "Red"}

Write-Host -ForegroundColor $Color "Basic:" $Profits "Per Day:" ($Profits*24)

$Costs = ($PriceData.MechanicalParts.SellPrice * $RefinedQuantity`
    + $PriceData.ConsumerElectronics.SellPrice * $RefinedQuantity)`
    * (1 + $SalesTax)
    
$Tax = 2 * $RefinedTax + $SpecializedTax

$Profits = ($Sales - $Costs) - $Tax

if($Profits -ge 0){$Color = "Green"}
else{$Color = "Red"}

Write-Host -ForegroundColor $Color "Refined:" $Profits "Per Day:" ($Profits*24)

Who

This is my attempt to create a command similar to Linux’s who command.  Basically all this is doing is using WMI to see who the logged on user is, this is the key line:

Get-WMIObject Win32_Computersystem -Comp $Hostname -ev myError -ea SilentlyContinue | Select Name, UserName

Here is the full script with help doc and exception handling:

##############################
# Author: Erich Cottom
# Copyright: Erich Cottom http://erichcottom.com
# Title: Who
# Description: This script gets the current loged on user of the local or remote computer
##############################

# who 1.0.0 - inital release
# who 1.0.1 - added default local hostname fixed trap exception
# who 1.1.0 - trap statment now only for dns
# who 1.1.1 - fixed dns trap to reset on fail
# bug - rdp user appear as not logged on

<#
.SYNOPSIS
This script acts like Linux's who command

.DESCRIPTION
This command uses WMI to get the user who is currently logged onto the system.

.PARAMETER Hostnames
A list of Hostnames to inquire about logged on users

.EXAMPLE
who.ps1 mycomp

Name                                                        UserName
----                                                        --------
mycomp                                                      MYCOMP\myuser

.EXAMPLE
who.ps1 pc1,pc2,pc3,pc4,pc5

Name                                                        UserName
----                                                        --------
pc1                                                         DOMAIN\user1
pc2                                                         DOMAIN\user2
pc3                                                         DOMAIN\user3
pc4                                                         DOMAIN\user4
pc5                                                         DOMAIN\user5

.NOTES
.LINK
#>

##############
# MAIN
##############

param
(
	[parameter(Mandatory=$true,ValueFromPipeline=$true)] $Hostnames = $env:computername
)

$Hostnames = $Hostnames | get-unique

foreach ($Hostname in $Hostnames)
{
	# Test if hostname will resolve to ip
	$DnsTest = [System.Net.Dns]::GetHostEntry("$hostname")
	trap [System.Net.Sockets.SocketException]
	{

		Write-Output "$hostname has no dns reccord" | Write-Host -ForegroundColor Red -BackgroundColor Black

		$DnsTest.AddressList = $null
		continue
	}
	if($DnsTest.AddressList -ne $null)
	{
		# Ping test
		$Ping = new-object System.Net.NetworkInformation.Ping
		$Reply = $Ping.Send($Hostname)
		$PingTest = $Reply.status
		if ($PingTest -eq "Success")
		{
			# Get logged on user
			Get-WMIObject Win32_Computersystem -Comp $Hostname -ev myError -ea SilentlyContinue | Select Name, UserName

			# RPC error if WMI call fails
			if ($MyError -ne $null)
			{

				Write-Output "The RPC server on $hostname is unavailable" | Write-Host -ForegroundColor Red -BackgroundColor Black

				continue
			}
		}
		# Ping test errors
		elseif ($PingTest -eq "TimedOut")
		{

			Write-Output "Ping Failed: $hostname appears to be down" | Write-Host -ForegroundColor Red -BackgroundColor Black

		}
		else
		{

			Write-Output "Other ping error: $PingTest" | Write-Host -ForegroundColor Red -BackgroundColor Black

		}
	}
}