Created
August 17, 2010 01:34
-
-
Save vcsjones/528112 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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