[] to create a network share
PS> (Get-WmiObject -List -ComputerName . | Where-Object -FilterScript {$_.Name -eq "Win32_Share"}).Create("C:\temp","TempShare",0,25,"test share of the temp folder")
[] to remove a network share
PS> (Get-WmiObject -Class Win32_Share -ComputerName . -Filter "Name='TempShare'").Delete()
[] to create a new networked drive that maps the share \\FPS01\users to local drive B:
PS> (New-Object -ComObject WScript.Network).MapNetworkDrive("B:", "\\FPS01\users")
Showing posts with label get-wmiobject. Show all posts
Showing posts with label get-wmiobject. Show all posts
Monday, January 19, 2009
Win32_NetworkAdapterConfiguration betw. Win32_NetworkAdapter
[] to retrieve network adapter information such as MAC addresses and adapter types
PS> Get-WmiObject -Class Win32_NetworkAdapter -ComputerName .
[] to find the DHCP-enabled adapters on a computer
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=true" -ComputerName .
[] to find the IP-enabled adapters on a computer
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
[] to enable DHCP on all adapters
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName .
| ForEach-Object -Process {$_.EnableDHCP()}
[] to releases all DHCP leases on adapters on the local computer that are obtaining DHCP leases from 192.168.1.254
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
| Where-Object -FilterScript {$_.DHCPServer -contains "192.168.1.254"}
| ForEach-Object -Process {$_.ReleaseDHCPLease()}
[] to renew a DHCP lease
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
| Where-Object -FilterScript {$_.DHCPServer -contains "192.168.1.254"}
| ForEach-Object -Process {$_.ReleaseDHCPLease()}
PS> Get-WmiObject -Class Win32_NetworkAdapter -ComputerName .
[] to find the DHCP-enabled adapters on a computer
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=true" -ComputerName .
[] to find the IP-enabled adapters on a computer
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
[] to enable DHCP on all adapters
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName .
| ForEach-Object -Process {$_.EnableDHCP()}
[] to releases all DHCP leases on adapters on the local computer that are obtaining DHCP leases from 192.168.1.254
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
| Where-Object -FilterScript {$_.DHCPServer -contains "192.168.1.254"}
| ForEach-Object -Process {$_.ReleaseDHCPLease()}
[] to renew a DHCP lease
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true and DHCPEnabled=true" -ComputerName .
| Where-Object -FilterScript {$_.DHCPServer -contains "192.168.1.254"}
| ForEach-Object -Process {$_.ReleaseDHCPLease()}
ping with Win32_PingStatus class
[] to ping against a computer (Address, ResponseTime)
PS> Get-WmiObject -Class Win32_PingStatus -Filter "Address='127.0.0.1'" -ComputerName .
| Format-Table -Property Address,ResponseTime,StatusCode -Autosize
[] to ping all of the computers on a subnet
PS> 1..254
| ForEach-Object -Process {Get-WmiObject -Class Win32_PingStatus -Filter ("Address='192.168.1." + $_ + "'") -ComputerName .}
| Select-Object -Property Address,ResponseTime,StatusCode
Private network number (192.168.1.0) and Class C subnet mask (255.255.255.0)
PS> Get-WmiObject -Class Win32_PingStatus -Filter "Address='127.0.0.1'" -ComputerName .
| Format-Table -Property Address,ResponseTime,StatusCode -Autosize
[] to ping all of the computers on a subnet
PS> 1..254
| ForEach-Object -Process {Get-WmiObject -Class Win32_PingStatus -Filter ("Address='192.168.1." + $_ + "'") -ComputerName .}
| Select-Object -Property Address,ResponseTime,StatusCode
Private network number (192.168.1.0) and Class C subnet mask (255.255.255.0)
gets IP addresses, DHCP, DNS, routing
[] to get all IP addresses in use on the local computer
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress
[] to display detailed IP configuration data for each network adapter
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .
[] to display detailed information about DHCP, DNS, routing
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress
[] to display detailed IP configuration data for each network adapter
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .
[] to display detailed information about DHCP, DNS, routing
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
add/remove printer
[] to add a new network printer
PS> (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\Printserver01\Xerox5")
[] to set the default printer
PS> (Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='HP LaserJet 5Si'").SetDefaultPrinter()
or,
PS> (New-Object -ComObject WScript.Network).SetDefaultPrinter('HP LaserJet 5Si')
[] to remove a printer connection
PS> (New-Object -ComObject WScript.Network).RemovePrinterConnection("\\Printserver01\Xerox5")
PS> (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\Printserver01\Xerox5")
[] to set the default printer
PS> (Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='HP LaserJet 5Si'").SetDefaultPrinter()
or,
PS> (New-Object -ComObject WScript.Network).SetDefaultPrinter('HP LaserJet 5Si')
[] to remove a printer connection
PS> (New-Object -ComObject WScript.Network).RemovePrinterConnection("\\Printserver01\Xerox5")
log-off, shut-down, re-boot system
[] to logoff current session
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(0)
[] to shut down the computer
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(1)
[] to reboot the operating system
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(0)
[] to shut down the computer
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(1)
[] to reboot the operating system
PS> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
list the applications installed with the Windows Installer (MSI)
[] to list the applications installed with the Windows Installer, esp. those hidden from appwiz.cpl, in a summary
PS> Get-WmiObject -Class Win32_Product -ComputerName .
IdentifyingNumber : {95120000-00B9-0409-0000-0000000FF1CE}
Name : Microsoft Application Error Reporting
Vendor : Microsoft Corporation
Version : 12.0.6012.5000 <--- SQL Server 2008 component
Caption : Microsoft Application Error Reporting
[] to list the applications installed with the Windows Installer, esp. those hidden from appwiz.cpl, in detail
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fl -Property *
Extra information are InstallDate, PackageCache etc.
[] to list the applications installed with the Windows Installer, esp. those hidden from appwiz.cpl, in specified properties
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fl -Property Name,InstallDate,InstallLocation,PackageCache,Vendor
Name : Microsoft Application Error Reporting
InstallDate : 20081130
InstallLocation :
PackageCache : C:\LINDOWS\Installer\583d7.msi
Vendor : Microsoft Corporation
[] to find only the names of installed applications using Windows Installer
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fw -Column 1
MSXML4 Parser
Microsoft Application Error Reporting
Microsoft .NET Framework 3.0 Service Pack 2
Microsoft .NET Framework 3.5 SP1
Windows PowerShell(TM) V2 (CTP2)
Microsoft Office Access 2003 Runtime
Microsoft .NET Framework 2.0 Service Pack 2
PS> Get-WmiObject -Class Win32_Product -ComputerName .
IdentifyingNumber : {95120000-00B9-0409-0000-0000000FF1CE}
Name : Microsoft Application Error Reporting
Vendor : Microsoft Corporation
Version : 12.0.6012.5000 <--- SQL Server 2008 component
Caption : Microsoft Application Error Reporting
[] to list the applications installed with the Windows Installer, esp. those hidden from appwiz.cpl, in detail
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fl -Property *
Extra information are InstallDate, PackageCache etc.
[] to list the applications installed with the Windows Installer, esp. those hidden from appwiz.cpl, in specified properties
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fl -Property Name,InstallDate,InstallLocation,PackageCache,Vendor
Name : Microsoft Application Error Reporting
InstallDate : 20081130
InstallLocation :
PackageCache : C:\LINDOWS\Installer\583d7.msi
Vendor : Microsoft Corporation
[] to find only the names of installed applications using Windows Installer
PS> Get-WmiObject -Class Win32_Product -ComputerName . | fw -Column 1
MSXML4 Parser
Microsoft Application Error Reporting
Microsoft .NET Framework 3.0 Service Pack 2
Microsoft .NET Framework 3.5 SP1
Windows PowerShell(TM) V2 (CTP2)
Microsoft Office Access 2003 Runtime
Microsoft .NET Framework 2.0 Service Pack 2
is .NET CLR 2.0 running now?
to identify NT services' StartMode, ProcessId, and State
PS> Get-WmiObject -Class Win32_Service -ComputerName .
ExitCode : 0
Name : clr_optimization_v2.0.50727_32
ProcessId : 1492
StartMode : Auto
State : Running
Status : OK
When PowerShell v1.0, V2CTP2, or V2CTP3 is used for this project.
PS> Get-WmiObject -Class Win32_Service -ComputerName .
ExitCode : 0
Name : clr_optimization_v2.0.50727_32
ProcessId : 1492
StartMode : Auto
State : Running
Status : OK
When PowerShell v1.0, V2CTP2, or V2CTP3 is used for this project.
retrieve the current local time
PS> Get-WmiObject -Class Win32_LocalTime -ComputerName .
| Select-Object -Property [a-z]*
Information like DayOfWeek, WeekInMonth, Quarter etc.
| Select-Object -Property [a-z]*
Information like DayOfWeek, WeekInMonth, Quarter etc.
get information summary of CPU, OS, Licenses
[] to get version information summary of current CPU and OS
PS> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion
BuildNumber : 2600 <---- SP2
BuildType : Uniprocessor Free
OSType : 18 <---- XP
ServicePackMajorVersion : 2
ServicePackMinorVersion : 0
[] to retrieve information e.g. number of licensed users, current number of users, and owner name
PS> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property *user* | fl
NumberOfLicensedUsers :
NumberOfUsers : 2
RegisteredUser : Jose Clinton <--- UserName
My laptop software configuration.
PS> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property BuildNumber,BuildType,OSType,ServicePackMajorVersion,ServicePackMinorVersion
BuildNumber : 2600 <---- SP2
BuildType : Uniprocessor Free
OSType : 18 <---- XP
ServicePackMajorVersion : 2
ServicePackMinorVersion : 0
[] to retrieve information e.g. number of licensed users, current number of users, and owner name
PS> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-Object -Property *user* | fl
NumberOfLicensedUsers :
NumberOfUsers : 2
RegisteredUser : Jose Clinton <--- UserName
My laptop software configuration.
list all installed hotfixes
to list all installed hotfixes Id only
PS> Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName . -Property HotFixId | Select-Object -Property HotFixId
HotFixId
--------
File 1
File 1
File 1
Q147222
KB942288-v3
KB954550-v5
XpsEPSC
PS> Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName . -Property HotFixId | Select-Object -Property HotFixId
HotFixId
--------
File 1
File 1
File 1
Q147222
KB942288-v3
KB954550-v5
XpsEPSC
provide OEM data of computer model
PS> Get-WmiObject -Class Win32_ComputerSystem
Domain : WORKGROUP
Manufacturer : Acer
Model : Aspire 5610
Name : NPARKS <--- ComputerName
PrimaryOwnerName : Jose Clinton <--- UserName
TotalPhysicalMemory : 1063309312 <--- in bytes; 1GB
My laptop configuration.
Domain : WORKGROUP
Manufacturer : Acer
Model : Aspire 5610
Name : NPARKS <--- ComputerName
PrimaryOwnerName : Jose Clinton <--- UserName
TotalPhysicalMemory : 1063309312 <--- in bytes; 1GB
My laptop configuration.
retrieve CPU information
PS> Get-WmiObject -Class Win32_Processor -ComputerName .
Information like CurrentClockSpeed, CurrentVoltage, L2CacheSize, ExtClock, MaxClockSpeed, ProcessorId, SocketDesignation etc.
Information like CurrentClockSpeed, CurrentVoltage, L2CacheSize, ExtClock, MaxClockSpeed, ProcessorId, SocketDesignation etc.
collect information about the desktops
to collect information about the desktops on the local computer
PS> Get-WmiObject -Class Win32_Desktop -ComputerName .
Information like IconSpacing, IconTitleFaceName, ScreenSaverTimeout, Wallpaper etc.
PS> Get-WmiObject -Class Win32_Desktop -ComputerName .
Information like IconSpacing, IconTitleFaceName, ScreenSaverTimeout, Wallpaper etc.
Sunday, January 18, 2009
quick view of free disk space and drive type
[] to return free space information for each local disk in terms of bytes
PS> get-wmiobject -class win32_logicaldisk | ft -auto -Property DeviceId,DriveType,FreeSpace,Size,VolumeName
DeviceId DriveType FreeSpace Size VolumeName
-------- --------- --------- ---- ----------
C: 3 9533083648 20958011392 ACER
D: 3 2435698688 4992708608 MISC
E: 3 28816961536 50668896256 DATA
F: 5 <---- CDROM drive
R: 3 16655360 16694784 RamDisk
S: 5
[] to return free space information for each local disk in terms of GB
PS> Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property Name,FreeSpace | ForEach-Object -Process {$_.FreeSpace = ($_.FreeSpace)/1024.0/1024.0/1024.0; $_} | ft -auto
Name FreeSpace
---- ---------
C: 8.87826919555664
D: 2.2684211730957
E: 26.8378868103027
F: 0
R: 0.0155115127563477
S: 0
PS> get-wmiobject -class win32_logicaldisk | ft -auto -Property DeviceId,DriveType,FreeSpace,Size,VolumeName
DeviceId DriveType FreeSpace Size VolumeName
-------- --------- --------- ---- ----------
C: 3 9533083648 20958011392 ACER
D: 3 2435698688 4992708608 MISC
E: 3 28816961536 50668896256 DATA
F: 5 <---- CDROM drive
R: 3 16655360 16694784 RamDisk
S: 5
[] to return free space information for each local disk in terms of GB
PS> Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property Name,FreeSpace | ForEach-Object -Process {$_.FreeSpace = ($_.FreeSpace)/1024.0/1024.0/1024.0; $_} | ft -auto
Name FreeSpace
---- ---------
C: 8.87826919555664
D: 2.2684211730957
E: 26.8378868103027
F: 0
R: 0.0155115127563477
S: 0
system drivers running endlessly
to list out the 'Running' State of system drivers
PS> Get-WmiObject -Class Win32_SystemDriver | Where-Object -FilterScript {$_.State -eq "Running"}
DisplayName : XAudio <--- a sample
Name : XAudio
State : Running
Status : OK
Started : True
PS> Get-WmiObject -Class Win32_SystemDriver | Where-Object -FilterScript {$_.State -eq "Running"}
DisplayName : XAudio <--- a sample
Name : XAudio
State : Running
Status : OK
Started : True
display available memory data
[] to display available memory data
PS> Get-WmiObject -Class Win32_OperatingSystem -Property TotalVirtualMemorySize,TotalVisible
MemorySize,FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles
FreePhysicalMemory : 757084
FreeSpaceInPagingFiles : 2280892
FreeVirtualMemory : 2037184
TotalVirtualMemorySize : 2097024
TotalVisibleMemorySize : 1038388
[] to display available memory data more readable
PS> Get-WmiObject -Class Win32_OperatingSystem
| fl -Property TotalV*,Free*
TotalVirtualMemorySize : 2097024
TotalVisibleMemorySize : 1038388
FreePhysicalMemory : 758992
FreeSpaceInPagingFiles : 2280504
FreeVirtualMemory : 2037184
PS> Get-WmiObject -Class Win32_OperatingSystem -Property TotalVirtualMemorySize,TotalVisible
MemorySize,FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles
FreePhysicalMemory : 757084
FreeSpaceInPagingFiles : 2280892
FreeVirtualMemory : 2037184
TotalVirtualMemorySize : 2097024
TotalVisibleMemorySize : 1038388
[] to display available memory data more readable
PS> Get-WmiObject -Class Win32_OperatingSystem
| fl -Property TotalV*,Free*
TotalVirtualMemorySize : 2097024
TotalVisibleMemorySize : 1038388
FreePhysicalMemory : 758992
FreeSpaceInPagingFiles : 2280504
FreeVirtualMemory : 2037184
retrieve information about a computer
PS> get-wmiobject -class win32_operatingsystem
SystemDirectory : C:\LINDOWS\system32 <---- where drivers are stored
Organization : Regional Farmstay Inc. <---- same as Company
BuildNumber : 2600 <---- Service Pack 2
RegisteredUser : Jose Clinton <---- same as User Name
SerialNumber : 55274-642-3428963-23367 <---- actual is alphanumeric
Version : 5.1.2600 <---- Windows XP SP2
SystemDirectory : C:\LINDOWS\system32 <---- where drivers are stored
Organization : Regional Farmstay Inc. <---- same as Company
BuildNumber : 2600 <---- Service Pack 2
RegisteredUser : Jose Clinton <---- same as User Name
SerialNumber : 55274-642-3428963-23367 <---- actual is alphanumeric
Version : 5.1.2600 <---- Windows XP SP2
WMI classes from Local/Remote computer
[] to get a list of the WMI classes available on the local computer
PS> get-wmiobject -list
[] to get a list of the WMI classes available on the remote computer by specifying a computer name or IP address
PS> get-wmiobject -list -computername 127.0.0.1
PS> get-wmiobject -list
[] to get a list of the WMI classes available on the remote computer by specifying a computer name or IP address
PS> get-wmiobject -list -computername 127.0.0.1
Saturday, January 17, 2009
get-wmiObject
to get info about the BIOS on the local computer
PS> get-wmiobject win32_bios -computername nparks
SMBIOSBIOSVersion : V3.50
Manufacturer : Acer
Name : Ver 1.00PARTTBLP
SerialNumber : LXAU60J0077020D4581601
Version : ACRSYS - 6040000
PS> get-wmiobject win32_bios -computername nparks
SMBIOSBIOSVersion : V3.50
Manufacturer : Acer
Name : Ver 1.00PARTTBLP
SerialNumber : LXAU60J0077020D4581601
Version : ACRSYS - 6040000
Subscribe to:
Posts (Atom)