popunder new

https://www.blogger.com/blog/posts/1739890295310631346

Wednesday, December 12, 2012

List members of all local groups on a list of computers vbs script

Here is a script that I use to list members of all local groups on a list of computers. It takes a list of computer names and checks the group members on each one then writes the results to a second file. Change the file paths in lines 6,18 and 33 to match your environment. When its complete it will open the text file with the enumerated computers.

 Const ForAppending = 8  
Const ForReading = 1
ServerCount = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\scripts\serverlist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
strComputer = strNextLine
'WScript.Echo "Processing " & strComputer
ProcessGroups
ServerCount = ServerCount + 1
Loop
'WScript.Echo "Computers Processed " & ServerCount
'WScript.Quit
Sub ProcessGroups
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\scripts\GroupInfo.txt", _
ForAppending, True)
objLogFile.writeline " "
objLogFile.writeline "***************** " & strComputer & " *****************"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
objLogFile.writeline objGroup.Name
For Each objUser in objGroup.Members
objLogFile.writeline vbTab & objUser.Name
Next
Next
objLogFile.Close
End Sub
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\scripts\GroupInfo.txt"

Sunday, November 18, 2012

Windows Explorer MRU (most recently used) search clear powershell script

This one line powershell script will clear the Windows Explorer MRU (most recently used) search list.

The downloaded zip file also includes both the ps1 script and a compiled exe (executable) version of the script for those who want to run it without launching powershell or if you want to place the exe in your windows start-up folder to clear the search entries each time you start windows.  It works on Vista, Windows 7 or windows 8 and server 2008 or 2012. Getting to your startup folder in Windows 8 or Server 2012 requires browsing to the  location below

C:\Users\<User Profile folder name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Download Button5

Tuesday, November 13, 2012

Restoring deleted or messed up srv records in Windows Server 2012

There are occasions when you play with things you shouldn’t.  In those cases where you accidentally delete your SRV records it is very easy to get them back.

Go to an administrative command prompt an type nltest /dsregdns

Check the short 60 second video below.



Friday, November 9, 2012

Using Windows PowerShell to convert from a Windows Server 2012 Core installation to a Windows Server 2012 with a GUI installation

When you install Windows Server 2012, you can choose between Server Core Installation and Server with a GUI. The “Server with a GUI” option is the Windows Server 2012 equivalent of the Full installation option available in Windows Server 2008 R2. The “Server Core Installation” option reduces the space required on disk, the potential attack surface, and especially the servicing requirements. You can freely switch between these options at any time., one approach might be to initially install the Server with a GUI option, use the graphical tools to configure the you can freely switch between these options at any time later.

To add the Server with a GUI  to a Server Core from the  windows server core  command prompt  type
start powershell

In PowerShell type
Install-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell -Restart

This will start the installation of the gui feature and restart the system when it completes.

Once the system restarts and you login you will be presented with the standard windows server 2012 with the GUI

Check the short video below for a demonstration.




Thursday, October 25, 2012

Microsoft Windows 8 RDP all-in-one combo updater for Windows 7 & Server 2008 R2

Microsoft loves to make updates more complicated than they need to be. To simplify the process I have created and installer that automates the process.

My Windows 8 RDP all-in-one combo updater packages will install silently both required updates for you and then prompt you to restart your system.

There is one package for Windows 7 x86 and another for either Windows 7 x64 or Windows Server R2.

You will be prompted to restart the system when the updates completes.



Choose Yes  to restart now or No to restart later. The new client will not take effect until you restart.

Download Button5

Wednesday, October 24, 2012

Official MS RDP 8.0 Update for Windows 7 SP1 Released

The official Microsoft RDP 8.0 client for windows 7 x86 and x64 and for server 2008 has been released.

Make sure you download and install update 2574819 (links below) before installing  the RDP 8.0 client.  Each of these updates prompts for a re-boot, though I skipped the re-boot and continued to the second install before re-booting and it installed fine.  

Instead of downloading each file below and running them individually check my blog here if you want to download my MS Windows 8 RDP all-in-one combo updater package that automates the below process into one installer.

Operating systemUpdate
All supported x86-based versions of Windows 7DownloadDownload and install this update first (ignore reboot)
All supported x64-based versions of Windows 7DownloadDownload and install this update first  (ignore reboot)
All supported x64-based versions of Windows Server 2008 R2DownloadDownload and install this update first  (ignore reboot)

How to verify that RDP 8.0 is enabled

To verify that RDP 8.0 is enabled on a remote computer that is running Windows 7 SP1, connect to the computer from a computer that is running Windows 8 or that is running Windows 7 SP1 by using Remote Desktop Connection (RDC) 8.0. After you connect to the computer, follow these steps to verify that RDP 8.0 is enabled:

  1. If RDP 8.0 is enabled, the connection quality button will be displayed in the connection bar.

  2. Click the connection quality button to open an information dialog box that resembles the following.


The presence of the connection quality button and of the connection quality dialog box confirms the availability of RDP 8.0 for the remote connection.

Those who,  because of the  issues stated below,  want to keep their old client version can still download my version which retains you old rdp client. Check my blog here 
Known issues with the RDP 8.0 update

  1. Virtual desktops that have RemoteFX vGPU installed cannot use RDP 8.0.
    Issue

    After you install and enable RDP 8.0 by using Group Policy on a computer that has RemoteFX vGPU installed, RDP 8.0 is not available.
    Resolution

    This update does not enable RDP 8.0 for connections to computers that have RemoteFX vGPU installed. If you must have RDP 8.0 enabled, remove RemoteFX vGPU from the virtual desktop to enable RDP 8.0.

  2. The Shadow command cannot be used to remotely monitor another user's remote connection.
    Issue
    Windows 7 SP1 supports the Shadow command (Remote Control). This command can be used by an administrator to view or control an active session of another user. After RDP 8.0 is enabled on a computer that is running Windows 7 SP1, an administrator user cannot use the Shadow command to view or control another user's session.
    Resolution
    Administrators can use Remote Assistance or another product that provides similar capability to view or control another user's session.

  3. Aero Glass support is unavailable.
    Issue
    The Aero Glass remoting feature in Windows 7 lets users who are running compatible Remote Desktop Connection clients use features such as a Flip-3D, the live task bar preview, and the translucent window border in a remote desktop connection when a compatible RDC 7.0 client is used. After RDP 8.0 is enabled, users cannot use the Aero Glass remoting feature.
    Resolution
    Administrators should not enable RDP 8.0 on remote computers that are running Windows 7 SP1 for users who must use the Aero Glass remoting feature.

  4. RDP 8.0 on remote computers that are running Windows 7 SP1 does not use the UDP protocol.
    Issue
    The RemoteFX for WAN feature in RDP 8.0 intelligently uses TCP and UDP protocols to optimize the user experience. After you install and enable RDP 8.0 on computers that are running Windows 7 SP1, RDP 8.0 is configured to use only the TCP protocol.
    Resolution
    To resolve this issue, configure RDP 8.0 to use both the TCP and UDP protocols. For more information, see the "How to enable RDP 8.0" section.

  5. Local administrators who are not a member of the Remote Desktop Users group cannot sign in by using a Remote Desktop Connection client.
    Issue
    After RDP 8.0 is enabled, local administrators who are not a member of the Remote Desktop Users group cannot sign in.
    Resolution
    To resolve this issue, add local administrator users to the Remote Desktop Users group.

  6. The firewall rule that allows UDP traffic is not enabled when you use a Group Policy Object (GPO) to enable RDP 8.0.
    Issue
    If you use a GPO to enable RDP 8.0, the UDP firewall rule that allows UDP traffic is not enabled sometimes.
    Resolution

    To resolve this issue, create a GPO to enable the Remote Desktop - User Mode (UDP-In) firewall.

  7. You experience slow performance when IPsec is deployed in the network.
    Issue
    When you connect to a computer by using the RDP 8.0 protocol in certain situations, you experience slow performance. This issue occurs when IPsec is deployed in the network.
    Resolution
    To resolve this issue, install hotfix 2570170 on the server.

    For more information about hotfix 2570170, click the following article number to view the article in the Microsoft Knowledge Base:
    2570170 Performance issue when you enable the AuthNoEncap policy to handle large payloads in a network environment in Windows 7 or in Windows Server 2008 R2

  8. You cannot use the multi-touch and gestures functionalities when you connect to a computer remotely.
    Issue
    You cannot use the multi-touch and gestures functionalities when you use Remote Desktop Connection Client 8.0 on a computer that is running Windows 7 SP1.
    Resolution
    The RemoteFX multi-touch feature is supported only when both the client and server computers are running Windows 8 or Windows Server 2012.

Tuesday, October 23, 2012

Using Windows PowerShell to fix a broken Secure Channel and reset the computer account

When a computer joins a domain, a computer account is created in AD. The computer account gets its own password that will expire after 30 days (default). When the password expires, the computer itself will initiate a password change with a DC in its domain.

When the computer starts up, it uses this password to create a secure channel (SC) with a DC. The computer will request to sign all traffic that passes the SC. If a DC says “go ahead”, all traffic that is signed passes through this channel.

Traffic like NTLM pass through authentication is typically signed traffic.

So what happens if there is a mismatch between the computer account password? The computer tries to authenticate, but the DC says this is not the correct password.

The SC is down.

To reset the SC between a computer and a DC:

Open PowerShell on the local computer with the broken SC and run the cmdlet:

Test-ComputerSecureChannel -repair

*The cmdlet requires PowerShell 2.0  (which is pre-installed on Win7/2008R2) or greater

Tuesday, October 16, 2012

Restart Windows 8 or server 2012 in a remote desktop session

Restarting  Windows 8 or Server 2012 when in a remote desktop session


When you're in a remote desktop connection in Windows 8 or Server 2012 the quickest way to restart the PC is to go to the desktop and  press ALT-F4.   Pressing Alt-F4  inside an application will close that application, so make sure you are on the desktop.

The below Shut Down Windows screen will appear. Choose Restart to restart the system.

Wednesday, September 5, 2012

Windows Management Framework 3.0 "This update is not applicable to your computer" error

Windows Management Framework 3.0 (Includes PowerShell 3.0, WMI & WinRM for downlevel Win7, 2008, & 2008 R2) is now available here http://www.microsoft.com/en-us/download/details.aspx?id=34595.  For those getting a "This update is not applicable to your computer" error when trying to install it



Update your  Microsoft .Net Framework 4 first. Get it here http://www.microsoft.com/en-us/download/details.aspx?id=17851



After the update the install should complete fine.

Thursday, August 16, 2012

Find system uptime on Server 2012


  1. Right-Click in your taskbar and select Task Manager

  2. Select the performance tab

Or have a look at the 18 second video below.






Sunday, August 12, 2012

Getting the New Windows 8 Remote Desktop client on your Windows 7 system

The Remote Desktop Client Connection Software that comes with Windows 8 or Windows Server 2012 features a new menu called the Remote Commands menu. This menu allows you to send special commands, such as a start menu, accessing the Windows 8 / Windows Server 2012 Charms, switching apps, snapping apps and application specific app commands.

If you are in a windowed remote desktop session you can access the remote commands by selecting the remote desktop icon and then choosing remote commands.


If you are running remote desktop full screen click the down arrow on the connection bar to display the remote commands.



If you can’t wait for Microsoft to publish a version of the new Remote Desktop client for windows 7, then all is not lost. There is a way for Admins still running windows 7 desktops to get the new version on their systems. You have to copy four files from a Windows 8 x64 or Server 2012 system to your windows 7 x64 system.  If using windows 7 x86 then copy the files from a windows 8 x86 system

  • mstsc.exe  (in c:windowssystem32)

  • mstscax.dll  (in c:windowssystem32)

  • mstsc.exe.mui  (in c:windowssystem32en-US)

  • mstscax.dll.mui  (in c:windowssystem32en-US)


Instead of overwriting the existing files on your windows 7 system (in case you ever want to revert back to the old version) create a new folder called Remote Desktop 8 anywhere on your system.  I put my folder on my desktop. Now copy mstsc.exe and mstscax.dll to that folder. Inside that folder create another folder called en-US and put the other two files into that. If you’re running a version that is not English then you will need to put the two mui files in the folder that corresponds to your language version.

Running mstsc.exe will now launch the new RDP client with the new remote commands on your Windows 7 system.

Or if you prefer you can download my installers that will automate the process for you.  Available for Windows 7 or Server 2008  in x86 and x64 versions.  English Only

Download Button5


The official Microsoft version has now been released. Check here for links and info or instead of downloading each file from the above link and running them individually get my MS Windows 8 RDP all-in-one combo updater package that automates the process into one installer.

Sunday, July 22, 2012

Quickly creating a WordPress site with Webmatrix 4

WebMatrix is a free and lightweight web development tool.
It lets you create, publish, and maintain your website with ease.

To setup a wordpress site you first need to download Webmatrix 4 here.  After Webmatrix is installed you will download Wordpress  from within Webmartrix and run the installer.


Sunday, July 8, 2012

Disable Internet Explorer Enhanced Internet Security Configuration inWindows Server 2012

Here’s a short 45 second video showing how to turn off Internet Explorer Enhanced Internet Security Configuration in Windows Server 2012



Tuesday, June 5, 2012

Installing Webmatrix on Server 2012

Download Microsoft Web Platform Installer 4.0and choose run when prompted.

Install the application and then access your start menu (windows key) and begin typing the word web,  The search function should display Microsoft Web Platform installer. Run the application

Select the Microsoft Webmatrix 2 refresh.

Choose add and then select install. It will install all the files necessary for the WebMatrix application.

Once installed access your start screen and it should be on the main menu.  If not access the  start menu and begin typing the word webmatrix to search for it.


Monday, May 28, 2012

Powershell Ping Subnet Gui form

This powershell script with GUI Lets you ping an entire subnet or just a range. Run it by entering .PingSubnetGuiForm.ps1'or use the compiled executalbe file Ping Subnet Gui Form.exe included in the zip file download to run without having to launch powershell.

  1. Enter the first three octets in the Subnet box

  2. Then enter the start and end range

  3. Adjust any variables and whether to show only pingable and host names,

  4. Press the Ping button.


Be patient pinging an entire subnet can take time, especially if there are many offline systems.



Download Button5

 

Monday, March 19, 2012

Group Membership Tool - Lets you add , remove or list the members in agroup

This PowerShell script with GUI Lets you add, remove or list local group members on a remote computer. Run it by entering .'group membership tool with gui.ps1'or use the compiled executable file group membership tool with gui.exe included in the zip file download to run without having to launch PowerShell.
  1. Enter the Computer name to check groups on
  2. Select the group name from the drop-down menu or type one of your own.
  3. Enter the username to add or remove from the groups





Download Button5

Tuesday, March 13, 2012

Display computers status report powershell gui script

This powershell script with built-in GUI allows you to point to a text file list of computers and will then retrieve the following information for each computer in the list.
  • Whether it is pingable
  • Its IP address
  • OS Version
  • Service Pack Version
  • Uptime
  • Last boot time.
Run it by entering  .Display-ComputerStatus.ps1 in powershell or run the self-contained executable file.
Change c:computers.txt to point to your text file containing the computers you are scanning one name per line.
The refresh rate can be set by the user to any interval or you can force a rescan at any time by clicking the Get Status Button.



Download Button5

Tuesday, March 6, 2012

Windows 8 Consumer Preview Keyboard Shortcut Keys and Mouse Keys Movements


Windows 8 Start Screen


 



Need to access new Windows 8 Start screen (pictured above) or toggle between the Start screen and an app? The new Start experience replaces the Start button we had on Windows 95 thru to Windows 7

Keyboard: Tap the Windows Key (WINKEY) on your keyboard, or CTRL + ESC.
Mouse: Mouse into the lower left corner of the screen to display the Start tip, and then click it.


Power Menu







The power menu gives you quick access to many commonly needed windows utilites (see picture)

Keyboard: WINKEY + X.

Mouse: Right-click the bottom left corner

Back to previous app


In Windows 8 you can move "back" to the previous app. You can invoke Back with the following input devices:

Keyboard: WINKEY + TAB (or WINKEY + SHIFT + TAB)

Mouse: Move the mouse cursor to the top left corner of the screen. A thumbnail of the previous app will appear. Click it to go Back.

Switching between windows


Switching between the currently running Metro apps and desktop applications. This  works in both the desktop and Metro. You invoke it as follows:

Keyboard: WINKEY + TAB (or WINKEY + SHIFT + TAB)  OR ALT + TAB (SHIFT +ALT + TAB )


Mouse: Move the mouse cursor into the top left corner of the screen. When the thumbnail of the previous app appears, move down the left edge of the screen.



Switcher provides a vertical list of thumbnails representing all of the running apps and applications and, at the bottom, the Start screen. You can navigate between them until you find the one you want; select it, and that app will move to the forefront.
Switcher also lets you close running apps and applications. To do so, drag it out of Switcher and down to the bottom of the screen. (You can also drag thumbnails out of Switcher to utilize the side-by-side screen sharing feature described below.)

Monday, March 5, 2012

Thursday, February 23, 2012

Show Cmdlets with there definitions in Powershell Titlebar

This module creates a PowerShell title bar ticker which cycles every 60 minutes, a Windows PowerShell 2 cmdlet and its definition. Great for those just starting out with Powershell to get them familiar to the new cmdlets and their definitions.
Simply import the module Cmdletdefticker.psm1 or add it to your powershell profile! You can change the cycle frequency from the default 1 hour (3600) seconds to any value you want up to 5 seconds
To import module import-module .cmdletsticker.psm1

To start the module get-cmdletdef

or add both of the above commands to your powershell profile to have it start automatically.
Calling $cmdletdef lists all of the cmdlets in the array

Thanks go to Jeffery Hicks and Boe Prox from which this module is based.



Download Button5

 #requires -version 2.0  
<# use import-module .cmdletsticker.psm1
and then start it by entering get-cmdletdef
change refresh interval value on line 314
#>
Function New-Timer {
<#
.Synopsis
Create an event timer object
.Description
Create an event timer object, primarily to be used by the ConsoleTitle module.
Each timer job will automatically be added to the global variable, $ConsoleTitleEvents
unless you use the -NoAdd parameter. This variable is used by Remove-Timer to clear
console title related timers.
This function is called from within other module functions but you can use it to
create non-module timers.
.Parameter Identifier
A source identifier for your timer
.Parameter Refresh
The timer interval in Seconds. The default is 300 (5 minutes). Minimum
value is 5 seconds.
.Parameter Action
The scriptblock to execute when the timer runs down.
.Parameter NoAdd
Don't add the timer object to the $ConsoleTitleEvents global variable.
#>
Param(
[Parameter(Position=0,Mandatory=$True,HelpMessage="Enter a source identifier for your timer")]
[ValidateNotNullorEmpty()]
[string]$Identifier,
[Parameter(Position=1)]
[validatescript({$_ -ge 5})]
[int]$Refresh=300,
[Parameter(Position=2,Mandatory=$True,HelpMessage="Enter an action scriptblock")]
[scriptblock]$Action,
[switch]$NoAdd
)
Write-Verbose ("Creating a timer called {0} to refresh every {1} seconds." -f $Identifier,$Refresh)
#create a timer object
$timer = new-object timers.timer
#timer interval is in milliseconds
$timer.Interval = $Refresh*1000
$timer.Enabled=$True
#create the event subscription and add to the global variable
$evt=Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier $Identifier -Action $Action
if (-Not $NoAdd) {
#add the event to a global variable to track all events
$global:ConsoleTitleEvents+=$evt
}
#start the timer
$timer.Start()
} #Function
Function Set-TimerInterval {
<#
.Synopsis
Set a new timer refresh interval
.Description
This function will change the interval property of your event timers. You can
either specify a single event subscriber name or use -All to update all timers
to the same value. The refresh interval is in seconds with a minumum value of
5.
.Parameter SourceIdentifier
A source identifier for your timer
.Parameter Refresh
The new timer interval in seconds. Minimum value is 5
.Parameter All
Update all consoletimer event subscribers to the same value
#>
[cmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="default")]
Param (
[Parameter(Position=0,HelpMessage="Enter the sourceidentifier of an event subscriber",ParameterSetName="Default")]
[string]$SourceIdentifier,
[Parameter(Mandatory=$True,HelpMessage="Enter the new refresh interval in seconds")]
[ValidateScript({$_ -ge 5})]
[int]$Refresh,
[Parameter(ParameterSetName="All")]
[switch]$All
)
if ($all) {
$sourceIdentifier=$global:ConsoleTitleEvents | Where {$_.state -eq "Running"} | Select-Object -ExpandProperty Name -Unique
}
if (-Not $SourceIdentifier) {
Write-Error "No value specified for SourceIdentifier"
}
else {
$sourceidentifier | foreach {
Get-EventSubscriber -SourceIdentifier $_ | ForEach {
Write-Verbose $_.SourceIdentifier
if ($psCmdlet.ShouldProcess("$($_.SourceIdentifier) to $Refresh")) {
$_.sourceobject.Interval=($Refresh*1000)
} #should process
} #foreach event subscriber
} #foreach source id
}
} #function
Function Get-Timer {
<#
.Synopsis
Get console timer objects
.Description
Get all event subscribers created for updating the console window title.
#>
Param()
if ($global:ConsoleTitleEvents) {
$global:ConsoleTitleEvents | Where {$_.state -match "Running|NotStarted"} | select name -unique | foreach {
get-eventsubscriber -source $_.name | Select SourceIdentifier,@{Name="Refresh";Expression={
$_.SourceObject.Interval/1000}}, @{Name="Enabled";Expression={$_.SourceObject.Enabled}},
@{Name="Action";Expression={$_.Action.Command}}
}
}
} #function
Function Remove-Timer {
<#
.Synopsis
Remove timer event subscriptions
.Description
This function will remove all console title related timer event subscriptions.
.Parameter Events
The events to remove. This defaults to the global variable $ConsoleTitleEvents
#>
[cmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Position=0)]
[ValidateNotNullorEmpty()]
$Events=$global:ConsoleTitleEvents)
if ($events -is [string]) {
Get-EventSubscriber -SourceIdentifier $events | foreach {
$_ | Unregister-Event
get-job -Name $_.SourceIdentifier | Remove-Job
}
}
else {
#there might be old and new events for the same name, so just get the names
$events | Select -Property Name -Unique | foreach { Get-EventSubscriber -SourceIdentifier $_.name} |
foreach {
$_| Unregister-Event
get-job -Name $_.SourceIdentifier | Remove-Job
}
}
} #Function
Function Start-TitleTimer {
<#
.Synopsis
Create a timer to update the console window title
.Description
This function will update the console window title and create a new event
timer that will update the title at the end of the refresh period. This event
will continue until you remove it or end your PowerShell session.
.Parameter Title
The text to set for the console window title. The default is the value of the
global variable $PSConsoleTitle
.Parameter Refresh
The timer interval in Seconds. The default is 300 (5 minutes). Minimum
value is 5 seconds.
#>
Param(
[Parameter(Position=0)]
[string]$Title=$global:PSConsoleTitle,
[Parameter(Position=1)]
[ValidateScript({$_ -ge 5})]
[int]$Refresh=300
)
Write-Verbose "Creating timer event to update console title every $Refresh seconds"
#create a timer action
$Actionsb= {$host.ui.RawUI.WindowTitle=$Global:PSConsoleTitle}
#invoke the scriptblock to set the title now
Write-Verbose ("{0} Setting window title to {1}. " -f (Get-Date),$Global:PSConsoleTitle)
Invoke-Command -ScriptBlock $ActionSB
#create a timer object
New-Timer -Identifier "TitleTimer" -Refresh $Refresh -Action $ActionSB
} #function
Function Get-SystemStat {
<#
.Synopsis
Set console window title with system information
.Description
This is a sample command to update the console title bar with system
information gathered from WMI. This is a sample:
CLIENT01 CPU:18% FreeMem:931MB Procs:118 Free C:10.57% ▲5.05:23:22
The function will create the necessary background timer.
.Parameter Refresh
The timer interval in Seconds. The default is 300 (5 minutes). Minimum
value is 5 seconds.
#>
Param(
[Parameter(Position=0)]
[ValidateScript({$_ -ge 5})]
[int]$Refresh=300
)
#create a scriptblock
$sb={
#Gather some stats
$cdrive=Get-WMIObject -query "Select Freespace,Size from win32_logicaldisk where deviceid='c:'"
[int]$freeMem=(Get-Wmiobject -query "Select FreeAndZeroPageListBytes from Win32_PerfFormattedData_PerfOS_Memory").FreeAndZeroPageListBytes/1mb
$cpu=Get-WMIObject -class win32_processor -Property loadpercentage
$pcount=(Get-Process).Count
$diskinfo="{0:N2}" -f (($cdrive.freespace/1gb)/($cdrive.size/1gb)*100)
#get uptime
$OS=Get-WmiObject -class Win32_OperatingSystem
$Uptime=(Get-Date) - $OS.ConvertToDateTime($OS.Lastbootuptime)
#parse out milliseconds from uptime
$up=$uptime.tostring().Substring(0,$uptime.ToString().LastIndexOf("."))
[string]$text="{5} CPU:{0}% FreeMem:{6}MB Procs:{1} Free C:{2}% {3}{4}" -f $cpu.LoadPercentage,$pcount,$diskinfo,([char]0x25b2),$up,$env:computername,$FreeMem
Write-verbose $text
$global:PSConsoleTitle=$Text
}
Write-Verbose "Creating timer event to get system stats every $refresh seconds"
#invoke the scriptblock to set the title now
Invoke-Command -ScriptBlock $sb
New-Timer -identifier "SystemStatTimer" -action $sb -refresh $refresh
} #end Function
Function Set-ConsoleTitle {
<#
.Synopsis
Set the console window title
.Description
This function immediately sets the console window title bar. The
default value is $PSConsoleTitle.
.Parameter Title
The new value for the console window title bar.
#>
[cmdletbinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Position=0)]
[ValidateNotNullorEmpty()]
[string]$Title=$global:PSConsoleTitle
)
if ($pscmdlet.shouldprocess($Title)) {
$host.ui.RawUI.WindowTitle=$Title
}
} #function
Function Get-cmdletdef {
<#
.Synopsis
Set console window title with a quote or message
.Description
This is a sample command to update the console title bar with a random
powershell cmdlet and its definition taken from an array of strings, stored in the global
variably $cmdletdef. This array is pre-defined but you can modife the value
of $cmdletdef from your PowerShell session anytime you want.
If there is no title timer object, this command will create it.
.Parameter Refresh
The timer interval in seconds. The default is 3600 (60 minutes). Minimum
value is 5 seconds.
#>
Param(
[Parameter(Position=0)]
[ValidateScript({$_ -ge 5})]
[int]$Refresh=3600
)
#Define an array of powershell commands and cmdlets including active directory cmdlets to display
#we'll create as a globally scoped variable so you can add to it anytime you want from PowerShell
$global:cmdletdef=@(
"Get-Acl - Get permission settings for a file or registry key",
"Get-AuthenticodeSignature - Get the signature object associated with a file",
"Set-Acl - Set permissions",
"Get-Alias - gal Return alias names for Cmdlets",
"Import-Alias - ipal Import an alias list from a file",
"New-Alias - nal Create a new alias.",
"Set-Alias - sal Create or change an alias",
"Set-AuthenticodeSignature - Place a signature in a .ps1 script or other file",
"Set-Location - cd/chdir/sl Set the current working location",
"Get-ChildItem - dir/ls/gci Get child items (contents of a folder or registry key)",
"Clear-Host - clear/cls Clear the screen",
"Clear-Item - cli Remove content from a variable or an alias",
"Get-Command - gcm - Retrieve basic information about a command",
"Measure-Command - Measure running time",
"Trace-Command - Trace an expression or command",
"Add-Computer - Add a computer to the domain",
"Checkpoint-Computer - Create a system restore point (XP)",
"Remove-Computer - Remove the local computer from a workgroup or domain",
"Restart-Computer - Restart the operating system on a computer",
"Restore-Computer - Restore the computer to a previous state",
"Stop-Computer - Stop (shut down) a computer",
"Reset-ComputerMachinePassword - Reset the machine account password for the computer",
"Test-ComputerSecureChannel - Test and repair the secure channel to the domain",
"Add-Content - ac - Add to the content of the item",
"Get-Content - cat/type/gc - Get content from item (specific location)",
"Set-Content - sc - Set content in the item (specific location)",
"Clear-Content - clc - Remove content from a file/item",
"Get-Command - gcm - Get basic information about cmdlets",
"Invoke-Command - icm - Run command",
"Enable-ComputerRestore - Enable System Restore on a drive",
"Disable-ComputerRestore - Disable System Restore on a drive",
"Get-ComputerRestorePoint - Get the restore points on the local computer",
"Test-Connection - Ping one or more computers",
"ConvertFrom-CSV - Convert object properties (in CSV format) into CSV objects",
"ConvertTo-CSV - Convert .NET Framework objects into CSV variable-length strings",
"ConvertTo-Html - Convert the input into an HTML table",
"ConvertTo-Xml - Convert the input into XML",
"ConvertFrom-SecureString - Convert a secure string into an encrypted standard string",
"ConvertTo-SecureString - Convert an encrypted standard string into a secure string",
"Copy-Item - copy/cp/ci - Copy an item from a namespace location",
"Export-Counter - Export Performance Counter data to log files",
"Get-Counter - Get performance counter data",
"Import-Counter - Import performance counter log files",
"Get-Credential - Get a security credential (username/password)",
"Get-Culture - Get region information (language and keyboard layout)",
"Get-ChildItem - Dir/ls/gci - Get child items (contents of a folder or registry key)",
"Get-Date - Get current date and time",
"Set-Date - Set system time on the host system",
"Remove-Item - Del/erase/rd/rm/rmdir - Delete an item",
"Compare-Object - diff/compare - Compare the properties of objects",
"Do - Loop while a condition is True",
"Get-Event - Get events in the event queueGet-Content - cat/type/gc - Get content from item (specific location)",
"Set-Content - sc - Set content in the item (specific location)",
"Clear-Content - clc - Remove content from a file/item",
"Get-Command - gcm - Get basic information about cmdlets",
"Invoke-Command - icm - Run command",
"Enable-ComputerRestore - Enable System Restore on a drive",
"Disable-ComputerRestore - Disable System Restore on a drive",
"Get-ComputerRestorePoint - Get the restore points on the local computer",
"Test-Connection - Ping one or more computers",
"ConvertFrom-CSV - Convert object properties (in CSV format) into CSV objects",
"ConvertTo-CSV - Convert .NET Framework objects into CSV variable-length strings",
"ConvertTo-Html - Convert the input into an HTML table",
"ConvertTo-Xml - Convert the input into XML",
"ConvertFrom-SecureString - Convert a secure string into an encrypted standard string",
"ConvertTo-SecureString - Convert an encrypted standard string into a secure string",
"Copy-Item - copy/cp/ci - Copy an item from a namespace location",
"Export-Counter - Export Performance Counter data to log files",
"Get-Counter - Get performance counter data",
"Import-Counter - Import performance counter log files",
"Get-Credential - Get a security credential (username/password)",
"Get-Culture - Get region information (language and keyboard layout)",
"Get-ChildItem - Dir/ls/gci - Get child items (contents of a folder or registry key)",
"Get-Date - Get current date and time",
"Set-Date - Set system time on the host system",
"Remove-Item - Del/erase/rd/rm/rmdir - Delete an item",
"Compare-Object - diff/compare - Compare the properties of objects",
"Do - Loop while a condition is True",
"Get-Event - Get events in the event queue",
"Get-WinEvent - Get events from event logs and event trace logs",
"New-Event - Create a new event",
"Remove-Event - Delete events from the event queue",
"Unregister-Event - Cancel an event subscription",
"Wait-Event - Wait until a particular event is raised",
"Clear-EventLog - Delete all entries from an event log",
"Get-Eventlog - Get event log data",
"Limit-EventLog - Limit the size of the event log",
"New-Eventlog - Create a new event log and a new event source",
"Remove-EventLog - Delete an event log",
"Show-EventLog - Display an event log",
"Write-EventLog - Write an event to an event log",
"Get-EventSubscriber - Get event subscribers",
"egister-EngineEvent - Subscribe to powershell events",
"Register-ObjectEvent - Subscribe to .NET events",
"Register-WmiEvent - Subscribe to a WMI event",
"Get-ExecutionPolicy - Get the execution policy for the shell",
"Set-ExecutionPolicy - Change the execution policy (user preference)",
"Export-Alias - epal - Export an alias list to a file",
"Export-Clixml - Produce a clixml representation of powershell objects",
"Export-Console - Export console configuration to a file",
"Export-Csv - epcsv - Export to Comma Separated Values (spreadsheet)",
"Exit - Exit Powershell (or exit a script)",
"ForEach-Object - foreach - Loop for each object in the pipeline ( % )",
"ForEach - Loop through values in the pipeline",
"For - Loop through items that match a condition",
"Format-Custom - fc - Format output using a customized view",
"Format-List - fl - Format output as a list of properties, each on a new line",
"Format-Table - ft - Format output as a table",
"Format-Wide - fw - Format output as a table listing one property only",
"Export-FormatData - Save formatting data from the current session",
"Get-FormatData - Get the formatting data in the current session",
"Get-Item - gi Get a file/registry object (or any other namespace object)",
"Get-ChildItem - dir/ls/gci Get child items (contents of a folder or registry key)",
"Get-Help - help - Open the help file",
"Add-History - Add entries to the session history",
"Clear-History - clhy Delete entries from the session history",
"Get-History - history/h/ghy - Get a listing of the session history",
"Invoke-History - r/ihy - Invoke a previously executed Cmdlet",
"Get-Host - Get host information (PowerShell Version and Region)",
"Clear-Host - clear/cls - Clear the screen",
"Read-Host - Read a line of input from the host console",
"Write-Host - Write customized output to the host/screen",
"Get-HotFix - Get Installed hotfixes",
"if - Conditionally perform a command",
"Import-Clixml - Import a clixml file and rebuild the PS object",
"Import-Csv - ipcsv - Take values from a CSV list and send objects down the pipeline",
"Invoke-Command - Run commands on local and remote computers",
"Invoke-Expression - iex - Run a PowerShell expression",
"Get-Item - gi - Get a file object or get a registry (or other namespace) object",
"Invoke-Item - ii - Invoke an executable or open a file (START)",
"New-Item - ni - Create a new item in a namespace",
"Remove-Item - rm/del/erase/rd/ri/rmdir - Remove an item",
"Set-Item - si - Change the value of an item",
"Clear-ItemProperty - clp - Remove the property value from a property",
"Copy-ItemProperty - cpp - Copy a property along with it's value",
"Get-ItemProperty - gp - Retrieve the properties of an object",
"Move-ItemProperty - mp - Move a property from one location to another",
"New-ItemProperty - Set a new property",
"Remove-ItemProperty - rp - Remove a property and its value",
"Rename-ItemProperty - rnp - Renames a property at its location",
"Set-ItemProperty - sp - Set a property at the specified location to a specified value",
"Get-Job - gjb - Get PowerShell background jobs that are running",
"Receive-Job - rcjb - Get PowerShell background job results",
"Remove-Job - rjb - Delete a PowerShell background job",
"Start-Job - sajb - Start a PowerShell background job",
"Stop-Job - spjb - Stop a PowerShell background job",
"Wait-Job - wjb - Wait for a background job",
"Stop-Process - kill/spps - Stop a running process",
"Update-List - Add and remove items from a collection",
"Get-Location - pwd / gl - Get and display the current location",
"Pop-Location - popd - Set the current working location from the stack",
"Push-Location - pushd - Push a location to the stack",
"Set-Location - cd/chdir/sl - Set the current working location",
"Send-MailMessage - Send an email message",
"Add-Member - Add a member to an instance of a PowerShell object",
"Get-Member - gm - Enumerate the properties of an object",
"Get-Module - gmo - Get the modules imported to the session",
"Import-Module - ipmo - Add a module to the session",
"New-Module - nmo - Create a new dynamic module (only in memory)",
"Remove-Module - rmo - Remove a module from the current session",
"Move-Item - mv/move/mi - Move an item from one location to another",
"Compare-Object - diff/compare - Compare the properties of objects",
"Group-Object - group - Group objects that contain the same value",
"Measure-Object - Measure the properties of an object",
"New-Object - Create a new .Net object",
"Select-Object - select - Select properties of objects",
"Sort-Object - sort - Sort objects by property value",
"Where-Object - Filter the objects passed along the command pipeline",
"Out-Default - Send output to default",
"Out-File - Send output to a file",
"Out-GridView - ogv - Send output to an interactive table",
"Out-Host - oh - Send output to the host",
"Out-Null - Send output to null",
"Out-Printer - lp - Send the output to a printer",
"Out-String - Send objects to the host as strings",
"Convert-Path - cvpa - Convert a ps path to a provider path",
"Join-Path - Combine a path and child-path",
"Resolve-Path - rvpa - Resolves the wildcards in a path",
"Split-Path - Return part of a path",
"Test-Path - Return true if the path exists, otherwise return false",
"Get-Pfxcertificate - Get pfx certificate information",
"Pop-Location - popd - Set the current working location from the stack",
"Push-Location - pushd - Push a location to the stack",
"Get-Process - ps/gps - Get a list of processes on a machine",
"Debug-Process - Attach a debugger to a running process",
"Start-Process - start/saps - Start one or more processes",
"Stop-Process - kill/spps - Stop a running process",
"Wait-Process - Wait for a process to stop",
"Enable-PSBreakpoint - ebp - Enable a breakpoint in the current console",
"Disable-PSBreakpoint - dbp - Disable a breakpoint in the current console",
"Get-PSBreakpoint - gbp - Get the currently set breakpoints",
"Set-PSBreakpoint - sbp - Set a breakpoint on a line, command, or variable",
"Remove-PSBreakpoint - rbp - Delete breakpoints from the current console",
"Get-PSDrive - gdr - Get drive information (DriveInfo)",
"New-PSDrive - mount/ndr - Install a new drive on the machine",
"Remove-PSDrive - rdr - Remove a provider/drive from its location",
"Get-PSProvider - Get information for the specified provider",
"Set-PSdebug - Turn script debugging on or off",
"Enter-PSSession - etsn - Start an interactive session with a remote computer",
"Exit-PSSession - exsn - End an interactive session with a remote computer",
"Export-PSSession - epsn - Import commands and save them in a PowerShell module",
"Get-PSSession - gsn - Get the PSSessions in the current session",
"Import-PSSession - ipsn - Import commands from another session",
"New-PSSession - nsn - Create a persistent connection to a local or remote computer",
"Remove-PSSession - rsn - Close PowerShell sessions",
"Disable-PSSessionConfiguration - Deny access to PS session configuration",
"Enable-PSSessionConfiguration - Enable PS session configuration",
"Get-PSSessionConfiguration - Get the registered PS session configuration",
"Register-PSSessionConfiguration - Create and register a new PS session configuration",
"Set-PSSessionConfiguration - Change properties of a registered session configuration",
"Unregister-PSSessionConfiguration - Delete registered PS session configuration",
"New-PSSessionOption - Advanced options for a PSSession",
"Add-PsSnapIn - asnp - Add snap-ins to the console",
"Get-PsSnapin - gsnp - List PowerShell snap-ins on this computer",
"Remove-PSSnapin - rsnp - Remove PowerShell snap-ins from the console",
"Get-Random - Get a random number",
"Read-Host - Read a line of input from the host console",
"Remove-Item - rm/del/erase/rd/ri/rmdir - Remove an item",
"Rename-Item - ren/rni - Change the name of an existing item",
"Rename-ItemProperty - Rename a property of an item",
"Run/Call - & - Run a command (call operator)",
"Select-Object - select - Select properties of objects",
"Select-XML - Find text in an XML string or document",
"Send-MailMessage - Send an email message",
"Get-Service - gsv - Get a list of services",
"New-Service - Create a new service",
"Restart-Service - Stop and then restart a service",
"Resume-Service - Resume a suspended service",
"Set-Service - Change the start mode/properties of a service",
"Start-Service - sasv - Start a stopped service",
"Stop-Service - spsv - Stop a running service",
"Suspend-Service - Suspend a running service",
"Sort-Object - sort Sort objects by property value",
"Set-StrictMode - Enforce coding rules in expressions & scripts",
"Start-Sleep - sleep - Suspend shell, script, or runspace activity",
"Switch - Multiple if statements",
"ConvertFrom-StringData - Convert a here-string into a hash table",
"Select-String - Search through strings or files for patterns",
"Tee-Object - tee - Send input objects to two places",
"New-Timespan - Create a timespan object",
"Trace-Command - Trace an expression or command",
"Get-Tracesource - Get components that are instrumented for tracing",
"Set-Tracesource - Trace a PowerShell component",
"Start-Transaction - Start a new transaction",
"Complete-Transaction - Commit the transaction",
"Get-Transaction - Get information about the active transaction",
"Use-Transaction - Add a command or expression to the transaction",
"Undo-Transaction - Roll back a transaction",
"Start-Transcript - Start a transcript of a command shell session",
"Stop-Transcript - Stop the transcription process",
"Add-Type - Add a .NET Framework type to a PowerShell session",
"Update-TypeData - Update extended type configuration",
"Get-Uiculture - Get the ui culture information",
"Get-Unique - gu Get the unique items in a collection",
"Update-Formatdata - Update and append format data files",
"Update-Typedata - Update the current extended type configuration",
"Clear-Variable - clv - Remove the value from a variable",
"Get-Variable - gv - Get a powershell variable",
"New-Variable - nv - Create a new variable",
"Remove-Variable - rv - Remove a variable and its value",
"Set-Variable - set/sv - Set a variable and a value",
"New-WebServiceProxy - Create a Web service proxy object",
"Where-Object - where/? - Filter input from the pipeline",
"Where - Filter objects from the pipeline",
"While - Loop while a condition is True",
"Write-Debug - Write a debug message to the host display",
"Write-Error - Write an object to the error pipeline",
"Write-Host - Write customized output to the host/screen",
"Write-Output - write/echo - Write an object to the pipeline",
"Write-Progress - Display a progress bar",
"Write-Verbose - Write a string to the host's verbose display",
"Write-Warning - Write a warning message",
"Set-WmiInstance - Create or update an instance of an existing WMI class",
"Invoke-WmiMethod - iwmi Call WMI methods",
"Get-WmiObject - gwmi Get WMI class information",
"Remove-WmiObject - rwmi Delete an instance of a WMI class",
"Connect-WSMan - Connect to the WinRM service on a remote computer",
"Disconnect-WSMan - Disconnect from the WinRM service on a remote computer",
"Test-WSMan - Test whether the WinRM service is running",
"Invoke-WSManAction - Invoke an action on a specified object",
"Disable-WSManCredSSP - Disable Credential Security Service Provider (SSP) authentication",
"Enable-WSManCredSSP - Enable Credential SSP authentication",
"Get-WSManCredSSP - Get the Credential SSP configuration",
"New-WSManInstance - Create a new instance of a management resource",
"Get-WSManInstance - Display management information (XML or value)",
"Set-WSManInstance - Modify the management information related to a resource",
"Remove-WSManInstance - Delete a management resource instance",
"Set-WSManQuickConfig - Configure the local computer for remote management",
"New-WSManSessionOption - Options for WSMan commands",
"Disable-adAccount Disable an Active Directory account",
"Enable-adAccount Enable an Active Directory account",
"Search-adAccount Get AD user, computer, and service accounts",
"Unlock-adAccount Unlock an AD account",
"Get-adAccountAuthorizationGroup Get the groups in which an account is a direct or indirect member",
"Set-adAccountControl Modify user account control (UAC) values for an AD account",
"Clear-adAccountExpiration Clear the expiration date for an AD account",
"Set-adAccountExpiration Set the expiration date for an AD account",
"Set-adAccountPassword Modify the password of an AD account",
"Get-adAccountResultantPasswordReplicationPolicy Resultant password replication policy for an AD account",
"Get-adComputer Get one or more AD computers",
"New-adComputer Create a new AD computer",
"Remove-adComputer Remove an AD computer",
"Set-adComputer Modify an AD computer",
"Add-adComputerServiceAccount Add one or more service accounts to an AD computer",
"Get-adComputerServiceAccount Get the service accounts that are hosted by an AD computer",
"Remove-adComputerServiceAccount Remove one or more service accounts from a computer",
"Get-adDefaultDomainPasswordPolicy Get the default password policy for an AD domain",
"Set-adDefaultDomainPasswordPolicy Modify the default password policy for an AD domain",
"Move-adDirectoryServer Move a domain controller in AD DS to a new site",
"Move-adDirectoryServerOperationMasterRole Move the operation master (FSMO) roles to an AD domain controller",
"Get-adDomain Get an AD domain",
"Set-adDomain Modify an AD domain",
"Get-adDomainController Get one or more AD domain controllers",
"Add-adDomainControllerPasswordReplicationPolicy - Add users, computers, and groups to the Allowed List or the Denied List of the read-only domain controller",
"Get-adDomainControllerPasswordReplicationPolicy RODC PRP Allowed/Denied List",
"Remove-adDomainControllerPasswordReplicationPolicy RODC PRP Allowed/Denied List",
"Get-adDomainControllerPasswordReplicationPolicyUsage Get the resultant password policy of the specified AD Account on the specified RODC",
"Set-adDomainMode Set the domain functional level for an AD domain",
"Get-adFineGrainedPasswordPolicy Get one or more AD fine-grained password policies",
"New-adFineGrainedPasswordPolicy Create a new AD fine-grained policy",
"Remove-adFineGrainedPasswordPolicy Remove an AD fine-grained password policy",
"Set-adFineGrainedPasswordPolicy Modify an AD fine-grained password policy",
"Add-adFineGrainedPasswordPolicySubject Apply a fine-grained password policy to one more users and groups",
"Get-adFineGrainedPasswordPolicySubject Get the users and groups to which a fine-grained policy is applied",
"Remove-adFineGrainedPasswordPolicySubject Remove one or more users from a fine-grained policy",
"Get-adForest Get an AD forest",
"Set-adForest Modify an AD forest",
"Set-adForestMode Set the forest mode for an AD forest",
"Get-adGroup Get one or more AD groups",
"New-adGroup Create an AD group",
"Remove-adGroup Remove an AD group",
"Set-adGroup Modify an AD group",
"Add-adGroupMember Add one or more members to an AD group",
"Get-adGroupMember Get the members of an AD group",
"Remove-adGroupMember Remove one or more members from an AD group",
"Get-adObject Get one or more AD objects",
"Move-adObject Move an AD object or a container of objects to a different container or domain",
"New-adObject Create an AD object",
"Remove-adObject Remove an AD object",
"Rename-adObject Change the name of an AD object",
"Restore-adObject Restore an AD object",
"Set-adObject Modify an AD object",
"Disable-adOptionalFeature Disable an AD optional feature",
"Enable-adOptionalFeature Enable an AD optional feature",
"Get-adOptionalFeature Get one or more AD optional features",
"Get-adOrganizationalUnit Get one or more AD OUs",
"New-adOrganizationalUnit Create a new AD OU",
"Remove-adOrganizationalUnit Remove an AD OU",
"Set-adOrganizationalUnit Modify an AD OU",
"Add-adPrincipalGroupMembership Add a member to one or more AD groups",
"Get-adPrincipalGroupMembership Get the AD groups that have a specified user, computer, or group",
"Remove-adPrincipalGroupMembership Remove a member from one or more AD groups",
"Get-adRootDSE Get the root of a domain controller information tree",
"Get-adServiceAccount Get one or more AD service accounts",
"Install-adServiceAccount Install an AD service account on a computer",
"New-adServiceAccount Create a new AD service account",
"Remove-adServiceAccount Remove an AD service account",
"Set-adServiceAccount Modify an AD service account",
"Uninstall-adServiceAccount UnInstall an AD service account from a computer",
"Reset-adServiceAccountPassword Reset the service account password for a computer",
"Get-adUser Get one or more AD users",
"New-adUser Create a new AD user",
"Remove-adUser Remove an AD user",
"Set-adUser Modify an AD user",
"Get-adUserResultantPasswordPolicy",
"# - Comment / Remark",
". (source) - Run a command script in the current shell",
"& (call) - Run a command script",
"? - Alias for Where-Object"
)
$sb={ $global:PSConsoleTitle=$global:cmdletdef | get-random }
#invoke the scriptblock
Invoke-Command $sb
New-Timer -identifier "SloganUpdate" -action $sb -refresh $refresh
#start the update timer if not already running
if (-Not (Get-EventSubscriber -SourceIdentifier "TitleTimer" -ea "SilentlyContinue")) {
Start-TitleTimer -refresh $refresh
}
} #function
#=================================================================
#Set a global variable for the console title
$Global:PSConsoleTitle="PowerShell Windows 2.0"
$Global:ConsoleTitleEvents=@()
Export-ModuleMember -Function * -Variable PSConsoleTitle,cmdletdef,ConsoleTitleEvents

Saturday, February 18, 2012

Hard drive report to pretty html file

This script will get a list of computers and output the hard drive information to a pretty html file. You can also just specify the computer(s) on the command line by entering it  like below

'.hard drive report to html.ps1' computer1,computer2,computer3

or use a list of computers jut change file path and name on line 7 to reflect name and path of computer list file using.

Your browser will open with a report that looks similar to below when the script completes.

The file drivereport.htm file will be saved to same location as script.



Download Button5
 #requires -version 2.0  
#use parameter drive report to html.ps1 computer1,computer2 or a computer list file
#change file path and name of list below to reflect name and path of computer list file using.
#script will open web browser with current report when completed.
Param (
$computers = (Get-Content "C:ScriptsComputers.txt")
)
$Title="Hard Drive Report to HTML"
#embed a stylesheet in the html header
$head = @"
<style>
body { background-color:#FFFFCC;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid #000033;
border-collapse:collapse; }
th { color:white;
background-color:#000033; }
table, tr, td, th { padding: 0px; margin: 0px }
table { margin-left:10px; }
</style>
<Title>$Title</Title>
<br>
"@
#define an array for html fragments
$fragments=@()
#get the drive data
$data=Get-WmiObject -Class Win32_logicaldisk -filter "drivetype=3" -computer $computers
#group data by computername
$groups=$Data | Group-Object -Property SystemName
#this is the graph character
[string]$g=[char]9608
#create html fragments for each computer
#iterate through each group object
ForEach ($computer in $groups) {
$fragments+="<H2>$($computer.Name)</H2>"
#define a collection of drives from the group object
$Drives=$computer.group
#create an html fragment
$html=$drives | Select @{Name="Drive";Expression={$_.DeviceID}},
@{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
@{Name="UsedGB";Expression={"{0:N2}" -f (($_.Size - $_.Freespace)/1GB) }},
@{Name="FreeGB";Expression={"{0:N2}" -f ($_.FreeSpace/1GB) }},
@{Name="Usage";Expression={
$UsedPer= (($_.Size - $_.Freespace)/$_.Size)*100
$UsedGraph=$g * ($UsedPer/2)
$FreeGraph=$g* ((100-$UsedPer)/2)
#I'm using place holders for the < and > characters
"xopenFont color=Redxclose{0}xopen/FontxclosexopenFont Color=Greenxclose{1}xopen/fontxclose" -f $usedGraph,$FreeGraph
}} | ConvertTo-Html -Fragment
#replace the tag place holders. It is a hack but it works.
$html=$html -replace "xopen","<"
$html=$html -replace "xclose",">"
#add to fragments
$Fragments+=$html
#insert a return between each computer
$fragments+="<br>"
} #foreach computer
#add a footer
$footer=("<br><I>Report run {0} by {1}{2}<I>" -f (Get-Date -displayhint date),$env:userdomain,$env:username)
$fragments+=$footer
#write the result to a file
ConvertTo-Html -head $head -body $fragments | Out-File drivereport.htm
.drivereport.htm

Friday, January 13, 2012

Installing the Active Directory Module for Windows PowerShell 2.0

With the release of PowerShell 2.0, we now have a PowerShell module that we can use to administer Active Directory. The Active Directory Module for Windows PowerShell runs on Windows Server 2008 R2 and on Windows 7 and relies on a web service that is hosted on one or more domain controllers in your environment. In this post I'll go over what you need in order to install and use the Active Directory Module for PowerShell, also known as AD PowerShell.
 

Setting up your Domain Controllers

In order to use the Active Directory Module for Windows PowerShell on 2008 R2 and Windows 7, you first need to be running Active Directory Web Services (ADWS) on at least one Domain Controller. To install Active Directory Web Services (ADWS) you'll need one of the following:

1. Windows Server 2008 R2 AD DS

You can load Active Directory Web Services (ADWS) on a Windows Server 2008 R2 Domain Controller when you install the AD DS role. The AD PowerShell module will also be installed during this process. Active Directory Web Services (ADWS) will be enabled when you promote the server to a DC using DCPromo.

2. Active Directory Management Gateway Service

If you cannot run Windows Server 2008 R2 Domain Controllers, you can install the Active Directory Management Gateway Service. Installing this will allow you to run the same Active Directory web service that runs on Windows Server 2008 R2 DC's. You can download the Active Directory Management Gateway Service here. Make sure you read the instructions carefully, there are several hotfixes that need to be applied depending on the version of Windows you are running. You can install the Active Directory Management Gateway Service on DC's running the following operating systems:
  • Windows Server 2003 R2 with Service Pack 2
  • Windows Server 2003 SP2
  • Windows Server 2008
  • Windows Server 2008 SP2
Note: You can also use AD PowerShell to manage AD LDS instances on Windows Server 2008 R2. If you plan on using AD LDS, Active Directory web services will be installed with the AD LDS role, the AD PowerShell module will also be installed during this process. The ADWS service will be enabled when your LDS instance is created.

Once you've got Active Directory web services up and running on your Domain Controller(s), you'll notice you now have an ADWS service as shown here:



At this point, you should be ready to install the AD PowerShell module. You can run AD PowerShell on all versions of Windows Server 2008 R2 (except the Web Edition) and on Windows 7.

Installing the Active Directory Module for Windows PowerShell on 2008 R2 member servers

You can install the Active Directory Module on Windows 2008 R2 member servers by adding the RSAT-AD-PowerShell feature using the Server Manager. I usually use the ServerManager module to do this because it is quick and easy. To install the feature using the ServerManager module, launch PowerShell and run the following commands:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell



Remember, this only needs to be done on Windows Server 2008 R2 member servers. The RSAT-AD-PowerShell feature will be added to 2008 R2 DC's during the DCPromo process.

Installing the Remote Server Administration Tools (RSAT) feature on Windows 7

In order to install the Active Directory Module for Windows PowerShell you need to download the RSAT tools for Windows 7 here. Once this is installed you are still not finished, you need to enable the Active Directory module. Navigate to Control Panel > Programs and Features > Turn Windows Features On or Off and select Active Directory Module for Windows PowerShell as show here:



Once you have Active Directory web services running on at least one domain controller and the AD PowerShell module is installed, you are ready to run the AD PowerShell module. You can do this in one of two ways. First, you can access the "Active Directory Module for Windows PowerShell" shortcut in Administrative Tools as shown here:



Right click the shortcut and select "Run as administrator" in order to start PowerShell with elevated permissions.

You can also simply import the AD PowerShell module in your existing PowerShell session. Just use the Import-Module ActiveDirectory command:

Import-Module ActiveDirectory



That's all that needs to be done to get up and running.

 
Below is a list of the new AD cmdlets that will be available and a synopsis of what they do.

NameCategorySynopsis
Add-ADComputerServiceAccountCmdletAdds one or more service accounts to an Active Directory computer.
Add-ADDomainControllerPasswordReplicationPolicyCmdletAdds users, computers, and groups to the allowed or denied list of a read-only domain controller password replication policy.
Add-ADFineGrainedPasswordPolicySubjectCmdletApplies a fine-grained password policy to one more users and groups.
Add-ADGroupMemberCmdletAdds one or more members to an Active Directory group.
Add-ADPrincipalGroupMembershipCmdletAdds a member to one or more Active Directory groups.
Clear-ADAccountExpirationCmdletClears the expiration date for an Active Directory account.
Disable-ADAccountCmdletDisables an Active Directory account.
Disable-ADOptionalFeatureCmdletDisables an Active Directory optional feature.
Enable-ADAccountCmdletEnables an Active Directory account.
Enable-ADOptionalFeatureCmdletEnables an Active Directory optional feature.
Get-ADAccountAuthorizationGroupCmdletGets the accounts token group information.
Get-ADAccountResultantPasswordReplicationPolicyCmdletGets the resultant password replication policy for an Active Directory account.
Get-ADComputerCmdletGets one or more Active Directory computers.
Get-ADComputerServiceAccountCmdletGets the service accounts hosted by a computer.
Get-ADDefaultDomainPasswordPolicyCmdletGets the default password policy for an Active Directory domain.
Get-ADDomainCmdletGets an Active Directory domain.
Get-ADDomainControllerCmdletGets one or more Active Directory domain controllers based on discoverable services criteria, search parameters or by providing a domain controller identifier, such as the NetBIOS name.
Get-ADDomainControllerPasswordReplicationPolicyCmdletGets the members of the allowed list or denied list of a read-only domain controller's password replication policy.
Get-ADDomainControllerPasswordReplicationPolicyUsageCmdletGets the Active Directory accounts that are authenticated by a read-only domain controller or that are in the revealed list of the domain controller.
Get-ADFineGrainedPasswordPolicyCmdletGets one or more Active Directory fine grained password policies.
Get-ADFineGrainedPasswordPolicySubjectCmdletGets the users and groups to which a fine grained password policy is applied.
Get-ADForestCmdletGets an Active Directory forest.
Get-ADGroupCmdletGets one or more Active Directory groups.
Get-ADGroupMemberCmdletGets the members of an Active Directory group.
Get-ADObjectCmdletGets one or more Active Directory objects.
Get-ADOptionalFeatureCmdletGets one or more Active Directory optional features.
Get-ADOrganizationalUnitCmdletGets one or more Active Directory organizational units.
Get-ADPrincipalGroupMembershipCmdletGets the Active Directory groups that have a specified user, computer, group, or service account.
Get-ADRootDSECmdletGets the root of a Directory Server information tree.
Get-ADServiceAccountCmdletGets one or more Active Directory service accounts.
Get-ADUserCmdletGets one or more Active Directory users.
Get-ADUserResultantPasswordPolicyCmdletGets the resultant password policy for a user.
Install-ADServiceAccountCmdletInstalls an Active Directory service account on a computer.
Move-ADDirectoryServerCmdletMoves a directory server in Active Directory to a new site.
Move-ADDirectoryServerOperationMasterRoleCmdletMoves operation master roles to an Active Directory directory server.
Move-ADObjectCmdletMoves an Active Directory object or a container of objects to a different container or domain.
New-ADComputerCmdletCreates a new Active Directory computer.
New-ADFineGrainedPasswordPolicyCmdletCreates a new Active Directory fine grained password policy.
New-ADGroupCmdletCreates an Active Directory group.
New-ADObjectCmdletCreates an Active Directory object.
New-ADOrganizationalUnitCmdletCreates a new Active Directory organizational unit.
New-ADServiceAccountCmdletCreates a new Active Directory service account.
New-ADUserCmdletCreates a new Active Directory user.
Remove-ADComputerCmdletRemoves an Active Directory computer.
Remove-ADComputerServiceAccountCmdletRemoves one or more service accounts from a computer.
Remove-ADDomainControllerPasswordReplicationPolicyCmdletRemoves users, computers and groups from the allowed or denied list of a read-only domain controller password replication policy.
Remove-ADFineGrainedPasswordPolicyCmdletRemoves an Active Directory fine grained password policy.
Remove-ADFineGrainedPasswordPolicySubjectCmdletRemoves one or more users from a fine grained password policy.
Remove-ADGroupCmdletRemoves an Active Directory group.
Remove-ADGroupMemberCmdletRemoves one or more members from an Active Directory group.
Remove-ADObjectCmdletRemoves an Active Directory object.
Remove-ADOrganizationalUnitCmdletRemoves an Active Directory organizational unit.
Remove-ADPrincipalGroupMembershipCmdletRemoves a member from one or more Active Directory groups.
Remove-ADServiceAccountCmdletRemove an Active Directory service account.
Remove-ADUserCmdletRemoves an Active Directory user.
Rename-ADObjectCmdletChanges the name of an Active Directory object.
Reset-ADServiceAccountPasswordCmdletResets the service account password for a computer.
Restore-ADObjectCmdletRestores an Active Directory object.
Search-ADAccountCmdletGets Active Directory user, computer, or service accounts.
Set-ADAccountControlCmdletModifies user account control (UAC) values for an Active Directory account.
Set-ADAccountExpirationCmdletSets the expiration date for an Active Directory account.
Set-ADAccountPasswordCmdletModifies the password of an Active Directory account.
Set-ADComputerCmdletModifies an Active Directory computer object.
Set-ADDefaultDomainPasswordPolicyCmdletModifies the default password policy for an Active Directory domain.
Set-ADDomainCmdletModifies an Active Directory domain.
Set-ADDomainModeCmdletSets the domain mode for an Active Directory domain.
Set-ADFineGrainedPasswordPolicyCmdletModifies an Active Directory fine grained password policy.
Set-ADForestCmdletModifies an Active Directory forest.
Set-ADForestModeCmdletSets the forest mode for an Active Directory forest.
Set-ADGroupCmdletModifies an Active Directory group.
Set-ADObjectCmdletModifies an Active Directory object.
Set-ADOrganizationalUnitCmdletModifies an Active Directory organizational unit.
Set-ADServiceAccountCmdletModifies an Active Directory service account.
Set-ADUserCmdletModifies an Active Directory user.
Uninstall-ADServiceAccountCmdletUninstalls an Active Directory service account from a computer.

 

Thursday, January 12, 2012

Installation and Configuration of the Windows Server 2008 SMTP Server Feature

Installing the SMTP Server Feature on Windows 2008 is an easy process requiring only few steps to complete. In this article I will describe the step by step configuration and installation of the SMTP Server feature and how to enable the smtp to relay from the local server.


Step 1:
Opening Server Manager Console and under Features select Add Features


Step 2:
Selecting SMTP Server option


Step 3:
Click on Install wait until finish and click close


Step 4:
Waiting for installation to finish and clicking on Close


Step 5:
Opening IIS 6.0 Manager under Administrative Tools -> Internet Information Services 6.0


Step 6:
Under [SMTP Virtual Server] second mouse click and properties


Step 7:
Select Relay under Access Tab


Step 8:
Select Only the list below and click on Add button


Step 9:
Enter IP Address 127.0.0.1 for relay


Step 10:
Sending a manual email through telnet to confirm everything working successfully.Telnet localhost 25 or telnet your public ip 25 and make sure you open the specific port on your firewall to be available to public.
To end message hit ENTER then a period then hit ENTER again
You will need to in an administrative command prompt and type “Telnet localhost 25 or telnet ‘outside IP’ 25″.  If you get the message “‘telnet’ is not recognized as an internal or external command,” then you need to install telnet. see here http://technet.microsoft.com/en-us/library/cc771275(v=WS.10).aspx