PowerShell: Creating large dummy files with .NET

Ok, this one’s is cool i think. Whenever i needed a large dummy file, i opened up notepad, write ASDFASDFASDFA CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V. CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V,CTRL-V.. Then i saved the file, opened up a CMD-Shell and wrote copy dummyFile.txt+dummyFile.txt+dummyFile.txt until the file was large enough.. ok, there’s fsutil.exe which does the same in a much more efficient manner.. OR, unleash the Power of .NET – no, you don’t have to start programming using Visual Studio, just open up PowerShell.. Logo_PowerShell

Continue reading

PowerShell: Running PowerShell Scripts as Scheduled Task

Schtasks.exe – Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task.

If you have jobs that need to execute regularly, you can manage them with a PowerShell script and make it a scheduled task:

Logo_PowerShell

Continue reading

PowerShell: Delete specific files recursively / recursive

Okay, this post I’m going to write down for my personal notes but also for you..
Ever needed to delete a specific file, in my case in need to delete (remove-item) all *.pdb files in one of my Visual Studio Solution.. recursive of course.
To get a list of Files use the Get-ChildItem CmdLet. Extend that command using the –rec or –recurse parameter – so you’ll get all the files recursively, starting from the current path / directory.
Logo_PowerShell

Continue reading

Accessing Individual WMI Instances

Did you know, accessing individual WMI Instances and their Namespaces is pretty easy as 1-2-3..


You always get back all instances of a given WMI class when using Get-WMIObject. However, what if you just wanted to get a specific instance? Or you just wanted to find out how much space is left on drive C:? The next line gives you all drives:

Logo_PowerShell

Continue reading

Powershell – Download File from the Internet using Net.WebClient Object

Powershell – Download File from the Internet using Net.WebClient Object

You can tap into the wealth of .NET methods easily. Use New-Object to instantiate a new .NET class, and off you go.
For example, instantiate an instance of Net.WebClient and you can enable your PowerShell scripts to download files from the Internet:

$object = New-Object Net.WebClient
$url = 'http://download.microsoft.com/download/4/7/1/47104ec6-410d-4492-890b-2a34900c9df2/Workshops-EN.zip'
$local = "$home\powershellworkshop.zip"
$object.DownloadFile($url, $local)

This will download a great PowerShell workshop from Microsoft to your home folder. Unfortunately, the simple DownloadFile() method does not provide a progress indicator so depending on your Internet connection, it may take a couple of minutes until the command is processed.

Servermanagercmd.exe is deprecated, and is not guaranteed to be supported in future releases of Windows.

Command Line version of Server Manager in Windows Server 2008 R2
Today I was using “ServerManagerCmd.exe” on a Microsoft Windows Server 2008 R2. When I executed it I saw the following informational message:

“Servermanagercmd.exe is deprecated, and is not guaranteed to be supported in future releases of Windows. We recommend that you use the Windows PowerShell cmdlets that are available for Server Manager.”
Continue reading