![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | function -credentials Hi, I'm trying to write a script running as system account on a MOSS2007 server (Win2K8). This script has stsadm commands to upload forms to an sql-server. The local sysaccount has no access to the sql-instance. So I try (by knowing SQL credentials) to transfer the credentials (userid and password) within the script to the sql-server. As the stsadm commands doesn't accept the -credentials parameter I created two functions (VerForm & UplForm) and attempted to transfer creds into the function. But this doens't seem to work. Have a look below to the script. Where am I wrong ? As always I appreciate your tips to get this done! Thanks in advance. Read-Host ”Enter password to secure:” -AsSecureString | ConvertFrom-SecureString | Out-File c:\scripts\securepass.txt ### The password gets encrypted and placed in C:\scripts\securepass.txt #+++++++++++++++ start +++++++++++++++++++++++# ## ----- Static Constants ----- ## $userid = "SQLMOSS@xxxxxx" $WorkingDirectory = “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN” $InfoPathDirectory = "\\server\InfoPathForms\TechnicalReport.xsn" ## ---------------------------- ## # $pass = Get-Content C:\Scripts\securepass.txt | ConvertTo-SecureString ### Taking back the psw into the script $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userid,$pass cd $WorkingDirectory ### Change to working directory ### STSADM commands to verify and upload form templates ### function VerForm ($creds){ .\STSADM.EXE -o verifyformtemplate -filename $InfoPathDirectory } function UplForm ($creds){ .\STSADM.EXE -o uploadformtemplate -filename $InfoPathDirectory } # Write-Host "Verifying Form " -ForegroundColor Green VErForm ### Call function VerifyForm Write-Host " +++++++++++++++++++++++++++++++++++++" -ForegroundColor Yellow Write-Host "Uploading Form " -ForegroundColor Green UplForm ### Call function UploadForm cd c:\Scripts #+++++++++++++++ end +++++++++++++++++++++++++# -- PIBCAK - Problem is between Chair and Keyboard! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: function -credentials why you don't want to grant access for your system account to SQL Server? -- WBR, Vadims Podans MVP: PowerShell PowerShell blog - www.sysadmins.lv "TheOther Dude" <TheOtherDude@xxxxxx> rakstīja ziņojumā "news:EF7746B5-0ACF-48FC-AFAD-62E6A3FEFA73@xxxxxx"... Quote: > Hi, I'm trying to write a script running as system account on a MOSS2007 > server (Win2K8). This script has stsadm commands to upload forms to an > sql-server. The local sysaccount has no access to the sql-instance. So I > try > (by knowing SQL credentials) to transfer the credentials (userid and > password) within the script to the sql-server. > As the stsadm commands doesn't accept the -credentials parameter I created > two functions (VerForm & UplForm) and attempted to transfer creds into the > function. But this doens't seem to work. Have a look below to the script. > Where am I wrong ? As always I appreciate your tips to get this done! > Thanks > in advance. > > > Read-Host ”Enter password to secure:” -AsSecureString | > ConvertFrom-SecureString | Out-File c:\scripts\securepass.txt ### The > password gets encrypted and placed in C:\scripts\securepass.txt > > #+++++++++++++++ start +++++++++++++++++++++++# > > ## ----- Static Constants ----- ## > $userid = "SQLMOSS@xxxxxx" > $WorkingDirectory = “C:\Program Files\Common Files\Microsoft Shared\Web > Server Extensions\12\BIN” > $InfoPathDirectory = "\\server\InfoPathForms\TechnicalReport.xsn" > ## ---------------------------- ## > # > $pass = Get-Content C:\Scripts\securepass.txt | ConvertTo-SecureString ### > Taking back the psw into the script > $creds = New-Object -TypeName System.Management.Automation.PSCredential > -ArgumentList $userid,$pass > > > cd $WorkingDirectory ### Change to working directory > ### STSADM commands to verify and upload form templates ### > function VerForm ($creds){ > .\STSADM.EXE -o verifyformtemplate -filename $InfoPathDirectory > } > function UplForm ($creds){ > .\STSADM.EXE -o uploadformtemplate -filename $InfoPathDirectory > } > # > Write-Host "Verifying Form " -ForegroundColor Green > VErForm ### Call function VerifyForm > Write-Host " +++++++++++++++++++++++++++++++++++++" -ForegroundColor > Yellow > Write-Host "Uploading Form " -ForegroundColor Green > UplForm ### Call function UploadForm > > cd c:\Scripts > > #+++++++++++++++ end +++++++++++++++++++++++++# > -- > PIBCAK - Problem is between Chair and Keyboard! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: function -credentials Hi TheOther, I would follow Vadims' advice when ever you can, still the below is more generic approach when you need to get credentials in a secure way and pass them along (to console utils) as clear text: $cred = Get-Credential # type your credentials in UI # print it to see what it looks like #$cred.GetNetworkCredential() # get the creds (clear text) so you can pass them to stsadm $user = $cred.GetNetworkCredential().UserName $psw = $cred.GetNetworkCredential().Password --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic PowerShell Toolbar: http://tinyurl.com/PSToolbar TD> Hi, I'm trying to write a script running as system account on a TD> MOSS2007 TD> server (Win2K8). This script has stsadm commands to upload forms to TD> an TD> sql-server. The local sysaccount has no access to the sql-instance. TD> So I try TD> (by knowing SQL credentials) to transfer the credentials (userid and TD> password) within the script to the sql-server. TD> As the stsadm commands doesn't accept the -credentials parameter I TD> created TD> two functions (VerForm & UplForm) and attempted to transfer creds TD> into the TD> function. But this doens't seem to work. Have a look below to the TD> script. TD> Where am I wrong ? As always I appreciate your tips to get this TD> done! Thanks TD> in advance. TD> Read-Host Enter password to secure: -AsSecureString | TD> ConvertFrom-SecureString | Out-File c:\scripts\securepass.txt ### TD> The password gets encrypted and placed in C:\scripts\securepass.txt TD> TD> #+++++++++++++++ start +++++++++++++++++++++++# TD> TD> ## ----- Static Constants ----- ## TD> $userid = "SQLMOSS@xxxxxx" TD> $WorkingDirectory = C:\Program Files\Common Files\Microsoft TD> Shared\Web TD> Server Extensions\12\BIN TD> $InfoPathDirectory = "\\server\InfoPathForms\TechnicalReport.xsn" TD> ## ---------------------------- ## TD> # TD> $pass = Get-Content C:\Scripts\securepass.txt | TD> ConvertTo-SecureString ### TD> Taking back the psw into the script TD> $creds = New-Object -TypeName TD> System.Management.Automation.PSCredential TD> -ArgumentList $userid,$pass TD> cd $WorkingDirectory ### Change to working directory TD> ### STSADM commands to verify and upload form templates ### TD> function VerForm ($creds){ TD> .\STSADM.EXE -o verifyformtemplate -filename $InfoPathDirectory TD> } TD> function UplForm ($creds){ TD> .\STSADM.EXE -o uploadformtemplate -filename $InfoPathDirectory TD> } TD> # TD> Write-Host "Verifying Form " -ForegroundColor Green TD> VErForm ### Call function VerifyForm TD> Write-Host " +++++++++++++++++++++++++++++++++++++" -ForegroundColor TD> Yellow TD> Write-Host "Uploading Form " -ForegroundColor Green TD> UplForm ### Call function UploadForm TD> cd c:\Scripts TD> TD> #+++++++++++++++ end +++++++++++++++++++++++++# TD> |
My System Specs![]() |
| | #4 (permalink) |
| | Re: function -credentials Thanks Vadims, this is actually somethig I'll discuss with our SQL Admin. His decision depends on Company policy. But if he agrees then we're good to go. Yeah, simple way. Appreciate your post. -- PIBCAK - Problem is between Chair and Keyboard! "Vadims Podans [MVP]" wrote: Quote: > why you don't want to grant access for your system account to SQL Server? > -- > WBR, Vadims Podans > MVP: PowerShell > PowerShell blog - www.sysadmins.lv > > "TheOther Dude" <TheOtherDude@xxxxxx> rakstīja ziņojumā > "news:EF7746B5-0ACF-48FC-AFAD-62E6A3FEFA73@xxxxxx"... Quote: > > Hi, I'm trying to write a script running as system account on a MOSS2007 > > server (Win2K8). This script has stsadm commands to upload forms to an > > sql-server. The local sysaccount has no access to the sql-instance. So I > > try > > (by knowing SQL credentials) to transfer the credentials (userid and > > password) within the script to the sql-server. > > As the stsadm commands doesn't accept the -credentials parameter I created > > two functions (VerForm & UplForm) and attempted to transfer creds into the > > function. But this doens't seem to work. Have a look below to the script. > > Where am I wrong ? As always I appreciate your tips to get this done! > > Thanks > > in advance. > > > > > > Read-Host ”Enter password to secure:” -AsSecureString | > > ConvertFrom-SecureString | Out-File c:\scripts\securepass.txt ### The > > password gets encrypted and placed in C:\scripts\securepass.txt > > > > #+++++++++++++++ start +++++++++++++++++++++++# > > > > ## ----- Static Constants ----- ## > > $userid = "SQLMOSS@xxxxxx" > > $WorkingDirectory = “C:\Program Files\Common Files\Microsoft Shared\Web > > Server Extensions\12\BIN” > > $InfoPathDirectory = "\\server\InfoPathForms\TechnicalReport.xsn" > > ## ---------------------------- ## > > # > > $pass = Get-Content C:\Scripts\securepass.txt | ConvertTo-SecureString ### > > Taking back the psw into the script > > $creds = New-Object -TypeName System.Management.Automation.PSCredential > > -ArgumentList $userid,$pass > > > > > > cd $WorkingDirectory ### Change to working directory > > ### STSADM commands to verify and upload form templates ### > > function VerForm ($creds){ > > .\STSADM.EXE -o verifyformtemplate -filename $InfoPathDirectory > > } > > function UplForm ($creds){ > > .\STSADM.EXE -o uploadformtemplate -filename $InfoPathDirectory > > } > > # > > Write-Host "Verifying Form " -ForegroundColor Green > > VErForm ### Call function VerifyForm > > Write-Host " +++++++++++++++++++++++++++++++++++++" -ForegroundColor > > Yellow > > Write-Host "Uploading Form " -ForegroundColor Green > > UplForm ### Call function UploadForm > > > > cd c:\Scripts > > > > #+++++++++++++++ end +++++++++++++++++++++++++# > > -- > > PIBCAK - Problem is between Chair and Keyboard! > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| function to delete a function | PowerShell | |||
| function not working dispite working outside the function block | PowerShell | |||
| Help - Credentials | PowerShell | |||
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | PowerShell | |||
| Workgroup credentials | Vista networking & sharing | |||