public
Last active

  • Download Gist
gistfile1.sh
Shell
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
$URI = "https://myserver/webservices/sswebservice.asmx" #The URI of the webservice
$templateName = "File Storage" #The name of the secret template we are going to use.
$username = "myusername"
$domain = "" #Leave empty if you aren't using domain accounts
$password = "mypassword"
$organizationCode = "" #Leave empty unless you are using Secret Server Online
$pathToFile = "C:\Users\My Account\Desktop\input.txt" #The path to the file we are going to upload.
$maxFieldSize = 1991
$secretName = "My New File 2"
 
 
#End Configuration
 
$ss = New-WebServiceProxy -UseDefaultCredential -uri $URI
 
#Set the correct username and password. It's recommended to use an empty string rather than "Local" for domain
$token = $ss.Authenticate($username, $password, $organizationCode, $domain)
 
if ($token.Errors.Length -gt 0)
{
echo $token.Errors
Return
}
 
#Get the template for the secret we are adding
$template = $ss.GetSecretTemplates($token.Token).SecretTemplates | Where {$_.Name -eq $templateName}
$fields = $ss.GetSecretTemplateFields($token.Token, $template.Id).Fields | Where {$_.DisplayName -match "Item\d"} | Sort DisplayName
$content = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($pathToFile))
$contentSplit = @()
While($content.Length -gt 0)
{
$fileSection = $content.Substring(0, [System.Math]::Min($content.Length, $maxFieldSize))
$contentSplit = $contentSplit + $fileSection
$content = $content.Substring($fileSection.Length)
}
While($contentSplit.Length -lt $fields.Length)
{
$contentSplit = $contentSplit + ""
}
 
$fieldIds = @()
$fields | ForEach {$fieldIds = $fieldIds + $_.Id}
$ss.AddSecret($token.Token, $template.Id, $secretName, $fieldIds, $contentSplit, -1)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.