Sunday, January 25, 2009

rename computer

Expert PowerShell advice and commentary from Dr. Tobias Weltner.

Function
 Rename-ComputerName ([string]$NewComputerName){ 

 
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem 
$ComputerInfo.rename($NewComputerName
 

This script shows you how to rename computer by using WMI

How to use it :

& .\rename-computerName.ps1

rename-computername "MyNewComputerNAME"

And to reboot you can use WMI class Win32_OperatingSystem and its method reboot():

$OS = Get-WmiObject -Class Win32_OperatingSystem

$OS.reboot()

OR

shutdown -r -t 10 -f -c "Restart OS"

Users of PowerShell V2 (currently CTP3) can use the Restart-Computer cmdlet too. :)

DETAILED DESCRIPTION

   The Restart-Computer cmdlet restarts the operating system on the local and remote computers.

   You can use the parameters of Restart-Computer to run the restart operations as a background job, to specify the authentication levels and alternate credentials, to limit the operations that run concurrently, and to force an immediate restart.

   This cmdlet does not require Windows PowerShell remoting unless you use the AsJob parameter.



Friday, January 23, 2009

Get-QADComputer Lastlogintime

=========

also switched lastLogonTimeStamp with pwdLastSet
Re: Get-QADComputer Lastlogintime
Posted: Dec 16, 2008 7:29 AM in response to: alex.stefishen@...
Answered
Reply

Sure. :-)

$limit = (get-date).AddDays(-30).ToFileTime()
$filter = "(&(objectcategory=computer)(|(lastLogonTimestamp<=$limit)(!(lastLogonTimestamp=*))))" $inactivecomputers = Get-QADComputer -ldapFilter $filter -ip lastlogontimestamp -SizeLimit 0 $inactivecomputers | ft name,@{l="LastLogonTimeStamp";e={if($_.lastLogonTimestamp -ne $null){[DateTime]::FromFileTime([Int64]::Parse($_.lastLogonTimestamp))}} } -autosize

Saturday, January 3, 2009

Get-QADComputer Lastlogintime

Get-QADComputer Lastlogintime                      

This code will give you the computers that have been inactive for 30 days:

$limit = (get-date).AddDays(-30).ToFileTime()
$filter = "(&(objectcategory=computer)(|(lastLogonTimestamp<=$limit)(!(lastLogonTimestamp=*))))" $inactivecomputers = Get-QADComputer -ldapFilter $filter -SizeLimit 0


It's faster than piping to where-object.


show the time stamp?



$limit = (get-date).AddDays(-30).ToFileTime()
$filter = "(&(objectcategory=computer)(|(lastLogonTimestamp<=$limit)(!(lastLogonTimestamp=*))))"

$inactivecomputers = Get-QADComputer -ldapFilter $filter -ip lastlogontimestamp -SizeLimit 0

$inactivecomputers | ft name,@{l="LastLogonTimeStamp";e={if($_.lastLogonTimestamp -ne $null){[DateTime]::FromFileTime([Int64]::Parse($_.lastLogonTimestamp))}} } -autosize


managing AD

Manage my AD OU with powergui