0

第一次用PS,第一次写脚本!

我在我的主机上本地存储了一个 wsdl,它指向一个 localhost 端点。这是必要的,因为远程服务器不为 wsdl 提供服务。但是,它们是这些 SOAP 请求的有效端点。

我的网络中有多个端点,我想在引用静态 wsdl 的同时向每个端点发送 New-WebServiceProxy 请求。有没有办法使用本地 wsdl,但指定一个目标端点覆盖?

这是我目前拥有的(请原谅评论,我正在努力学习):

# The uri refers to the wsdl page            

$uri = ( Join-Path $PSScriptRoot "\wsdl\PublicService.wsdl" )

# Create the Web Service Proxy           
$service = New-WebServiceProxy -Uri $uri  -Namespace WebServiceProxy  -UseDefaultCredential -Verbose       

# Specify the list of target servers IP addressesr hostnames

$serverlistpath = ( Join-Path $PSScriptRoot "\servers\servers.txt" )
$servers = gc $serverlistpath


# Create an output path to the templates folderr use witin the SOAP request
$templatetemp = ( Join-Path $PSScriptRoot "\template_temp\" )


# Gets the UNC path of the script running location

$currentDirectory = Get-Location
$currentDrive = Split-Path -qualifier $currentDirectory.Path
$logicalDisk = Gwmi Win32_LogicalDisk -filter "DriveType = 4 AND DeviceID = '$currentDrive'"
$uncPath = $currentDirectory.Path.Replace($currentDrive, $logicalDisk.ProviderName)

# Execute SOAP request

$service.Backup("false", "true", "false", "false", "$uncpath\template_temp")

我计划在 servers.txt 中将其作为 ForEach 循环运行,但每次都需要能够在指向静态 wsdl 的同时设置不同的 URL。每台服务器都不为 wsdl 本身提供服务。

任何建议表示赞赏。

4

1 回答 1

0

You may want to look at creating a CSV file with two headers, one for your server names and the other for the URL.

Ex.

server,url SERVER01,http://www.example.com/oneendpoint SERVER02,http://www.example.com/twoendpoint

Then you can iterate over each entry using a foreach loop. You can import csv files easily in PowerShell with the Import-CSV cmdlet

于 2018-07-06T18:16:21.360 回答