Monthly Archives: February 2014

do and while

Do you understand the difference between do loops and while loops?  On the surface they appear very similar. £> do{$i++}while($i -lt 10)£> $i10 £> $i=0£> while($i -lt 10){$i++}£> $i10 BUT there is a difference £> $i=11£> do{$i++}while($i -lt 10)£> $i12 … Continue reading

Posted in Powershell Basics | Leave a comment

Automatically create folder for home drive

In this post  https://richardspowershellblog.wordpress.com/2013/10/28/setting-ad-attributes-from-a-csv-file/ I showed how to modify the user’s home folder setting in Active Directory. A comment was recently left asking about automatically creating the folder on the fileserver and creating the share that is associated with it. … Continue reading

Posted in Active Directory, File system | Leave a comment

File or Folder?

This is a common type of use for Get-ChildItem: Get-ChildItem -Path c:\temp  However, you could get files or folders returned.  Very often you just want to see the files In PowerShell 1.0 & 2.0 you had to do this: Get-ChildItem … Continue reading

Posted in Powershell Basics | Leave a comment

I’m afraid you can’t do that anymore

In PowerShell 1.0 you could do this: notepad$proc = Get-WmiObject -Class Win32_Process -Filter “Name=’notepad.exe’”$proc.Terminate() To access the methods of the WMI class you had to get a variable representing the instance and call the method. This technique still works in … Continue reading

Posted in CIM, PowerShell and WMI, Powershell Basics, PowerShell V3, PowerShell v4 | Leave a comment

Learn AD Management in a Month of Lunches–ebook available

The ebook – PDF format – for Learn AD Management in a Month of Lunches has been published – http://www.manning.com/siddaway3/ If you bought the ebook as part of your MEAP you should be able to down load it – you’ll … Continue reading

Posted in Active Directory, Books, PowerShell and Active Directory | Leave a comment

PowerShell Summit NA 2014

The PowerShell Summit is happening in Bellevue (Seattle) – April 28 – 30th.  You will be able to hear, meet and talk to some of the biggest names in PowerShell: – Jeffrey Snover – the inventor of PowerShell – PowerShell … Continue reading

Posted in Powershell, Summit | 1 Comment

Useful storage cmdlets

Scanning through the Storage module there is a bunch of useful cmdlets – starting with the Get* cmdlets: Get-Command -Module Storage get* Get-DiskGet-DiskImageGet-FileIntegrityGet-FileStorageTierGet-InitiatorIdGet-InitiatorPortGet-MaskingSetGet-OffloadDataTransferSettingGet-PartitionGet-PartitionSupportedSizeGet-PhysicalDiskGet-ResiliencySettingGet-StorageJobGet-StorageNodeGet-StoragePoolGet-StorageProviderGet-StorageReliabilityCounterGet-StorageSettingGet-StorageSubSystemGet-StorageTierGet-StorageTierSupportedSizeGet-SupportedClusterSizesGet-SupportedFileSystemsGet-TargetPortGet-TargetPortalGet-VirtualDiskGet-VirtualDiskSupportedSizeGet-VolumeGet-VolumeCorruptionCountGet-VolumeScrubPolicy £> Get-PhysicalDisk | Format-List FriendlyName, CanPool, OperationalStatus, HealthStatus, Usage, Size FriendlyName      : PhysicalDisk0CanPool           : FalseOperationalStatus : OKHealthStatus      … Continue reading

Posted in PowerShell v4 | Leave a comment

Delete all but the last N

I was asked a question about deleting files from a folder based on age.  The requirement was to delete all but the youngest N files. One solution is a classic PowerShell one-liner. It is actually one PowerShell pipeline though I’ve … Continue reading

Posted in Powershell Basics | Leave a comment

Requires

You may have seen this at the top of scripts or modules #Requires –Version 3 This will stop the script running if the PowerShell version is 2.0 or below. Other options are available #Requires –PSSnapin      can be used to force … Continue reading

Posted in Powershell Basics | Leave a comment

Waiting for restart

Some times you need to reboot a remote machine as part of your process.  PowerShell provides the Restart-Computer cmdlet to perform that task: Restart-Computer -ComputerName server03 If you want you process to pause until the reboot has finished then you … Continue reading

Posted in Powershell Basics | Leave a comment