Showing posts with label new-object. Show all posts
Showing posts with label new-object. Show all posts

Monday, January 19, 2009

network share and networked drive

[] 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")

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")

Sunday, January 18, 2009

wipe out entries not wanted in Event Log

to clear an event log's entries of the Application log

PS> $AppLog = new-object -typename system.diagnostics.eventlog -argumentlist application
PS> $AppLog

Max(K) Retain OverflowAction Entries Name
------ ------ -------------- ------- ----
51,200 -1 DoNotOverwrite 2,523 Application <--- before


PS> $AppLog.Clear()
PS> $AppLog

Max(K) Retain OverflowAction Entries Name
------ ------ -------------- ------- ----
51,200 -1 DoNotOverwrite 0 Application <--- after

gather total number of Event Log entries

to get information about an event log, e.g. Application

PS> new-object -typename system.diagnostics.eventlog -argumentlist application

Max(K) Retain OverflowAction Entries Name
------ ------ -------------- ------- ----
51,200 -1 DoNotOverwrite 2,523 Application

Event viewer won't show these valuable information.