Font Size



o IT

SCCM NetBIOS query

Most of my colleagues requests I get on the table are asking for creating a collection for "these computers". Then, mostly a list of NetBIOS names follows, either in csv or txt format. So you can imagine that I'm using NetBIOS query very often while creating a collection in SCCM. As I'm a lazy person and don't want to add required quotes at the beginning and at the end of each computer name, I wrote this simple script.


Script runs in powershell, ask you for a input file which is simple txt file with one computer name on a row - that's something that could be easily copied from excel, email communication or IM. Then the script add requested quote to the begging and quote followed by comma at the end. Finally, all the computers are surrounded by the WQL statement for standard "select *  from SMS_R_System where SMS_R_System.NetbiosName in" NetBIOS query. And the last trick at the end - the result is printed on the screen AND automatically added to the clipboard, so you simply paste it directly into the "Show the query statement" window right after running the script.



Function Get-FileName($initialDirectory)


 [System.Reflection.Assembly]::LoadWithPartialName("") |



 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

 $OpenFileDialog.initialDirectory = $initialDirectory

 $OpenFileDialog.filter = "All files (*.*)| *.*"

 $OpenFileDialog.ShowDialog() | Out-Null



<# $Justcomputers - change to $true to get computer list only #>

$justcomputers = $true



$query = 0

Clear-Variable -Name query

$file = Get-FileName -initialDirectory "C:\TEMP\"

$content = Get-Content $file 

ForEach($computer in $content) 

    $query += '"' + $computer + '",'   


$query = $query -replace ".$"

if ($justcomputers -ne $true) {$query = 'select *  from  SMS_R_System where SMS_R_System.NetbiosName in (' + $query + ')'}


$query | clip

Write-Host $query

Přidat komentář