Apr 09

How to: Find the HP Product Number of all your HP server using powershell

You can easly find the HP product number of any of your HP server by looking on the server itself or on the warranty card.
The HP product number is nice to have if you want to easily find that date your HP server will be out of warranty.

This product number is no longer mandatory if you are using this Warranty check tool, but in some case you will still need it.
 

If your HP server was built using HP SmartStart the product number could be found in the windows registry:
HKLM\HARDWARE\DESCRIPTION\System\BIOS\SystemSKU
 

Here is how to use powershell to read this information:

#Read HP product number from registry
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "NameOfServer")
$regkey = $reg.OpenSubkey("HARDWARE\\DESCRIPTION\\System\\BIOS")
$SystemSku = $regkey.GetValue("SystemSku")

Read the rest of this entry »

Apr 02

Powershell Tips of the week #4 – Get-ChildItem – Only show directories

Here’s quick tip on how to make Get-ChildItem only return directories.

With Powershell v3, there is a new parameter that allow you to only get directories:

Get-ChildItem C:\ -directory


Result:
Directory: C:\
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         7/13/2009  11:20 PM            PerfLogs
d-r--          4/2/2013   8:31 AM            Program Files
d-r--         3/27/2013   9:03 AM            Program Files (x86)
d-r--         1/17/2013   2:17 PM            Users
d----         3/27/2013   9:01 AM            Windows

 
 
Since the parameter “-directory” does not exist in Powershell v2 you will need to use the attribute “PSIsContainer” to filer the directories:

Get-ChildItem c:\ | Where-Object{$_.PSIsContainer -eq $true}


Result:
Directory: C:\
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         7/13/2009  11:20 PM            PerfLogs
d-r--          4/2/2013   8:31 AM            Program Files
d-r--         3/27/2013   9:03 AM            Program Files (x86)
d-r--         1/17/2013   2:17 PM            Users
d----         3/27/2013   9:01 AM            Windows

Mar 25

Powershell Tips of the week #3 – Find parent folder

How to find the parent folder of a path that is stored in a variable

For the purpose of the example I will manually add a path to a variable.

$VarA = "\\Domain.net\dfs\files\dan.fortier\"

The parent folder of this path is “\\Domain.net\dfs\files” but lets find it with powershell using the Get-Item cmdlet.

$ParentFolder = (Get-Item $VarA).parent.FullName
Write-host $ParentFolder

Result:
\\Domain.net\dfs\files

If you want to get to one level higher, add another .parent:

$ParentFolder = (Get-Item $VarA).parent.parent.FullName
Write-host $ParentFolder

Result:
\\Domain.net\dfs\

Note that the path need to be valid, otherwise you will get an error.

Mar 19

Powershell Tips of the week #2 – Measure-Command

In today’s post I will talk about the Measure-Command function in Powershell. This function will tell you exactly how much time it took to run a cmdlet or a script block. The result will be displayed like this:

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 140
Ticks             : 11409189
TotalDays         : 1.32050798611111E-05
TotalHours        : 0.000316921916666667
TotalMinutes      : 0.019015315
TotalSeconds      : 1.1409189
TotalMilliseconds : 1140.9189

Like you see it is very detailed and precise (Milliseconds). Now let’s look how to use Measure-Command.

Measure-Command is really easy to use. Simply add your cmdlet or script block between brackets after Measure-Command:

Measure-Command {get-childitem c:\windows}

Result:
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 8
Milliseconds      : 618
Ticks             : 86182763
TotalDays         : 9.9748568287037E-05
TotalHours        : 0.00239396563888889
TotalMinutes      : 0.143637938333333
TotalSeconds      : 8.6182763
TotalMilliseconds : 8618.2763

Example with Script Block:

Measure-Command{
    $VarA = Get-ChildItem C:\ -Recurse

    foreach($VarB in $VarA){
        Write-Host $VarB.Name  
    }
}


Result:
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 140
Ticks             : 11409189
TotalDays         : 1.32050798611111E-05
TotalHours        : 0.000316921916666667
TotalMinutes      : 0.019015315
TotalSeconds      : 1.1409189
TotalMilliseconds : 1140.9189

Mar 14

Powershell Tips of the week #1 – Cmdlet Start-Transcript

This week I will show you how to use the Start-Transcript cmdlet. Start-Transcript will allow you to record your powershell session in a text file. The transcript includes all command that the user types and all output that appears on the console.

Here is some example on how to use Start-Transcript:

This command starts a transcript in the default file location.

Start-Transcript

This command starts a transcript in C:\Transcript.txt

Start-Transcript -path "C:\Transcript.txt"

This command starts a transcript in C:\Transcript.txt only if the file doesn’t exist (will not overwrite)

Start-Transcript -path "C:\Transcript.txt" -NoClobber

Other available options:

-Append: Adds the new transcript to the end of an existing file. Use the Path parameter to specify the file.

-Force: Allows the cmdlet to append the transcript to an existing read-only file. When used on a read-only file, the cmdlet changes the file permission to read-write. Even using the Force parameter, the cmdlet cannot override security restrictions.

-Confirm: Prompts you for confirmation before executing the command.

EDIT: I forgot to mention that you could stop the transcript anytime with Stop-Transcript

Feb 14

How to: cleanup the winsxs folder after SP1 installation on Windows 2008 R2

After the installation on SP1 on Windows 2008 R2 I have notice that lots of my server were getting low disk space. I scanned the C: drive with TreeSize Pro and I found out that the Winsxs folder was really big (between 9 and 16 Gb). There is a command that you can use to cleanup after the SP1 install.

WARNING: Once you run this command you will NOT be able to uninstall SP1.

To cleanup after the installation of SP1 follow these steps:
-Open an elevated command prompt (Right click “Command Prompt” and select “Run as administrator”
-Run this command (It does not require a reboot):

DISM.exe /online /Cleanup-Image /spsuperseded /hidesp

-The operation should take about 10 to 15 minutes. Once completed you will see: “The operation completed successfully”

/Online: Targets the running operating system.
/Cleanup-Image: Performs cleanup and recovery operations on the image
/spsuperseded: Remove SP backup and unused files
/hidesp: Optional – Hide the service pack from Installed updates

I have use this command on multiple servers without any issue. I was able to save between 2 and 6 Gb. Most of my server are virtual servers running on VMware and created using the same template. For some reason the amount of space that was clean was still different for each servers.

Use this command at your own risk, you should also backup or snapshot your server before running this.

Comment this article to let me know how much space you got back after running the cleanup.

Jan 16

Windows profile username.001, username.002, username.003 … in RD (TS) or Citrix

Issue:
When using Remote Desktop, Terminal Services or Citrix XenApp on a Vmware server, windows might now be able to delete the copy of the profile. At the next logon another profile will be created to finally end up with multiple folders for the same users (ie: username.001, username.002, username.003 …)

If you look in the event viewer (Applications) you will see multiple Event 1533:

Event 1533

Windows cannot delete the profile directory C:\Users\test.danf.domain.dom This error may be caused by files in this directory being used by another program.

DETAIL – The directory is not empty.

Cause:
The VMWare Share Folders option was installed as part of VMWare Tools. VMWare Shared Folders allows files to be shared between the virtual machine and the HOST computer (ESX or ESXi). This feature is not support on ESX and GSX servers, but is supported on VMWare Workstation. It could still be install on virtual servers running on those host.

Read the rest of this entry »

Older posts «