Bart's Weblog

Just a blog…

Archive for the ‘PowerShell’ Category

PowerShell: Return wandering VMs to their preferred ESX host

Posted by bartvdw on 0303/0909/2011

For the people that want to place VMs at specific ESX hosts, the scripts in the link below will make your life easy!

Return wandering VMs to their preferred ESX host

Posted in PowerShell, VMware | Leave a Comment »

PowerShell: Outlook unified signature based on Active Directory information

Posted by bartvdw on 0303/0909/2011

I came across this nice PowerShell solution to have unified Outlook signature based on Active Directory information in your company. Check it out!

Outlook signature based on user information from Active Directory

Deploying a Unified Email Signature Template in Outlook

Microsoft TechNet Script Center link: Outlook signature based on user information from Active Directory

Posted in Active Directory, Outlook, PowerShell | Leave a Comment »

PowerShell: Protect all OU’s in Active Directory from accidental deletion

Posted by bartvdw on 1313/0808/2011

1) Check which OUs aren’t protected:
Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false} | ft

2) Protect them:
Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false} | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true

3) Then rerun the first command to verify they have been changed.

These commands should run with "Active Directory Module for Windows PowerShell" for AD only or "PowerShell Modules" to load all of them.

 

AD DS: All OUs in this domain should be protected from accidental deletion
http://technet.microsoft.com/en-us/library/dd723677%28WS.10%29.aspx

Posted in Active Directory, PowerShell | 4 Comments »

PowerShell: How to retrieve disk size & free disk space for a list of computers (input file)

Posted by bartvdw on 1919/0606/2008

Note: works only with V2 which is currently in CTP stage!

The command below will show you a very nice overview of disk size & free space for a list of computers (input file). The great thing about PowerShell, from my point of view, is “piping” commands into 1 big command which eliminates the need to create a script for certain operations. Secondly in V2 (CTP), the “gridview” option is amazing!

Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -computer (Get-Content c:\scripts\computers.txt) | Select SystemName,DeviceID,VolumeName,@{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}},@{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}} | Out-GridView

Posted in PowerShell, Scripting | 29 Comments »

PowerShell: ExecutionPolicy

Posted by bartvdw on 2222/0404/2008

I know I waited far too long to start working with PowerShell. But OK, here we are. And immediately encountered something. By default it sets some security related to running scripts. Only when I did what it said, I was unable to change that security!

OK in short, after you install PowerShell, it sets the “ExecutionPolicy” for scripts to “Restricted”, which means you’re not allowed to execute scripts. Not very interesting… So I used the “Set-ExecutionPolicy RemoteSigned” command to change, but this returned an error:
Set-ExecutionPolicy : Access to the registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell’ is denied.
At line:1 char:20
+ Set-ExecutionPolicy  <<<< RemoteSigned

  • Open registry
  • Browse to key HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
  • If “ExecutionPolicy” does not exist, create it as REG_SZ with value “RemoteSigned”
  • Open PowerShell and use the command “Get-ExecutionPolicy” to see it is done correctly

It’s only obvious that if another security level is desired, you adapt the value… :-)

Posted in PowerShell, Scripting | 9 Comments »

 
Follow

Get every new post delivered to your Inbox.