forked from jjmolerof/PowerShellScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-UPDReport.ps1
More file actions
50 lines (44 loc) · 1.43 KB
/
Copy pathGet-UPDReport.ps1
File metadata and controls
50 lines (44 loc) · 1.43 KB
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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[String]$UPDPath
)
$3f = @()
$1f = Get-ChildItem $UPDPath -Recurse | where {!$_.PSIsContainer} | Select-Object FullName,LastWriteTime,@{Name="Size";Expression={$_.Length / 1MB}} | sort LastWriteTime -Descending
foreach ($2f in $1f) {
$SID = $2f.FullName -replace('.*UVHD-','') -replace('.vhdx','')
$p1 = @{"FullName"=$2f.FullName;
"LastWriteTime"=$2f.LastWriteTime;
"Size"=$2f.Size;
"SID"=$SID}
$3f += New-Object -TypeName PSObject -Property $p1
}
foreach ($4f in $3f) {
$a = @()
$e = @()
$ErrorActionPreference = 'SilentlyContinue'
$a = Get-ADUser $4f.SID -Properties Name,UserPrincipalName,Enabled,LastLogonDate -ErrorVariable e
if ($e) {
$p2 = @{"FullName"=$4f.FullName;
"LastWriteTime"=$4f.LastWriteTime;
"Size"=$4f.Size;
"SID"="No AD Account for this UPD";
"AD_Account_Name"="No AD Account for this UPD";
"AD_Account_UPN"="No AD Account for this UPD";
"AD_User_Enabled"="No AD Account for this UPD";
"AD_User_LastLogon"="No AD Account for this UPD"}
}
else {
$p2 = @{"FullName"=$4f.FullName;
"LastWriteTime"=$4f.LastWriteTime;
"Size"=$4f.Size;
"SID"=$4f.SID;
"AD_Account_Name"=$a.Name;
"AD_Account_UPN"=$a.UserPrincipalName;
"AD_User_Enabled"=$a.Enabled;
"AD_User_LastLogon"=$a.LastLogonDate}
}
$Obj = New-Object -TypeName PSObject -Property $p2
Write-Output $Obj | select FullName,LastWriteTime,Size,SID,AD_Account_Name,AD_Account_UPN,AD_User_Enabled,AD_User_LastLogon
}