Skip to main content

Posts

Showing posts from April, 2017

Find All Azure DBs where a table is missing

Import-Module "SqlServer" $fullsqlsrv='myservername.database.windows.net' $sa='myadmin' $sapwd='mypassword' $connStr = "Server = $fullSqlSrv ; Database = master; User ID=$sa;Password=$sapwd" $connection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection $connection.ConnectionString = $connStr $connection.Connect() $server = New-Object Microsoft.SqlServer.Management.Smo.Server($connection) $allDBs= $server.Databases foreach ($db in $alldbs){     if (!($db.tables.Name -contains 'cspCompany')) {"$($db.name) has no CSpCompany"}     }

Generate Random Password with PowerShell

This snippet generates a random password starting with 2 digits or capital letters following by 16 random characters with ASCII codes between 33 and 126 and ending with two random lower case letters (48..57)+(65..90) | Get-Random -Count  2 | % -begin {$PwdStr='';} -process {$PwdStr+=[char]$_} (33..126) | Get-Random -Count 16 | % -process {$PwdStr+=[char]$_}  (97..122) | Get-Random -Count  2 | % -process {$PwdStr+=[char]$_} -end {$PwdStr} Exclude XML escape characters (as well as '\' and '/') from the passwords (33..126) | ? {([int][char]'!',[int][char]'<',[int][char]'>', [int][char]'\',[int][char]'/',[int][char]'"',[int][char]"'", [int][char]'&' ) -notcontains $_} `  | Get-Random -Count 44 | % -begin {$PwdStr=''} -process {$PwdStr+=[char]$_} -end {$pwdStr} Password from a string --> $("!@#$%*_-=+.:;[]{}0123456789abcdefghijklmnopqrstuvwxyzABCDEFGH