1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
$BackupDay = 6
$server = $env:COMPUTERNAME
Set-ExecutionPolicy unrestricted -force
Function Get-DriveLetters{
param($Server)
$volumes = @{}
$allvolumes = Get-WmiObject -Class "win32_volume" -ComputerName $server | Select DeviceID, Name
foreach ($v in $allvolumes)
{
$volumes.add($v.DeviceID, $v.Name)
}
$volumes
}
Function Get-vol{
$test2=@{}
# Attention au drive perso : new-PSDrive MonDrive c:\projets\ ...
$test = Get-PSdrive -PSProvider FileSystem |
Where-Object {$_.name -match '^[A-Z]$'} |
Select-Object Root, Name
foreach ($t in $test)
{
$test2.add($t.Root, $t.Name)
}
$test2
}
$teste = Get-vol
write-host $teste
Function New-InfosCliches{
#crée un objet personnalisé
param(
[Parameter(Mandatory=$True,position=0)]
[AllowNull()]
$Select,
[Parameter(Mandatory=$True,position=1)]
[AllowNull()]
$Etat,
[Parameter(Mandatory=$True,position=2)]
[AllowNull()]
$Date
)
[pscustomobject]@{
PSTypeName='InfosCliches';
Select=$Select;
Etat=$Etat;
Date=$Date;
}
}# New-InfosCliches
Function Check-ShadowCopies{
param($Servers)
foreach ($Srv in $servers)
{
$driveletters = Get-DriveLetters $Srv
$shadowcopies = Get-WmiObject -Class "Win32_shadowcopy" | Select InstallDate, VolumeName
foreach ( $copy in $shadowcopies)
{
$shadowcopy=New-InfosCliches -Select $null -Etat $null-Date $null
$date = [datetime]::ParseExact($copy.InstallDate.Split(".")[0], "yyyyMMddHHmmss", $null)
if ( $date -ge (Get-Date).Addhours(-$backupday))
{
## On ajoute à l'objet personnalisé $cliches une propriété Etat où l'on mettra la valeur retournée ##
$shadowcopy.Select=$driveletters.item($copy.VolumeName)
$shadowcopy.Etat="Ok"
$shadowcopy.Date=$Date
## On émet le nouvel objet dans le pipeline
write-debug "Création objet avec cliché"
Write-output $shadowcopy
}
else
{
write-debug "Création Objet sans cliché "
$shadowcopy.Etat="Ko"
$shadowcopy.Select=$teste
## On émet le nouvel objet dans le pipeline
Write-output $shadowcopy
}
}
}
}
$Debugpreference='Continue'
$checkshadowcopy = Check-Shadowcopies $Server
$Debugpreference='SilentlyContinue'
$checkshadowcopy | Sort-Object Etat,Driveletter -Descending| Out-File C:\Users\Administrateur\Desktop\test.txt |
Partager