Archive

Posts Tagged ‘PowerShell’

Increase VMBus buffer sizes to increase network throughput to guest VMs – PowerShell Edition

September 23rd, 2010 No comments

In this article the title is explained. It also explains how to set it manually on all VM’s that you have. As lazy admin as I am I created a PowerShell script that can be ran manually when configuring/installing a VM or you can set is as shutdown script so every time a VM shuts down it is checked if a new “Microsoft Virtual Machine Bus Network Adapter” has been added to the VM.

RSBufferSize.ps1
if (Get-ItemProperty -Name “ReceiveBufferSize” -path “hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\*” -erroraction silentlycontinue | where {$_.DriverDesc -eq “Microsoft Virtual Machine Bus Network Adapter”}) {“Registry key ReceiveBufferSize already exists”} else {Get-ItemProperty -Name “DriverDesc” -path “hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\*” -erroraction silentlycontinue | where {$_.DriverDesc -eq “Microsoft Virtual Machine Bus Network Adapter”} | new-itemproperty -name ReceiveBufferSize -value 2048 -propertyType dword -erroraction silentlycontinue}if (Get-ItemProperty -Name “SendBufferSize” -path “hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\*” -erroraction silentlycontinue | where {$_.DriverDesc -eq “Microsoft Virtual Machine Bus Network Adapter”})

{“Registry key SendBufferSize already exists”}

else

{Get-ItemProperty -Name “DriverDesc” -path “hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\*” -erroraction silentlycontinue | where {$_.DriverDesc -eq “Microsoft Virtual Machine Bus Network Adapter”} | new-itemproperty -name SendBufferSize -value 2048 -propertyType dword -erroraction silentlycontinue}

Having written the script we want to use it! At this point you have a choice to make; there are two options:

1. Sign the script (you’ll need a Code Signing certificate and private key, then: $cert = @(gci cert:\currentuser\CodeSigningCert)[0]; Set-AuthenticodeSignature RSBufferSize.ps1$cert);

2. Set the script execution policy to Unrestricted (Set-ExecutionPolicy -ExecutionPolicy Unrestricted)

I strongly recommend option 1 for security, but in a lab or low security environment (i.e. you WANT your hosts to be compromised) option 2 might be acceptable.

Finally, you need to configure Group Policy or Local Policy for the host to have a Startup Script. You’ll find these settings under Computer Settings > Windows Settings > Scripts (Startup/Shutdown):

PowerShell Scripts tab (not the default Scripts tab):

Add a new script and set the script path to your saved file:

Why a Startup script? I tried a shutdown script but it didn’t work ;-) Reboot required to make settings effective!

It’s worth noting that scripts executed by Group Policy do not need to be signed – they bypass the script execution policy settings. Nevertheless you’re going to want to sign it so that:

  • If someone changes the script you will know when you run it manually;
  • You can test the script;
  • You can use it for reasons other than shutting down a host.

That’s all that needs to be done – now it’s testing time. The script is included in the text so you can just copy it, save it, sign it and test it.

PowerShell Remote Password Reset

December 12th, 2009 No comments

Here is a very simple PowerShell script to remotly reset local user passwords:

$data = import-csv C:\Scripts\ResetAdminPassword.csv

foreach ($row in $data) {

$admin=[adsi](“WinNT://” + $row.Server + “/administrator, user”)

$admin.psbase.invoke(“SetPassword”, $row.Password)

$admin.psbase.CommitChanges()

}

The CSV file is build with as top row the values “Server,Password

Easy exch2k7 csv bulk user import with new-mailbox script

July 25th, 2008 No comments

Even om aan te geven dat deze blog echt van een nerdo is hieronder een script waarmee je eenvoudig een x aantal gebruikers kan importeren uit een csv bestand in een omgeving van Windows Server 2008 en Exchange 2007. Het is een PowerShell script overigens.

De eerste regel van het csv bestand ziet er als volgt uit:

FirstName,LastName,Name,Alias,UserPrincipalName,SamAccountName,Title,Password,Database,

OrganizationalUnit

Een nieuwe variable toevoegen kan door deze achteraan bij te voegen en in onderstaand script het op te nemen met <variabele naam> $_.<variabele naam>. Deze variabele naam is dus de toevoeging aan het cvs bestand. In onderstaand voorbeeld is namelijk 1( Title) van de vele variabelen uit Set-User meegenomen.

Function secureit( $string )
{
$ss = New-object System.Security.SecureString
$string.GetEnumerator() | foreach-object { $ss.AppendChar( $_ ) }
$ss
}

import-csv c:\New-MailboxUser.csv | foreach-object {New-Mailbox -Name $_.Name -Alias $_.Alias -OrganizationalUnit $_.OrganizationalUnit -UserPrincipalName $_.UserPrincipalName -SamAccountName $_.SamAccountName -FirstName $_.FirstName -LastName $_.LastName -Password (secureit $_.Password) -ResetPasswordOnNextLogon $true -Database $_.Database}

import-csv c:\New-MailboxUser.csv | foreach-object {set-user -identity $_.UserPrincipalName -Title $_.Title}

Opslaan als .ps1 bestand en plaatsen in de script directory van Exchange 2007. CSV bestand plaatsen in het opgegeven pad, hier is dat C:\.

Mocht je het csv bestand aanmaken in Excel zorg en dan voor dat jet het bestand na bewerkt door alle ; te vervangen door een ,(komma). Daarbij is bovenstaand script eenvoudig uit te breiden met meerdere regels die importeren uit hetzelfde csv bestand. Het toevoegen aan groepen zou bijv. ook tot de mogelijkheden kunnen behoren.

Op deze manier zijn er geen extra tools nodig van bijv. Quest.