Showing posts from June, 2011

Poweshell File and Folder Size Function

Have you ever wanted to know the size of a folder using Powershell? Of course! Sure, you can get the size of a file using the length property but what about folders? This is a function that uses .NET objects to calculate the size of a folder. You can use it for files too. function Get-Size{ param( $path ) if( test-path $path -pathtype container ) { $size = _get-dirsize $path } else { $size = get-item $path $size = $size.length } get-item $path | select-object Name, @{name="Size (MB)";expression={[Math]::Round( ($size / 1MB), 2 )}}, fullname, @{name="Size";expression={$size}} | format-table } function _Get-DirSize{ param( $folder ) $folder = resolve-path $folder $d = New-Object system.IO.DirectoryInfo $folder [long] $Size = 0; # Add file sizes. $fis = $d.GetFiles(); foreach ($fi in $fis){ $size += $fi.Length; } # Add subdirectory sizes

WSUS 3 Update Removal

In case your update server takes too much space on your hard disk, you can follow these steps to remove "old" updates. You might also like to try "Server CleanUp" first... So, Unapprove all updates from the Update Console. Stop "World Wide Web Publishing Service" service and all of it's dependents Stop "Update Service" and "Windows Update" services Delete all contents from the "WSUS Content" folder Start the above services Start a command line window and change to "c:\program files\update services\tools" Run wsusutil.exe reset The 'reset' command tells wsus to check all of it downloads and redownload any missing or corrupt files. Since you deleted them all it will download only the updates that have been approved.

Call a function from file in Windows Powershell

In order to call a function from a powershell file we have to use a method called dot-sourcing. Let's say we have file called a.ps1 and it's contents are: function f {     echo "Hi!!!" } And now we want to call that function from powershell. We have to load that file (think of a library): . .\a.ps1 (that's dot, space, path-to-file) and then we can call the function itself. This can be very usefull if you have many functions in your profile file and you don't want it to get very big.

Previewing ‘Windows 8’

The first preview of Microsoft's new Operating System, internaly codenamed " Windows 8 " by Julie Larson-Green, Corporate Vice President, Windows Experience.