header image

Archive for February, 2014

do and while

Posted by: | February 28, 2014 | No Comment |

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

under: PowerShell Basics

In this post  http://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. This isn’t a simple exercise – you will need a script to: You can create […]

under: Active Directory, File System

File or Folder?

Posted by: | February 28, 2014 | No Comment |

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 -Path c:\temp   | where {-not $_.PSIsContainer} If you want to see the subfolders only then […]

under: PowerShell Basics

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 PowerShell 4.0 When the CIM cmdlets were introduced in PowerShell 3.0 people assumed […]

under: PowerShell and CIM, PowerShell and WMI, PowerShell Basics, PowerShell V3, PowerShell v4

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 get or have got an email with the link. The printed version is at the […]

under: Active Directory, Books, PowerShell and Active Directory

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 Team members – Don Jones – Jason Helmick – Jeff Hicks – Ed Wilson (The […]

under: PowerShell original, PowerShell Summit

Useful storage cmdlets

Posted by: | February 26, 2014 | No Comment |

Scanning through the Storage module there is a bunch of useful cmdlets – starting with the Get* cmdlets: Get-Command -Module Storage get* Get-Disk Get-DiskImage Get-FileIntegrity Get-FileStorageTier Get-InitiatorId Get-InitiatorPort Get-MaskingSet Get-OffloadDataTransferSetting Get-Partition Get-PartitionSupportedSize Get-PhysicalDisk Get-ResiliencySetting Get-StorageJob Get-StorageNode Get-StoragePool Get-StorageProvider Get-StorageReliabilityCounter Get-StorageSetting Get-StorageSubSystem Get-StorageTier Get-StorageTierSupportedSize Get-SupportedClusterSizes Get-SupportedFileSystems Get-TargetPort Get-TargetPortal Get-VirtualDisk Get-VirtualDiskSupportedSize Get-Volume Get-VolumeCorruptionCount Get-VolumeScrubPolicy £> Get-PhysicalDisk | […]

under: PowerShell v4

Delete all but the last N

Posted by: | February 26, 2014 | No Comment |

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 split it across multiple lines for ease of reading. Get-ChildItem -Path c:\temp -Filter *.tmp -File […]

under: PowerShell Basics

Requires

Posted by: | February 25, 2014 | No Comment |

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 the loading of a snapin   #Requires –Modules     can be used to force […]

under: PowerShell Basics

Waiting for restart

Posted by: | February 25, 2014 | No Comment |

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 add the –Wait parameter: Restart-Computer -ComputerName server03 You final options when pausing are to wait […]

under: PowerShell Basics

Older Posts »

Categories