![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Find a string within a variable string I'm still learning PowerShell, and here's what I'm trying to accomplish. Find out what service pack version my machines are running and then save this information to a file. The way I'm going about this task is: 1. I'm going to feed the computer netbios name to the ps script. 2. The ps script will find this information and match the netbios name to the service pack version 3. Write this information to a file and append to it until it's done. So far, I'm able to pass a parameter to the script and get the service pack version; however, I can't figure out how to find a string within the variable string that holds the results. Here's what I have so far: # Handle parameter received from users param( [string] $ComputerName ) $SpFound = Get-WMIObject Win32_OperatingSystem –Property ServicePackMajorVersion –Computer $ComputerName Any suggestions will be greatly appreciated. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Find a string within a variable string Hi Edward, I have to admit I don't completely understand what you mean, but how about this:- function process-servicepack ($Hostname) { $a = gwmi win32_operatingsystem | Select-Object "ServicePackMajorVersion" $a -match "\d" | Out-Null ; $v = $matches[0] Add-content -path "C:\servicepacks.txt" -Value "Netbios Name : $hostname`tServicepack : $v" } Get-Content "C:\computers.txt" | % {process-servicepack $_ } Where "C:\computers.txt" is your list of Netbios names. One on each line. Where "C:\servicepacks.txt" is your output file containing the result ( I think ) you want. Hope it helps, Stuart |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Find a string within a variable string Whoops, in my mad rush to post I made a little mistake; I forgot to put the -computername parameter and value in the gwmi line. This is the correct code:- -------------- function process-servicepack ($Hostname) { $a = gwmi win32_operatingsystem -ComputerName $Hostname | Select- Object "ServicePackMajorVersion" $a -match "\d" | Out-Null ; $v = $matches[0] Add-content -path "C:\servicepacks.txt" -Value "Netbios Name : $hostname`tServicepack : $v" } Get-Content "C:\computers.txt" | % {process-servicepack $_ } --------------- Sorry about that. The above ought to do what you need...if I understood properly(!) Regards, Stuart |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Find a string within a variable string I suggest using Quest software which is a free download, it can search for computer services packs, etc in a liner. "Kryten" <Kryten68@xxxxxx> wrote in message news:a42a9485-cbeb-4c7d-a96d-b4f00f884fc6@xxxxxx Quote: > Whoops, in my mad rush to post I made a little mistake; I forgot to > put the -computername parameter and value in the gwmi line. > This is the correct code:- > > -------------- > function process-servicepack ($Hostname) { > $a = gwmi win32_operatingsystem -ComputerName $Hostname | Select- > Object "ServicePackMajorVersion" > $a -match "\d" | Out-Null ; $v = $matches[0] > Add-content -path "C:\servicepacks.txt" -Value "Netbios Name : > $hostname`tServicepack : $v" > } > > Get-Content "C:\computers.txt" | % {process-servicepack $_ } > --------------- > > Sorry about that. The above ought to do what you need...if I > understood properly(!) > > Regards, > Stuart |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Find a string within a variable string On Aug 14, 6:06*pm, Kryten <Kryte...@xxxxxx> wrote: Quote: > Whoops, in my mad rush to post I made a little mistake; I forgot to > put the -computername parameter and value in the gwmi line. > This is the correct code:- > > -------------- > function process-servicepack ($Hostname) { > $a = gwmi win32_operatingsystem -ComputerName $Hostname | Select- > Object "ServicePackMajorVersion" > $a -match "\d" | Out-Null ; $v = $matches[0] > Add-content -path "C:\servicepacks.txt" -Value "Netbios Name : > $hostname`tServicepack : $v" > > } > > Get-Content "C:\computers.txt" | % {process-servicepack $_ } > --------------- > > Sorry about that. The above ought to do what you need...if I > understood properly(!) > > Regards, > Stuart could learn this thing )Yes, it was exactly what I needed. I'm just going to go over the code, that way I can understand how you accomplished the task. Thanks again. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| variable evaluation in a string | PowerShell | |||
| How to concatenate a literal string and a variable value? | VB Script | |||
| Re: how to tokenize a string into a variable via regex | PowerShell | |||
| SSIS - string variable! | .NET General | |||
| Subject: using a Variable with/in a string | PowerShell | |||