Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
$PSCredential- round two
-
Hi @Jonathan-Engstrom ,
I have noticed the $ServerName uses the name of my server configured in Otter, not the actual computer name. Have you tried running the remediation using
$env.computernameinstead of$ServerName? Or can you verify the Server Name in Otter matches the computers name?Thanks,
Rich -
That's a good idea, but I actually started off using the $env:computername and switched to $servername thinking that maybe somehow Otter wasn't using the $env:computername variable, but it didn't make any difference.
-
Hi @Jonathan-Engstrom ,
What version of PowerShell do you have installed on your SQL server? I'm running 5.1.18362.628.
Thanks,
Rich -
It's a 2016 Server, so it comes preinstalled with 5.1. 5.1.14393.3471 is the specific version.
-
@Jonathan-Engstrom said in $PSCredential- round two:
Same code, same machine.
Same user?
@Jonathan-Engstrom said in $PSCredential- round two:
it would help to understand why.
FYI -- Otter doesn't format PowerShell; it parses the PowerShell script (using MIcrosoft's parser), looks for variable tokens, and "injects" a variable into the runtime if there's a matching variable.
The interactive Powershell Host (which you're using,
ps.exe) also does things differently. There's a ton of layers-upon-layers with active directory. so it'll take some trial/error to find out what's happening. -
Yes, same user. Like I said, I have taken great care to eliminate variables trying to understand what is going on.
-
Hi @Jonathan-Engstrom ,
Have you tried wrapping your PSEnsure inside of a
withblock to force everything to run as a specific Resource Credential?Example using a resource credential named AdAdminResourceCredentials:
with credentials = AdAdminResourceCredentials { PSEnsure ( Key: RSHStuff, Value: True, Collect: >> $ErrorActionPreference = 'SilentlyContinue' $TargetOU = 'Users' $Value = (Get-ADComputer -Identity $env:COMPUTERNAME).DistinguishedName -match $TargetOU $CurrentValue = (Get-ADComputer -Identity $env:COMPUTERNAME).DistinguishedName ((($Value -eq $true) -and (($env:COMPUTERNAME) -match 'MyComputerName')) -or ($env:COMPUTERNAME -notmatch 'MyComputerName')) >>, Configure: >> $samAccountName = $ServerName $newOU = [adsi]"LDAP://$TargetOU" $comp= ([adsisearcher]"samaccountname=$($ServerName)$").FindOne() Write-Host $comp.GetDirectoryEntry() >>, Debug: true, Verbose: true ); }Please note that my PowerShell in
collectandconfigureis not 1 to 1 with yours, I would replace my PowerShell script with yours in those two properties.I also was talking with one of the solutions architects on a similar Otter execution question. He suggested that sometimes it is easier to figure out PowerShell issues by running PSExec under the local system account and attempting to run your PowerShell commands that way. It will sometimes show you more detailed errors than Otter. I would try running
PSExec -s powershell, which will open up a PowerShell console as the local system account, and then typing in the lines of PowerShell you have had trouble with.Thanks,
Rich
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login