Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Created August 17, 2010 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/528112 to your computer and use it in GitHub Desktop.
Save vcsjones/528112 to your computer and use it in GitHub Desktop.
$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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment