Skip to main content

Posts

Showing posts from January, 2012

Generate Random SecureString Key

Ever need to encrypt a SecureString that can be used across multiple servers? I suggest storing this BASE64 value in a secure location only accessible by the account(s) that need to decrypt the SecureString.
$secret = 'secret1234'$key    = [Convert]::ToBase64String((1..32 |% { [byte](Get-Random -Minimum 0 -Maximum 255) }))  $encryptedSecret = ConvertTo-SecureString -AsPlainText -Force -String $secret | ConvertFrom-SecureString -Key ([Convert]::FromBase64String($key))  $encryptedSecret | Select-Object @{Name='Key';Expression={$key}},@{Name='EncryptedSecret';Expression={$encryptedSecret}} | fl  $ss = ConvertTo-SecureString -Key ([Convert]::FromBase64String($key)) -String $encryptedSecret(New-Object System.Management.Automation.PSCredential 'SECURESTRING',$ss).GetNetworkCredential().Password

FIM Run History Statistics

Probably not optimal but I didn't find any problem running this on a server with over 500 runs in the history
Note: Remember to clear your run history every so often!

[Get-FIMRunHistoryStatistics.ps1]
param(      [string]   $ComputerName = '.',      [string[]] $MaName       = $null,      [string[]] $RunProfile   = $null)  process {  Get-WmiObject -Class 'MIIS_RunHistory' -Namespace 'root\MicrosoftIdentityIntegrationServer' -Filter 'RunStatus != "in-progress"' `          |? { ([int]$MaName.Count -eq 0 -or $MaName -contains $_.MaName) -and ([int]$RunProfile.Count -eq 0 -or $RunProfile -contains $_.RunProfile) } `          | Select-Object -Property MaName,RunProfile,@{Name='RunTime';Expression={[DateTime]::Parse($_.RunEndTime).Subtract([DateTime]$_.RunStartTime).Ticks}} `          | Group-Object -Property MaName,RunProfile `          | Sort-Object -Property Name `          | Select-Object -Property *,@{Name='RunTimeStatistics';E…

Export SQL Reporting Services Execution Log to CSV

We recently needed to export the SQL Server Reporting Services execution log so we can audit usage of our reporting services environment.

I just love how PowerShell makes this easy to do.

[Export-SSRSExecutionLog3.ps1]
param(      [string]   $ConnectionString = 'Server=(local);Database=ReportServer;Integrated Security=SSPI;',      [string]   $CommandText      = 'SELECT * FROM dbo.ExecutionLog3 WHERE TimeStart BETWEEN ''{0:MM/dd/yyyy} 12:00:00 AM'' AND ''{0:MM/dd/yyyy} 11:59:59 PM''',      [string]   $Path             = "$($ENV:WINDIR)\system32\LogFiles\SQL",      [string]   $FileName         = 'ReportServer-ExecutionLog3-{0:yyyyMMdd}.csv',      [DateTime] $Date             = [DateTime]::Now.Subtract([TimeSpan]::FromDays(1))  )  begin {  $ErrorActionPreference = 'Stop'$connection = New-Object System.Data.SqlClient.SqlConnection $ConnectionString$connection.Open()  }  process {  $adapter = New-Object System.Data.S…