TheloniusFunk
TheloniusFunk

Reputation: 11

Use Powershell to retrieve number from a sequence using web request

I have a very specific problem I have been trying to work out. I'm using a PowerShell script to name newly imaged computers during the imaging proceess, and I need to grab a newly generated number from a sequence. I use SCCM 2012 R2 for this, btw

For example, I have the script naming our computers by our convention using wmi query:

    if ($ComputerVersion  -eq "ThinkPad T400") 
{
$OSDComputerName = "T400xxxx-11"
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = "$OSDComputerName"
}

I set the $ComputerVersion variable, using WMI query, like so:

$ComputerVersion = (Get-WmiObject -Class Win32_ComputerSystemProduct | Select-Object Version).Version

So, the crux of my question is I want to set another variable, probably something simple like $num, for the next number available to label our computers. This number will be replacing the "xxxx". I'll be doing that by:

if ($ComputerVersion  -eq "ThinkPad T400") 
{
$OSDComputerName = "T400" + $num + "-11"
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = "$OSDComputerName"
}

This number is being generated by a linux server we have, and its already running some python script to dish out the next available number in the sequence. I can post that python script if needed, but it's 133 lines.

What I need to know is how to call for that web request via PowerShell, and set that returned number (the next available) as a new variable.

I've never used web-services or web-requests before and any help would be greatly appreciated. Thanks in advance!

Upvotes: 1

Views: 191

Answers (1)

arco444
arco444

Reputation: 22831

Depends what the web request returns and whether or not you need to process any return data, but if it simply returns the number you could do this:

$webClient = New-Object System.Net.WebClient
$num = $webClient.downloadstring("http://yourwebservice.com/buildnumber")

Upvotes: 1

Related Questions