See backup chain SQL Server

See the backup chain in SQL Server

SELECT 

TOP 100

s.database_name,

CASE s.type

WHEN 'D' THEN 'Full'

WHEN 'I' THEN 'Differential'

WHEN 'L' THEN 'Transaction Log'

END AS BackupType,

CAST(DATEDIFF(second, s.backup_start_date,

s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken,

s.backup_start_date,

CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn,

CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn,

m.physical_device_name,

CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize,

s.server_name,

s.recovery_model

FROM msdb.dbo.backupset s

INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id

WHERE s.database_name = DB_NAME() -- Remove this line for all the database

ORDER BY backup_start_date DESC, backup_finish_date

GO

Source: http://blog.sqlauthority.com/2010/11/10/sql-server-get-database-backup-history-for-a-single-database/

0  

Running PowerShell Script from Netlogon Share

To run a powershell script from a netlogon share, proceed as follows:

0  

PowerShell: updating AD photo for use in Office 365

I wanted to add a photo to every user in our Office 365 environment, so it is visible within our Lync software.
Normally I would think I would go to Lync, open op “Tools” and then “Options”, select My Picture and change it. But in Lync 2013 the “Edit or Remove Picture” is grayed out.
You can read some more about this “problem” in this support post. It will be available again when they upgrade our office 365 environment.

So for now I had to think of something.
As we have a synced environment (through DirSync) I thought I could make use of the AD User object property “ThumbnailPhoto”. If  I could fill this value with a jpg then it would get synced to office 365.
And for that I created a PowerShell Script.

Starting Point: I have a folder with all the JPG images which are named in the following format firstname.lastname@domainname.jpg (I got these from someone else, who saved them like that). So as u will see in the script below I had to use some string manipulation to match the JPG to a domain user

$photodir = "c:\temp\photo\"
$photos = Get-ChildItem -Path $photodir -Filter *.jpg

#itterate through Photos in Photo Directory
foreach ($photo in $photos)
{
	#store the raw file content of the image
	$jpg = [convert]::ToBase64String((get-content $photo.FullName -encoding byte))

	$Name = (($photo.Name).split("@")[0]).Replace("."," ")
	$LDAPString = "LDAP://cn=" + $Name + ",OU=OU1,dc=domain,dc=local"
	$userAD =  [adsi] $LDAPString
	$userAD.put("thumbnailPhoto",$jpg)
	$userAD.setinfo()
	Write-Host "Updated User " $userAD.name " Thumbnail Photo"
}

It will take some time before you see pictures.

I received the following error for a few images: Exception calling “setinfo” with “0″ argument(s): “A constraint violation occurred. (Exception from HRESULT: 0x8007202F)”.

I noticed that the thumpnailphoto attribute can’t hold more than about 75kb. So make sure you’re images are smaller.

0  

PowerShell: Import Scheduled Task

Some powershell I needed to import some scheduled tasks (xml files).
Just for my own reference

$XMLTaskDir = "C:\Program Files (x86)\****\***\"
$Tasks = Get-ChildItem -Path $XMLTaskDir -Filter *.xml -Recurse

foreach ($task in $tasks)
{
    $TaskName = [io.path]::GetFileNameWithoutExtension($task)
    Register-ScheduledTask -Xml (get-content $task.FullName | out-string) -TaskName $TaskName –User <UserName> –Password <Password> -taskpath Imported
    Disable-ScheduledTask -TaskName $TaskName -TaskPath Imported
}
0  

Server 2012 – installing Feature on Demand: .NET Framework 3.5

When installing SQL 2012 on my windows server 2012 box, I received errors about the install of .NET Framework 3.5.
As .NET Framework 3.5 is a “feature on demand”, the binaries and other files associated with the feature are not included on the server. Windows Server tries to contact Windows Update to download the files it needs to install the feature.
Your network configuration can have effect on the process of downloading the needed files.

I solved the problem, by mounting the Windows Server 2012 installation media and issuing the following command:

Dism /online /enable-feature /featurename:NetFx3 /All /Source:<drive>:\sources\sxs /LimitAccess

Where <drive> stands for the drive letter of the mounted installation media

0  

Changing an Office 365 User Principal Name with Powershell

It is very ease to change your login name in Office 365 if you have PowerShell for office 365 (x86 version, x64 Version) installed.

First connect to Office 365

Connect-msolService

Enter your Credentials, and then issue the next command:

Set-MsolUserPrincipalName -NewUserPrincipalName [New Name] -UserPrincipalName [Old Name] 
0  

Amazon Powershell Tools

The amazon Powershell Tools have arrived: http://aws.amazon.com/powershell/
578 commands

When first starting your AWS Powershell Tools, you have to specify your Access Key and you Secret Access Key.

AWS PowerShell Tools

They are then stored for future sessions.
You can also create another set of stored Credentials.

Set-AWSCredentials –AccessKey <Your Access Key> –Secretkey <Your Secret Key> –StoreAs SET1

SET1 is a name you can give to identify your credentials
You can now load your “SET1″ Credentials

Set-AWSCredentials –StoredCredentials SET1
AWS Tools for PowerShell
0  

Link: Where is the PowerShell ISE in Windows 8?

http://www.trekker.net/archives/where-is-the-powershell-ise-in-windows-8/

0  

PowerShell: Counting Files older than today (little mistake)

Today I had to count the number of XML files inside a folder.
Simple, I thought.

I created the following script:

$OldestFileImport = get-childitem d: *.XML | where-object {$_.LastWriteTime -le [datetime]::today}
$OldestFileImport.count

After executing it gave me an empty return (??).
I was sure there was one older xml file in D:… So to test again, I copied 15 other (older) XML files to D:. Executed the PowerShell and it gave me a count of 16.

What the……

After examining with Powergui (long live powergui), I got to the answer.
When there is more than one xml in D:, $oldestFileImport will be an array so you can use the method .count.
If there is just one xml, it will return that one item (a FileSystem Object). So .count doesn’t work. To resolve it I had to add [array] to $OldestFileImport. So the complete script is:

[array]$OldestFileImport = get-childitem d: *.XML | where-object {$_.LastWriteTime -le [datetime]::today}
$OldestFileImport.count
6  

PowerShell: Moving files into subfolder based on date

A script to move files from one directory to another and ordering them in subdirectory in the destination folder. The subdirectory name is bases on the date of the file, thus ordering all files with the same date in the same subdirectory. In the example below, only the XML files will be moved

$SourceDir = "C:Folder1"
$DestinationDir = "D:Folder2"

$files = get-childitem $SourceDir *.xml
foreach ($file in $files) 
{
$Directory = $DestinationDir + "" + $file.CreationTime.Date.ToString('dd-MM-yyyy')
if (!(Test-Path $Directory))
	{
	New-Item $directory -type directory
	}
	Move-Item $file.fullname $Directory

}
0