- <#
- .SYNOPSIS
- This script gets/displays the Sysgtem Uptime after
- converting it from WEBM time/date format
- .DESCRIPTION
- This script creates an instance of a SWbemDateTime object,
- gets the OS install date and converts the date to a more
- useful format.
- .NOTES
- File Name : Get-OSInstallDate.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa393687%28VS.85%29.aspx
- .EXAMPLE
- Psh [C:\foo]> .\Get-OsInstallDate.ps1
- This OS was installed in the year 2008
- Full installation date (VT_DATE format) is 4/9/2008 8:17:23 PM
- Full installation date (FILETIME format) is 128522458430000000
- #>
- # Create swbemdatetime object
- $datetime = New-Object -ComObject WbemScripting.SWbemDateTime
- # Get OS installation time and assign to datetime object
- $os = Get-WmiObject -Class Win32_OperatingSystem
- $dateTime.Value = $os.InstallDate
- # Now display the time
- "This OS was installed in the year {0}" -f $dateTime.Year
- "Full installation date (VT_DATE format) is {0}" -f $dateTime.GetVarDate()
- "Full installation date (FILETIME format) is {0}" -f $dateTime.GetFileTime()
- ##
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label wmi. Show all posts
Showing posts with label wmi. Show all posts
Tuesday, 11 October 2011
Get-OSInstallDate.ps1
Labels:
powershell,
PowerShell scripts,
SWbemDateTime,
wmi
Friday, 7 October 2011
Register-Event1.ps1
- <#
- .SYNOPSIS
- This script registers for a WMI event
- .DESCRIPTION
- This script used PowerShell to register for then display
- an event. This script is a re-write on an MSDN Sample.
- .NOTES
- File Name : Register-Event1.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/aa393013%28VS.85%29.aspx
- .EXAMPLE
- [PSH] C:\FOO> Register-Event1.ps1
- Waiting for events
- Log Event Occured
- EVENT MESSAGE
- A logon was attempted using explicit credentials.
- Subject:
- Security ID: S-1-5-21-2824006062-479960714-4144511058-1105
- Account Name: tfl
- ... -> Reminder snipped for brevity
- #>
- # Define event Query
- $query = "SELECT * FROM __InstanceCreationEvent
- WHERE TargetInstance ISA 'Win32_NTLogEvent' "
- # Register for event - also specify an action that
- # displays the log event when the event fires.
- Register-WmiEvent -Source Demo1 -Query $query -Action {
- Write-Host "Log Event occured"
- $global:myevent = $event
- Write-Host "EVENT MESSAGE"
- Write-Host $event.SourceEventArgs.NewEvent.TargetInstance.Message}
- # So wait
- "Waiting for events"
Labels:
powershell,
PowerShell scripts,
wmi
Friday, 30 September 2011
Get-FolderObjects.ps1
- <#
- .SYNOPSIS
- This script displays the WMI objects associated with a folder
- .DESCRIPTION
- This script uses the Associators Of query
- .NOTES
- File Name : get-folderobjects.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Get-FolderObjects "C:\Foo"
- what's in C:\foo
- 0 Volume objects
- 0 Logical Disk objects
- 10 Directory objects
- 171 File objects
- 0 Pagefile objects
- 1 Security Settings
- 0 Share objects
- 0 other objects
- .EXAMPLE
- Get-FolderObjects "C:\"
- what's in C:\
- 1 Volume objects
- 1 Logical Disk objects
- 18 Directory objects
- 8 File objects
- 1 Pagefile objects
- 1 Security Settings
- 1 Share objects
- 0 other objects
- #>
- # Function to get folder WMI object associations
- # Define function
- Function Get-FolderObjects {
- Param (
- $Folder = "c:\"
- )
- # Set query then get associations
- $query = "ASSOCIATORS OF {Win32_Directory.Name='$folder'}"
- $objs = Gwmi -q $query
- #
- # Now group them
- # Create empty arrays
- $directory = @()
- $datafile = @()
- $pagefile = @()
- $volume = @()
- $filesec = @()
- $share = @()
- $Logdisk = @()
- $unknown = @()
- # Now fill the arrays
- foreach ($obj in $objs) {
- switch ($Obj.__class) {
- "Win32_Directory" {$directory += $obj; break}
- "Cim_DataFile" {$datafile += $obj; break}
- "Win32_PageFile" {$pagefile += $obj; break}
- "Win32_Volume" {$volume += $obj; break}
- "Win32_LogicalDisk" {$logdisk += $obj; break}
- "Win32_LogicalFileSecuritySetting" {$filesec += $obj; break}
- "Win32_share" {$share += $obj; break}
- default {$unknown += $obj; break}
- }
- }
- # Display the output
- " what's in $folder"
- "{0} Volume objects" -f $volume.count
- "{0} Logical Disk objects" -f $logdisk.count
- "{0} Directory objects" -f $directory.count
- "{0} File objects" -f $datafile.count
- "{0} Pagefile objects" -f $pagefile.count
- "{0} Security Settings" -f $filesec.count
- "{0} Share objects" -f $share.count
- "{0} other objects" -f $unknown.count
- }
- # Here call function as an example
- Get-FolderObjects "C:\"
- "***"
- Get-FolderObjects "C:\foo"
Tuesday, 13 September 2011
Remove-WmiRegistryKey.ps1
- <#
- .SYNOPSIS
- This script creates removes registry key using WMI.
- .DESCRIPTION
- This script uses WMI to get remove registry key.
- This script deletes the key and everything below
- it in the registry - use carefully!
- .NOTES
- File Name : Remove-WmiRegistryKey.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>New-WMIRegistryKey.ps1
- Key removed
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $Key = "SOFTWARE\NewKey"
- # Create key and display reslts
- $results = $reg.DeleteKey($HKEY_LOCAL_MACHINE, $Key)
- If ($results.Returnvalue -eq 0) {"Key Removed"}
Labels:
DeleteKey,
powershell,
StdRegProv,
wmi
Monday, 12 September 2011
Get-WmiRegistryBinaryValue.ps1
- <#
- .SYNOPSIS
- This script Gets and displays a registry
- binary value using WMI.
- .DESCRIPTION
- This script uses WMI to get, then display
- a binary registry Value.
- This is a re-write of a VB Sample Script.
- .NOTES
- File Name : Set-WmiRegistryBinaryValue.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>Get-WmiRegistryBinaryValue.ps1
- 54
- 46
- 4c
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $ValueName = "Example Binary Value"
- $Values = @(0x54, 0x46, 0x4C)
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.GetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName)
- Foreach ($byte in $results.uvalue) {"{0}" -f $byte.tostring("x")}
W
Sunday, 11 September 2011
Set-WmiRegistryBinaryValue
- <#
- .SYNOPSIS
- This script sets a registry binary value
- using WMI.
- .DESCRIPTION
- This script uses WMI to set a binary
- registry Value.
- This is a re-write of a VB Sample Script.
- .NOTES
- File Name : Set-WmiRegistryBinaryValue.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>New-WmiRegistryBinaryValue.ps1
- Value created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $ValueName = "Example Binary Value"
- $Values = @(0x54, 0x46, 0x4C)
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.SetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values)
- If ($results.Returnvalue -eq 0) {"Value Set"}
Saturday, 10 September 2011
New-WmiRegistryValue.ps1
- <#
- .SYNOPSIS
- This script creates a new registry Value using WMI.
- .DESCRIPTION
- This script uses WMI to get create a new registry Value.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : New-RegistryKey.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>New-WmiRegistryValue.ps1
- Value created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $ValueName = "Example_Expanded_String_Value"
- $Value = "%PATHEXT%"
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.SetExpandedStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Value)
- If ($results.Returnvalue -eq 0) {"Value created"}
Labels:
SetExpandedStringValue,
StdRegProv,
wmi
Friday, 9 September 2011
New-WmiRegistryKey.ps1
- <#
- .SYNOPSIS
- This script creates a new registry key using WMI.
- .DESCRIPTION
- This script uses WMI to get create a new registry key.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : New-RegistryKey.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>New-WMIRegistryKey.ps1
- Key created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $Key = "SOFTWARE\NewKey"
- # Create key and display reslts
- $results = $reg.CreateKey($HKEY_LOCAL_MACHINE, $Key)
- If ($results.Returnvalue -eq 0) {"Key created"}
Thursday, 8 September 2011
Get-WmiRegDword.ps1
- <#
- .SYNOPSIS
- This script gets a registry value using WMI.
- .DESCRIPTION
- This script uses WMI to get then display a resistry value, using
- the SteRegProv class and the GetDWORDValue static method.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : Get-WMIRegDword.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>Get-WmiRegDword.ps1
- Current History Buffer Size: 50
- #>
- # Define Constants
- $HKEY_CURRENT_USER =2147483649
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- #defind key/value to get
- $Key = "Console"
- $Value = "HistoryBufferSize"
- # Get Value of buffer and display
- $results = $reg.GetDWORDValue($HKEY_CURRENT_USER, $Key, $value)
- "Current History Buffer Size: {0}" -f $results.uValue
Tuesday, 4 January 2011
Get-ComputerDomain.ps1
<#
.SYNOPSIS
This script uses WMI to get the name of a computer's domain then displays the name.
.DESCRIPTION
This script is a re-write of an MSDN sample, using PowerShell.
.NOTES
File Name : Get-ComputerDomain.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted tot:
http://msdn.microsoft.com/en-us/library/aa394586%28VS.85%29.aspx/
.EXAMPLE
PSH [C:\foo]: .\Get-ComputerDomain.ps1
System Name: WIN7
Domain: cookham.net
.EXAMPLE
Psh[Cookham8]> .\Get-ComputerDomain.ps1 cookham2
System Name: COOKHAM2
Domain: cookham.net
.PARAMETER comp
The name of the computer whose domain name to be displayed. Default is localhost.
#>
# Parameter block
param (
$comp = "."
)
# Get WMI Object
$system = Get-WmiObject -class Win32_ComputerSystem -ComputerName $comp
# Display results
"System Name: {0}" -f $System.Name
"Domain: {0}" -f $System.Domain
Labels:
PowerShell scripts,
win32_computersystem,
wmi
Thursday, 7 October 2010
Get-WMINameSpace.ps1
- <#
- .SYNOPSIS
- This script displays all the WMI namespaces within a Windows system
- .DESCRIPTION
- This script uses Get-WMIObject to retrieve the names of all the namespaces
- within a system.
- .NOTES
- File Name : Get-WMINameSpace.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/10/get-wminamespaceps1.html
- .EXAMPLE
- PSH [C:\foo]: .\Get-WMINameSpace.ps1
- 37 Namespaces on: Cookham8
- Namespace
- ---------
- ROOT
- ROOT\aspnet
- ROOT\CIMV2
- ROOT\CIMV2\Security
- ROOT\CIMV2\Security\MicrosoftTpm
- ... {Remainder of list snipped to save space on this page}
- #>
- # Set computer name
- $comp = "."
- # Get the name spaces on the local computer, and the local computer name
- $Namespace = get-wmiobject __namespace -namespace 'root' -list -recurse -computer $comp
- $hostname = hostname
- # Display number of and names of the namespaces
- "{0} Namespaces on: {1}" -f $namespace.count, $hostname
- $NameSpace| sort __namespace | Format-Table @{Expression = "__Namespace"; Label = "Namespace"}
Labels:
namespace,
powershell,
PowerShell scripts,
PowerShell V2,
wmi
Tuesday, 17 August 2010
Get-BrokenHardware.ps1
- <#
- .SYNOPSIS
- This script gets a list of non-working hardware using WMI.
- .DESCRIPTION
- This script re-implements another TechNet Scripting
- Gallery script that was written in VB (see
- http://tinyurl.com/y4hmtbr).
- This script first uses WMI to get system details, then
- gets and displays hardware that has errored.
- .NOTES
- File Name : Get-BrokenHardware.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- This script posted to TechNet Script Gallery at:
- http://gallery.technet.microsoft.com/ScriptCenter/en-us/dbb678f4-b95b-45c3-bc8b-2ae2d052448e
- .EXAMPLE
- PSH [C:\foo]: Get-BrokenHardware.ps1
- Computer Details:
- Manufacturer: Dell Inc.
- Model: Precision WorkStation T7400
- Service Tag: 6Y84C3J
- Hardware that's not working list
- Description: WD My Book Device USB Device
- Device ID: USBSTOR\OTHER&VEN_WD&PROD_MY_BOOK_DEVICE&REV_1010\7&2A4E07C&0&575532513130303732383932&1
- Error ID: 28
- #>
- # Display Computer details
- "Computer Details:"
- $comp = gwmi Win32_ComputerSystem
- "Manufacturer: {0}" -f $comp.Manufacturer
- "Model: {0}" -f $comp.Model
- $computer2 = Get-WmiObject Win32_ComputerSystemProduct
- "Service Tag: {0}" -f $computer2.IdentifyingNumber
- ""
- #Get hardware that is errored
- "Hardware that's not working list"
- $broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}
- #Display broken hardware
- foreach ($obj in $broken){
- "Description: {0}" -f $obj.Description
- "Device ID: {0}" -f $obj.DeviceID
- "Error ID: {0}" -f $obj.ConfigManagerErrorCode
- ""
- }
Technorati Tags: PowerShell,Scripts,WMI,Win32_ComputerSystem,Win32_ComputerSystemProduct,Win32_PnPEntity
Thursday, 12 August 2010
Get-DnsRegisteredServers.ps1
- <#
- .SYNOPSIS
- This script gets the reverse lookup zone from a DNS Server and
- displays all the systems registered
- .DESCRIPTION
- This script first gets the reverse lookup zone from a DNS Server (i.e.
- all the computers that have used the DNS server to register!). The
- script then displays the FQDN, IP Address and Timestamp.
- .NOTES
- File Name : Get-DnsRegisteredServers.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- This script posted to TechNet Scripting Gallery
- http://gallery.technet.microsoft.com/ScriptCenter/en-us/28e8b98e-565b-40be-ba2c-1134341bb555
- .EXAMPLE
- PSH [C:\foo]: .Get-DnsRegisteredNames.ps1
- Computers reverse registered on DNS Server: Cookham1
- 10.10.1.42 superman.cookham.net. 3590550
- 10.10.1.105 batman.cookham.net. 3582112
- 10.10.1.109 jeeves.cookham.net. 3586452
- 10.10.1.111 supergirl.cookham.net. 3590550
- 10.10.1.114 future.cookham.net. 3589209
- 10.10.1.131 bladerunner.cookham.net. 3587817
- 10.10.1.142 wonderwoman.kapoho.net. 3590551
- #>
- $dns = "Cookham1"
- $records = get-wmiobject -class MicrosoftDNS_PTRType -namespace root\MicrosoftDNS -computer $dns
- "Computers reverse registered on DNS Server: $DNS"
- # Loop through and display results
- foreach ($record in $records) {
- # Get owner name and ip address string
- $on = $record.ownerName.split(".")
- $ownerip = $on[3] + "." + $on[2] + "." + $on[1] + "." + $on[0]
- # Display details
- "{0, -15} {1,-40} {2,-10} " -f $ownerip, $record.ptrdomainname, $record.timestamp
- }
Labels:
MicrosoftDNS,
powershell,
PowerShell scripts,
wmi
Saturday, 31 July 2010
Get-WmiClassDescription.ps1
- <#
- .SYNOPSIS
- This script gets and displays the description of a WMI Class.
- .DESCRIPTION
- This script takes a WMI Class name as a parameter. The script
- then gets the class's description from the CIM repository and
- displays it. Based on a PowerShell.Com tip of the day!
- .NOTES
- File Name : Get-WmiClassDescription.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- PSH [C:\foo]: .\Get-WmiClassDescription.ps1
- Description for WMI Class Win32_ComputerSystem:
- The Win32_ComputerSystem class represents a computer system operating in a Win32 environment.
- .EXAMPLE
- PSH [C:\foo]: . \Get-WmiClassDescription.ps1 win32_bios
- Description for WMI Class win32_bios:
- The Win32_BIOS class represents the attributes of the computer system's basic input/output services
- (BIOS) that are installed on the computer.
- #>
- param (
- [string] $WMIClassName = "Win32_ComputerSystem"
- )
- # Get WMI class from class name
- $class = [wmiclass]$wmiclassname
- # Now get then print the class description
- # First use ammended qualifiers to get description
- $class.psbase.Options.UseAmendedQualifiers = $true
- "Description for WMI Class {0}:" -f $WmiClassName
- ($class.psbase.qualifiers["description"]).Value
Labels:
powershell,
PowerShell scripts,
PowerShell V2,
wmi
Thursday, 29 October 2009
Restart-DNS.ps1
- <#
- .SYNOPSIS
- This script restarts the DNS Service on a Remote System
- .DESCRIPTION
- This script uses WMI to reach out and restart the DNS
- DNS service on a remote machine. in my home environment,
- I find the DNS service on the home DC fails and needs
- to be restarted - this script works!
- .NOTES
- File Name : Restart-DNS.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2009/10/restart-dnsps1.html
- .EXAMPLE
- PSH [C:\foo]: .\Restart-DNS.ps1
- Restarting DNS Service on: Cookham1
- DNS Service stopped
- DNS Service started
- #>
- ##
- # Start Script
- ##
- # Set server to reset and display our intention
- $Server = "Cookham1"
- "Restarting DNS Service on: $Server"
- # Get DNS service
- $dns = gwmi win32_service -computer $Server | where {$_.name -eq "DNS"}
- # Now stop it
- $ret = $dns.stopservice()
- if ($ret.returnvalue -eq 0) {"DNS Service stopped"}
- else {"DNS Service not stopped"}
- # And now restart it
- $ret = $dns.startservice()
- if ($ret.returnvalue -eq 0) {"DNS Service started"}
- else {"DNS Service not started"}
- # End of Script
Labels:
dns,
powershell,
PowerShell scripts,
PowerShell V2,
wmi
Tuesday, 21 April 2009
Get-PrinterTestPage.ps1
- <#
- .SYNOPSIS
- This script uses WMI to print a test page
- all printers on this system
- .DESCRIPTION
- This script is an MSDN sample,using PowerShell. It first
- gets all the printrs installed, prints out details then
- tries to print a test page.
- The script also checks for printers known to not work well, and avoids using them
- .NOTES
- File Name : Get-PrinterTestPage.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Sample posted to:
- http://pshscripts.blogspot.com/2009/04/get-printertestpageps1.html
- Original MSDN sample at:
- http://msdn.microsoft.com/en-us/library/aa392757(VS.85).aspx
- .EXAMPLE
- PSH [C:\foo]: .Get-PrinterTestPage.ps1'
- 4 Printers defined on this system
- Printer share name: \
- Printer Port : C:\ProgramData\TechSmith\SnagIt 9\PrinterPortFile
- Printer share name: \Phaser PS
- Printer Port : X_10.10.1.117
- Printer share name: \
- Printer Port : XPSPort:
- Printer share name: \\SLT-PC\officejet
- Printer Port : USB002
- Printing test page for printer: SnagIt 9
- Not printing a test page for this printer
- Printing test page for printer: Phaser PS
- Result : 0
- Printing test page for printer: Microsoft XPS Document Writer
- Not printing a test page for this printer
- Printing test page for printer: \\JerryGarcia\HP Officejet Pro L7400 Series
- Result : 0
- #>
- ###
- # Start of Script
- ###
- # Get Printer Objects for this computer from WMI
- $printers = Get-WmiObject -Class Win32_Printer
- # Display printers
- "{0} Printers defined on this system" -f $printers.count
- # For printers, display printer details
- foreach ($printer in $printers) {
- "Printer share name: {0}\{1}" -f $printer.servername, $printer.sharename
- "Printer Port : {0} " -f $printer.PortName
- }
- ""
- # Now Print a test page for each printer
- foreach ($printer in $printers) {
- "Printing test page for printer: {0}" -f $printer.name
- # avoid issue with Known bad printers
- if ($printer.DriverName -match "XPS" -or $printer.DriverName -match "SnagIt") {
- "Not printing a test page for this printer"
- }
- else {
- $Result = $printer.PrintTestPage()
- "Result : {0}" -f $Result.ReturnValue
- }
- }
- # End of script
Labels:
powershell,
PowerShell scripts,
Win32_Printer,
wmi
Win32_Fan Sample using PowerShell
- <#
- .SYNOPSIS
- Uses Win32_Fan class to return information about fans in a system.
- .DESCRIPTION
- This script first defines some functions to decode various
- WMI attributed from binary to text. Then the script calls
- Get-WmiObject to retrieve fan details, then formats that
- information (using the functions defined at the top of the script.
- .NOTES
- File Name : Get-Fan.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- Script posted to:
- http://pshscripts.blogspot.com/2009/04/win32fan-sample-using-powershell.html
- Original MSDN Page
- http://msdn.microsoft.com/en-us/library/aa394146(VS.85).aspx
- .EXAMPLE
- Left as an exercise for the viewer.
- #>
- ###
- # Start of Script
- ###
- # Functions to decode details
- function FanAvailability {
- param ($value)
- switch ($value) {
- 1 {"Other"}
- 2 {"Unknown"}
- 3 {"Running on full power"}
- 4 {"Warning"}
- 5 {"In Test"}
- 6 {"Not Applicable"}
- 7 {"Power Off"}
- 8 {"Off Line"}
- 9 {"Off Duty"}
- 10 {"Degraded"}
- 11 {"Not Installed"}
- 12 {"Install Error"}
- 13 {"Power Save - Unknown"}
- 14 {"Power Save - Low Power Mode"}
- 15 {"Power Save - Standby"}
- 16 {"Power Cycle"}
- 17 {"Power Save - Warning"}
- default {"NOT SET"}
- }
- }
- function ConfigManagerErrorCode {
- param ($value)
- switch ($value) {
- 0 {"Device Is Working Properly"}
- 1 {"Device is not configured correctly"}
- 2 {"Windows Cannot load the driver for this device"}
- 3 {"Driver for this device might be corrupted, or the system may be low on memory or other resources"}
- 4 {"Device is not working properly. One of its drivers or the registry might be corrupted"}
- 5 {"Driver for the device requires a resource that Windows cannot manage"}
- 6 {"Boot configuration for the device conflicts with other devices"}
- 7 {"Cannot filter"}
- 8 {"Driver loader for the device is missing"}
- 9 {"Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device"}
- 10 {"Device cannot start"}
- 11 {"Device failed"}
- 12 {"Device cannot fine enough free resources to run"}
- 13 {"Windows cannot verify the devices's resources"}
- 14 {"Device cannot work propertly until the computer is restarted"}
- 15 {"Device is not working properly due to a possible re-enumeration problem"}
- 16 {"Windows cannot identify all of the resources that the device uses"}
- 17 {"Device is requesting an unknown resource type"}
- 18 {"Device drivers must be reinstalled"}
- 19 {"Failure using the VxD loader"}
- 20 {"Registry might be corrupted"}
- 21 {"System failure. if changing the device driver is ineffective, see the hardware documentation. Windows is removing the device"}
- 22 {"Device is disabled"}
- 23 {"System failure. if changing the device driver is ineffective, see the hardware documentation"}
- 24 {"Device is not present, not working properly, or does not have all of its drivers installed"}
- 25 {"Windows is still setting up the device"}
- 26 {"Windows is still setting up the device"}
- 27 {"Device does not have valid log configuration"}
- 28 {"Device drivers are not installed"}
- 29 {"Device is disabled. The device firmware did not provide the required resources"}
- 30 {"Device is using an IRQ resource that another device is using"}
- 31 {"Device is not working properly. Windows cannot load the required device drivers."}
- default {"NOT SET"}
- }
- }
- function PowerManagementCapabilities {
- param ($value)
- switch ($value) {
- 0 {"Unknown"}
- 1 {"Not Supported"}
- 2 {"Disabled"}
- 3 {"Enabled"}
- 4 {"Power Saving Modes Entered Automatically"}
- 5 {"Power State Settable"}
- 6 {"Power Cycling Supported"}
- 7 {"Timed Power-On Supported"}
- default {"NOT SET"}
- }
- }
- function StatusInfo {
- param ($value)
- switch ($value) {
- 0 {"Other"}
- 2 {"Unknown"}
- 3 {"Enabled"}
- 4 {"Disabled"}
- 5 {"Not Applicable"}
- default {"NOT SET"}
- }
- }
- ###
- # Start of Script
- ##
- # Get fan information
- $fans = Get-WmiObject -Class Win32_Fan
- # Display information
- $hostnm=hostname
- "Fan Information on System: {0} ({1} fans in total" -f $hostnm, $fans.count
- $i=1
- # display details of each fan
- foreach ($fan in $fans) {
- # Display details
- "Fan: {0}" -f $i
- "Active Cooling : {0}" -f $fan.ActiveCooling
- "Availability : {0}" -f (fanavailability($fan.availability))
- "Caption : {0}" -f $fan.caption
- "Config Manager Error code : {0}" -f (ConfigManagerErrorCode($fan.ConfigManagerErrorCode))
- "Config Manager User Config : {0}" -f $fan.ConfigManagerUserConfig
- "Creation Class Name : {0}" -f $fan.CreationClassName
- "Description : {0}" -f $fan.Description
- "Desired speed : {0}" -f $fan.DesiredSpeed
- "Error Cleared : {0}" -f $fan.ErrorCleared
- "Error Description : {0}" -f $fan.ErrorDescription
- "Install Date : {0}" -f $fan.InstallDate
- "Last Error code : {0}" -f $fan.LastErrorCode
- "Name : {0}" -f $fan.name
- "PNP Device Id : {0}" -f $fan.PNPDeviceID
- "Power Management Capabilities : {0}" -f (PowerManagementCapabilities($fan.PowerManagementCapabilities))
- "Status : {0}" -f $fan.Status
- "Status Information : {0}" -f (statusinfo($fan.StatusInfo))
- "System Creation Class Name : {0}" -f $fan.syu
- "System Name : {0}" -f $fan.SystemName
- "Variable Speed : {0}" -f $fan.VariableSpeed
- $i++;""
- }
Labels:
powershell,
PowerShell scripts,
Win32_Fan,
wmi
Subscribe to:
Posts (Atom)