It's a 2016 Server, so it comes preinstalled with 5.1. 5.1.14393.3471 is the specific version.
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!
Posts
-
RE: $PSCredential- round two
-
RE: $PSCredential- round two
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.
-
RE: $PSCredential- round two
Strange. I am running the code locally on the target server in powershell, and it is working flawlessly. The FindOne and FindAll work to limit the machine. Intellisense also auto completes these, so they are present and working.
([adsisearcher]"samaccountname=$($env:computername)$").FindOne()
works fine and returns the result on the sql machine I am targeting the psensure configuration on. I am not changing the code or machine I am testing on; changing anything or introducing variables would not constitute a very scientific observation. Same code, same machine. When run locally, works fine. When run in Otter, it does not work. I am guessing it is how Otter formats things sometimes; that would be my guess. But Otter is not handling this line of code. and it would help to understand why.
-
RE: $PSCredential- round two
Looking at your example, I am not sure how it could work. Your TargetOU is not in distinguished name format. Should be something like "'CN='Users',DN='Domain',DN='Test'". Did you move the computer object from one OU to another? I am curious about the results there.
-
RE: $PSCredential- round two
Here is the code for the PSEnsure:
##AH:UseTextMode
#Assembled Jonathan Engstrom 20200219
PSEnsure
(
Key: $KeyName,
Value: True,
Collect: >>$ErrorActionPreference = 'SilentlyContinue' $Value = (Get-ADComputer -Identity $env:COMPUTERNAME).DistinguishedName -match $TargetOU $CurrentValue = (Get-ADComputer -Identity $env:COMPUTERNAME).DistinguishedName ((($Value -eq $true) -and (($env:COMPUTERNAME) -match 'sql')) -or ($env:COMPUTERNAME -notmatch 'sql')),
Configure: >>$samAccountName = $ServerName $newOU = [adsi]"LDAP://$TargetOU" $comp= ([adsisearcher]"samaccountname=$($ServerName)$").FindOne() $comp.GetDirectoryEntry().MoveTo($newOU));
KeyName and TargetOU variables are set. I am not running an agent, I am doing everything agentless.
-
RE: $PSCredential- round two
I am not having a problem running the code locally, I am having a problem running it in Otter. The code I have works fine when run in PowerShell by itself; hence why I am wondering what is going on here.
That code does not work in Otter for me btw, I did not test outside of Otter.
-
RE: $PSCredential- round two
@rhessinger said in $PSCredential- round two:
$samAccountName = $ServerName
$newOU = [adsi]"LDAP://$TargetOU"
$test = ([adsisearcher]"samaccountname=$($samAccountName)$").FindOne()Good morning, I made this this change, and there was no change. I had the same error.
-
RE: $PSCredential- round two
I have a variable that specifies the TargetOU, it's just the path of the OU of where I want to move the computer account to. This is what is in the configure block of my PSEnsure:
$newOU = [adsi]"LDAP://$TargetOU" $test = ([adsisearcher]"samaccountname=$($ServerName)$").FindOne $comp.GetDirectoryEntry.MoveTo($newOU)There is no errors in the Diagnostic Center pertaining to this error.
-
RE: $PSCredential- round two
Here is the output. I also tested trying to use the method Findall instead of FindOne, it didn't make a difference.
Configuration job is targeting 1 servers by name.
Building configuration plan for server server.domain.test to target 1 roles.
Finished processing role configuration plans.
server.domain.test does not have a configuration plan in raft Default.
Finished processing 2 scripts.
Beginning collection run...
Collecting configuration...
Importing Name...
Importing ModuleName...
Invoke-DscResource -Name $Name -Method Get -Property $Property -ModuleName $ModuleName
Importing Name...
Importing Property...
Importing ModuleName...
Invoke-DscResource -Name $Name -Method Test -Property $Property -ModuleName $ModuleName
Importing Name...
Importing Property...
Importing ModuleName...
Comparing configuration...
Configuration matches template.
Collecting configuration...
Importing TargetOU...
Comparing configuration...
Difference: Value
=Template=> True
= Actual => , False
Configuration drift detected.
Adding to execution plan.
Collection run complete.
Collection run succeeded.
Beginning execution run...
Importing TargetOU...
Importing ServerName...
Exception calling "FindAll" with "0" argument(s): "An operations error occurred.
"
You cannot call a method on a null-valued expression.
Storing configuration template...
Execution run failed.
Recording configuration for server (ID=#2050)...
Configuration for server (ID=#2050) recorded.
Cleaning up temporary files on PowerShell... -
RE: Simplify running script assets in Otter Configurations (PSEnsure)
Alright, fair enough. As I use Otter almost exclusively for checking for compliance, I will look forward to this. Nontrivial asks are always the best ones, right? :D
-
RE: $PSCredential- round two
OK, thank you for the example, that makes much more sense with context around it. However, I am still not able to get this to work. I am not able to get the Move-ADObject cmdlet to work in Otter regardless even though I can get them to work every time outside of Otter. OK, so tried to do something different just in case. Same issue again, I can't get this line of code to work in an PSEnsure either:
([adsisearcher]"samaccountname=$($env:computername)$").FindOne()
This should return some simple AD attributes for the computer and runs fine outside of Otter. This does not work either when put inside of Otter. Wondering if there is something that is not allowing this code to work?
-
RE: Feature Request: Please add inside each Role which servers have drifted, and which ones are compliant.
Why does this have me listed as a guest who posted it instead of me? Was this something strange with the migration of the forums last year?
-
RE: $PSCredential- round two
Well, my question is not being answered I feel. That example lacks any context of use, so I can't really articulate what I can do with that. It's like if I called you and said some random thing like "rock" and hung up. OK, what is a person supposed to do with that information? I want to be able to do something like this in my configure portion of a psensure:
Move-ADObject -Identity (Get-ADComputer -Identity $env:COMPUTERNAME).ObjectGuid -Server $pdc -TargetPath $TargetOU -Credential "$PSCredential"
Is that all I need to do? If so, this is not working. The line of code works fine without the credential line in PowerShell, but does not work in Otter. I am having authentication issues, and need to be able to pass stored credentials I would like these questions answered:
- Is the $PSCredential being populated from the resource credentials stored in Otter for each server?
- Are the Username and Password sections populated from a plain text entry or manual intervention to populate the $PSCredential?
- If 1 and 2 have the answer of no, where are they coming from?
-
RE: Simplify running script assets in Otter Configurations (PSEnsure)
A Get-Asset operation always changes configuration
I am suprised that a "Get-Asset" " always changes configuration in stark contrast to powershell where the verb "get" is a read-only or gathering action only. This action, imho, is very poorly named.
So with that said, even if a collect is read only, I still don't understand why I can't load a script asset and gather/report data? Can a script asset be loaded to be made available for both collect and configure stages? That would be fantastic.
-
$PSCredential- round two
So, I am still struggling to pass the windows credentials stored in the resource credentials stored in the DB. I don't want to enter credentials manually or via in plain text, so unless I can get that stored password value, I fail to see the value in this for Windows Domain authentication. I found the documentation here:
https://docs.inedo.com/docs/otter/reference/functions/powershell/pscredential
But that does nothing to explain it. Does this have the username and password stored from the resource credentials so they can be used like a get-credential variable for domain authentication? I really need to pass the credentials stored in the DB to authenticate, thanks!
-
RE: Simplify running script assets in Otter Configurations (PSEnsure)
To add to this, I need the script assets to work in both the collect and configure passes, and I have not been able to get the module to work in both passes. I am not sure why they are so different, or would be designed in such a manner to disallow this to work. I have a great need to be able to call scripts and or modules to simplify my code and processes. Mostly as I need to keep extensive logging, I need to be able to during both collect and configure stages, I need to gather the existing settings in PowerShell for logging/ retention reasons. I then write that data to the computer's event log to be captured by logging systems.
I am not sure what you mean with the "call PSExecWithMods" example.
Also, I have one module I can run, Test-Module,ps1, but I have another script asset called TestOtter.ps1, and it won't load that PowerShell Asset. The actual content is the same; which makes it strange.
-
Migrating Otter and Git repository to new Server 2016 machine
Hello, Just wanted to ask if there has been anyone who has migrated their Otter instance to a new server? Is it just as simple as detaching the DB and reattach to a SQL instance on the new server? Any ideas for my Git based raft? I am using Bitbucket on prem server.
Thanks!
-
Simplify running script assets in Otter Configurations (PSEnsure)
I have been struggling calling PowerShell Script assets when running PSEnsure Configurations. I have used an example that someone sent to me with some success. I am not able to call multiple script assets, and they refuse to load as PowerShell Modules sometimes for no apparent reasons. I would like to ask for a feature to be added that when you call a PowerShell script asset, to allow it to import for you. I also want to verify I can load multiple Script Assets, as I have tried and not succeeded. I have a great need to reuse code across multiple roles as I have nearly ~100 roles currently.
Example:
##AH:UseTextMode set $ModuleName = Test-Function; Get-Asset $ModuleName.ps1 ( Type: Script ); set $ModuleNamePath = $PathCombine($WorkingDirectory, $ModuleName.ps1); PSEnsure ( Key: Test-Function, Value: True, Collect: "$false", Configure: >> Import-Module -Name "$ModuleNamePath" -Verbose &$ModuleName >> );I would like to see as an option for calling the script asset to load the module automatically. I also want to be able to import Powershell modules in the Collect Phase as well.