Difference between revisions of "Power Shell"

Jump to navigation Jump to search
843 bytes removed ,  11:36, 18 February 2010
m
→‎WMI: Revised WMI examples etc
m (→‎ConvertTo-SecureString: Added WMI command to example)
m (→‎WMI: Revised WMI examples etc)
Line 144: Line 144:
== WMI ==
== WMI ==


Cmdlet for using WMI via PowerShell is '''Get-WMIObject''', which has an alias of '''gwmi''', for example...
Cmdlet for using WMI via PowerShell is '''Get-WMIObject''', for example...


<source lang="powershell">
<source lang="powershell">
Line 155: Line 155:
SerialNumber    : 76487-OEM-0011903-00102
SerialNumber    : 76487-OEM-0011903-00102
Version        : 5.1.2600
Version        : 5.1.2600
</source>


PS H:\> Get-WMIObject -query "SELECT * FROM Win32_UTCTime"
Further useful examples...
 
<source lang="powershell">
__GENUS          : 2
# Get OS CPU info (address width, speed, FSB etc
__CLASS          : Win32_UTCTime
$cpu = Get-WMIObject -query "SELECT * FROM Win32_Processor WHERE DeviceID='CPU0'" -credential $cred -computer $svr
__SUPERCLASS    : Win32_CurrentTime
__DYNASTY        : Win32_CurrentTime
__RELPATH        : Win32_UTCTime=@
__PROPERTY_COUNT : 10
__DERIVATION    : {Win32_CurrentTime}
__SERVER        : L-0STRUTTS1
__NAMESPACE      : root\cimv2
__PATH          : \\L-0STRUTTS1\root\cimv2:Win32_UTCTime=@
Day              : 27
DayOfWeek        : 4
Hour            : 10
Milliseconds    :
Minute          : 0
Month            : 8
Quarter          : 3
Second          : 1
WeekInMonth      : 5
Year            : 2009
 
PS H:\> Get-WMIObject -query "Select * from Win32_OperatingSystem" -credential sysmgr -computer ukpgemon2
 
SystemDirectory : C:\WINDOWS\system32
Organization    : Thomson Financial
BuildNumber    : 3790
RegisteredUser  : Dell Image Rev 1
SerialNumber    : 69712-640-3560061-45321
Version        : 5.2.3790


PS H:\> Get-WMIObject -query "Select * from Win32_userAccount WHERE Domain = 'OCM-WCS1' AND Name = 'pptp_ypos'" -credential administrator -computer 159.104.224.167
# Get local disks
$drives = Get-WMIObject Win32_LogicalDisk -filter "Description = 'Local Fixed Disk'" -credential $cred -computer $svr
AccountType : 512
Caption    : OCM-WCS1\pptp_ypos
Domain      : OCM-WCS1
SID        : S-1-5-21-2453442427-2400495818-1845097998-1073
FullName    : Ypos-Consulting GmbH
Name        : pptp_ypos
</source>
</source>


Line 206: Line 174:
</source>
</source>


To then see all the properties of a class use (doesn't work on remote machines (access denied) - this is a known bug in Power Shell v1)...
To then see all the properties of a class use (if this doesn't work on remote machines (access denied) - it may be due to a known bug in Power Shell v1 whereby <code>Get-WMIObject</code> can't impersonate (or you may just have the wrong credentials)...
<source lang="powershell">
<source lang="powershell">
Get-WMIObject Win32_BIOS | Format-List *
Get-WMIObject Win32_BIOS | Format-List *

Navigation menu