Skip to content

Instantly share code, notes, and snippets.

@davegreen
Last active October 6, 2016 20:13
Show Gist options
  • Save davegreen/54d688e91a002c4d0b8dac3a02fabc0d to your computer and use it in GitHub Desktop.
Save davegreen/54d688e91a002c4d0b8dac3a02fabc0d to your computer and use it in GitHub Desktop.
# Requires -RunAsAdministrator
[CmdletBinding(
SupportsShouldProcess = $True,
ConfirmImpact = 'High'
)]
Param(
[parameter(
Mandatory = $true
)]
[ValidateScript({
Test-Path -Path $_
})]
[string]$StorePath,
[parameter(
Mandatory = $true
)]
[string]$DomainSID
)
$SID = (Get-WmiObject Win32_UserProfile | Where-Object {$_.SID -like "$DomainSID*"} |
Select-Object SID, Localpath, @{name="LastUsed";Expression={$_.ConvertToDateTime($_.LastUseTime)}} |
Sort LastUsed -Descending)[0].SID
$Username = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value
$StoreName = $Username.Split('\')[1]
$StoreFolder = (Get-Item -Path $StorePath\$StoreName* | Sort-Object Name -Descending).Name | Select-Object -First 1
if ($PSCmdlet.ShouldProcess("$StorePath\$StoreFolder")) {
.\loadstate.exe $StorePath\$StoreFolder /i:migdocs.xml /i:migapp.xml /v:5 /l:$env:TEMP\USMTLoad.log /progress:$env:TEMP\USMTLoadProgress.log /c
}
# Requires -RunAsAdministrator
[CmdletBinding(
SupportsShouldProcess = $True,
ConfirmImpact = 'Medium'
)]
Param(
[parameter(
Mandatory = $true
)]
[ValidateScript({
Test-Path -Path $_
})]
[string]$StorePath,
[parameter(
Mandatory = $true
)]
[string]$DomainSID
)
$SID = (Get-WmiObject Win32_UserProfile | Where-Object {$_.SID -like "$DomainSID*"} |
Select-Object SID, Localpath, @{name="LastUsed";Expression={$_.ConvertToDateTime($_.LastUseTime)}} |
Sort LastUsed -Descending)[0].SID
$Username = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value
$StoreName = $Username.Split('\')[1]
$StoreTime = Get-Date -Format "yyyy-MM-dd_HH-mm"
if ($PSCmdlet.ShouldProcess("$StorePath\$($StoreName)_$($StoreTime)")) {
.\scanstate.exe $StorePath\$($StoreName)_$($StoreTime) /i:migdocs.xml /i:migapp.xml /vsc /uel:5 /ue:* /ui:$($Username) /v:5 /l:$env:TEMP\USMTScan.log /progress:$env:TEMP\USMTScanProgress.log /c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment