PowerShell: Wait till time service initiated synchronization with the time source (Windows 2008)

$ew = new-object system.management.ManagementEventWatcher $ew.query = “Select * From __InstanceCreationEvent Where TargetInstance ISA ‘Win32_NTLogEvent'” while(!(get-eventlog -logname ‘System’ -Source ‘Microsoft-Windows-Time-Service’ | ? {$_.EventId -eq 35})){ $ew.WaitForNextEvent() }

PowerShell: Wait till time service initiated synchronization with the time source (Windows 2003)

$ew = new-object system.management.ManagementEventWatcher $ew.query = “Select * From __InstanceCreationEvent Where TargetInstance ISA ‘Win32_NTLogEvent'” while(!(get-eventlog -logname ‘System’ -Source ‘W32Time’ | ? {$_.EventId -eq 35})){ $ew.WaitForNextEvent() }

Windows Core: Install PowerShell 3.0 by using PowerShell 2.0

Run the script below in the PowerShell 2.0 on your Windows Core (new-object System.Net.WebClient).DownloadFile(‘http://download.microsoft.com/download/3/6/1/361DAE4E-E5B9-4824-B47F-6421A6C59227/dotNetFx40_Full_x86_x64_SC.exe’, ‘c:\dotNetFx40_Full_x86_x64_SC.exe’) .\dotNetFx40_Full_x86_x64_SC.exe (new-object System.Net.WebClient).DownloadFile(‘http://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu’, ‘c:\Windows6.1-KB2506143-x64.msu’) .\Windows6.1-KB2506143-x64.msu It is not unattended installation. You will be prompted several times to click Next.

Installing AWS CloudFormation Command Line Tools on Windows Core

AWS CloudFormation Command Line Tools (new-object System.Net.WebClient).DownloadFile(‘https://s3.amazonaws.com/cloudformation-cli/AWSCloudFormation-cli.zip’, ‘c:\AWSCloudFormation-cli.zip’) (new-object System.Net.WebClient).DownloadFile(‘https://s3.amazonaws.com/velaskec/7z920.exe’, ‘c:\7z920.exe’) (start 7z ‘x c:\AWSCloudFormation-cli.zip -oc:\ -r’ -wait -PassThru).ExitCode

AWS PowerShell store credentials

The AWS Tools for Windows PowerShell enable you to set up default credentials and a default region which can be used in every PowerShell session you run. This approach avoids having to specify these every time you run a cmdlet. The default credentials are placed in the credentials store under the profile name, AWS PS Default.Continue reading “AWS PowerShell store credentials”

Using PowerShell for common AWS SimpleDB operations

#Create SimpleDB client Add-Type -Path “C:\AWS SDK\1.3.8.0\bin\AWSSDK.dll” $sdb=[Amazon.AWSClientFactory]::CreateAmazonSimpleDBClient(‘Key Id’, ‘Secret Key’) #Create Domain $req = (new-object Amazon.SimpleDB.Model.CreateDomainRequest).WithDomainName(‘Contacts’) $sdb.CreateDomain($req) #List Domains $req = (new-object Amazon.SimpleDB.Model.ListDomainsRequest) $sdb.ListDomains($req) #Insert Item $req = (new-object Amazon.SimpleDB.Model.PutAttributesRequest).WithDomainName(‘Contacts’).WithItemName(‘user1’); $req.Attribute.Add((new-object Amazon.SimpleDB.Model.ReplaceableAttribute).WithName(‘FirstName’).WithValue(‘Konstantin’)) $req.Attribute.Add((new-object Amazon.SimpleDB.Model.ReplaceableAttribute).WithName(‘LastName’).WithValue(‘Vlasenko’)) $sdb.PutAttributes($req) #Query All Items $req = (new-object Amazon.SimpleDB.Model.SelectRequest).WithSelectExpression(‘select * from Contacts’) $sdb.Select($req) #Query Item $req = (new-object Amazon.SimpleDB.Model.SelectRequest).WithSelectExpression(‘select * fromContinue reading “Using PowerShell for common AWS SimpleDB operations”

PowerShell: Wait for SQL Server is ready for client connections

The useful PowerShell script waiting SQL server is ready. I found that waiting for starting service while((get-service MSSQL`$INSTANCENAME).Status -ne ‘Running’){Sleep 3} is not enough. Better to check the event log entry EventID = 17126: SQL Server is now ready for client connections. This is an informational message; no user action is required. $ew = new-objectContinue reading “PowerShell: Wait for SQL Server is ready for client connections”