Category Archives: PowerShell
PowerShell: Enabling PowerShell v2 Remotely
Accessing Individual WMI Instances
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.
Overview: Which PowerShell Snap-Ins and Modules are available for use
Which PowerShell Snap-Ins and Modules are available for use?
This is the way to determine which PowerShell Snap-Ins and Modules are available in Windows Server 2008 R2…
PS C:\> Get-PSSnapin
Continue reading
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
PowerShell: Get SID from AD (Active Directory) User / Group using PowerShell
To get the SID of an AD Object (User, Group, whatever) quickly, i recommend using PowerShell.
When trying to get the SID using ADUC (Active Directory User and Computer Snap-in), you can not copy/paste the SID as a string since it is stored in a binary format.
Manage you Hyper-V Virtual Machines using Microsoft PowerShell Management Library for Hyper-V
Absolutely cool and awesome, a Management Library for PowerShell to manage your Hyper-V Virtual Machines and Hosts using Microsoft PowerShell.
Get it / read more here: PowerShell Management Library for Hyper-V
It is published on Codeplex
Powershell: How to find (large) files
Using Microsoft Powershell to find large files on a specific drive recursively is very easy.
Start PowerShell as Admin (run as administrator)
To search for files larger than 100MB on Drive C type:
Get-ChildItem c:\ -Recurse | Where-Object {$_.Length -gt 100MB}
This command can also be entered abbreviated
gci c:\ -rec | where {$_.Length -gt 100mb}
PowerShell: Enumerate Files recursive and get full path for each file
To enumerate all files of a specific path recursive and get the full path for each file using Microsoft PowerShell:
Get-ChildItem -rec | ForEach-Object -Process {$_.FullName}
to capture the output and generate an XML file do:
Get-ChildItem -rec | ForEach-Object -Process {$_.FullName} | Export-Clixml c:\temp\report.xml
to only enumerate / list files, use the psIsContainer switch:
Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true} | ForEach-Object -Process {$_.FullName}
or for folders only:
Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $false} | ForEach-Object -Process {$_.FullName}