Thursday, February 4, 2016

Check a machine is valid.

This was part of a solution to check that a PC was a valid PC to launch on.  I've posted it here to illustrate several techniques including deleting files, generating files, evaluating variables, block coments and querying machine information using WMI.

-computername <machname> can direct a get-wmiobject query to a remote machine


#reset
Remove-Item ".\Application Data\Folder\PCValid.txt"
#read current PC name
$machname = get-wmiobject -namespace root\CIMV2 -Class Win32_ComputerSystem | select -expand name
#read AssignedPC.txt
$AssignedPC = get-content ".\Application Data\Folder\AssignedPC.txt"
# create a file if the values match.
if ($machname -eq $AssignedPC) {out-file ".\Application Data\Folder\PCValid.txt"}

<#
This is a block comment
#>