-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInVMScriptExecution.ps1
36 lines (33 loc) · 1.3 KB
/
InVMScriptExecution.ps1
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
Param(
# Recieve the Content from the sender/commandline
[parameter(Mandatory=$true)][String]$Content,
# File name for the content to be saved in
[parameter(Mandatory=$true)][String]$FileName,
#Path where the file needs to be created
[parameter(Mandatory=$true)][String]$Path,
# File needs to be appended or forced overwritten
[parameter(Mandatory=$false)][String]$Append
)
#Since the Boolean doesnt work very well with parameters from Invoke Command, convert yes/no to true/false
if($append.ToUpper() -eq "YES"){
$toAppend = $true
}
else{
$toAppend = $False
}
#Create the full file path to store the conent into
$fileObj = (Join-Path -Path $Path -ChildPath $FileName)
if($toAppend){
Write-Host "Appending file"
#Decode and store file content into a previously existing file
[System.Text.Encoding]::utf8.GetString([System.Convert]::FromBase64String($Content)) | Out-File $fileObj -Append -Encoding default -NoNewline
}
else{
Write-Host "Forcing file"
#Decode and store file content into a file, overwrite the file if it already exists
[System.Text.Encoding]::utf8.GetString([System.Convert]::FromBase64String($Content)) | Out-File $fileObj -Force -Encoding default -NoNewline
}
#Show the directory contents
Dir $path
#Check the target file size
(Get-Item -Path $fileObj).length