Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

2016-04-08

PowerShell: How to clear all Event Logs

Run PowerShell as an administrator and use example:

wevtutil el | Foreach-Object {wevtutil cl "$_"}

Warining! Command will clear ALL events on ALL event logs!


/Geecoholic

2016-03-01

PowerShell: How to get users list with password related information from AD

The following example demonstrates how get user list from Active Directory(AD) and export to excel friendly format with non ASCII characters for later filtering:

$maxPasswordAge = (get-addefaultdomainpasswordpolicy).MaxPasswordAge.Days

Get-ADUser -Filter * -Properties CannotChangePassword,PasswordNeverExpires,LastLogonDate,Passwordexpired,passwordlastset | Select Name, SamAccountName ,CannotChangePassword, PasswordNeverExpires, Enabled, LastLogonDate, Passwordexpired, Passwordlastset,@{l="ExpiryDate";e={$_.PasswordLastSet.AddDays($maxPasswordAge)}} | sort -property name | export-csv users_export.csv -Encoding UTF8


/Geecoholic

2016-02-28

VBScript: How to get needed Windows updates count

Save sample below to a file named NeededUpadatesCount.vbs:

Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "Geecoholic Script"

Set updateSearcher = updateSession.CreateUpdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")

WScript.Echo "Updates Count: " & searchResult.Updates.Count
WScript.Quit


 You can run the sample by opening a Command Prompt window and typing the following command at the command prompt:

script NeededUpadatesCount.vbs

Script made using example from MS link

/Geecoholic

2016-02-26

PowerShell: Total all hdd space script

On local computer:

Get-WMIObject Win32_LogicalDisk | ForEach-Object {[math]::round($_.size / 1GB)}|Measure-Object -sum | select sum

On remote computer:

Get-WMIObject Win32_LogicalDisk -ComputerName RemoteComputerName | ForEach-Object {[math]::round($_.size / 1GB)}|Measure-Object -sum | select sum

/Geecoholic