How do you use move-resourcepool? - powercli

I run:
Move-ResourcePool -ResourcePool testresource -Destination myhost.mydomain.com
And get:
Move-ResourcePool : Cannot bind parameter 'Destination' to the target.
Exception setting "Destination": "Unable to cast object of type VMware.VimAutomation.ViCore.Util10.Surrogate.DefaultValue.StringWrapperResourcePool' to type 'VMware.VimAutomation.ViCore.Interop.V1.Inventory.VIContainerInterop'."

Maybe it breaks trying to translate your -Destination string into an object. Curious if this works any better?
Move-ResourcePool -ResourcePool testresource -Destination (Get-VMHost myhost.mydomain.com)

Related

List location of executables within the CTest test suite

I have some source code that is compiled using CMake, with unit tests that are added to CTest via the CMake directive add_test(). I want the list of executables (absolute/relative path) that are used within this test suite.
Since tests are added as follows:
add_test(NAME ${A} COMMAND ${execA})
add_test(NAME ${B} COMMAND ${execB})
add_test(NAME ${C} COMMAND ${execA} ${addOptions})
there are only two distinct executables (${execA}, ${execB}) for three tests (${A}, ${B}, and ${C}).
I am totally fine having duplicates and ignoring options or having options.
So, the ideal output would be the following (but I certainly can do some parsing manually if needed):
src/folder1/test/testThisFunction
src/folder2/test/testThatFunction
src/folder1/test/testThisFunction -WithThisFlag
The closest I was able to get was with:
ctest -N,--show-only
which does not run the tests, but simply shows them:
Start 1: testA
1/3 Test #1: testA ....................... Passed 0.01 sec
Start 2: testB
2/3 Test #2: testB ....................... Passed 0.01 sec
Start 3: testC
3/3 Test #3: testC ........................ Passed 0.01 sec
Unfortunately, this output does not contain the information about the path to the executable.
In this example above, it is assumed that
${execA} = testThisFunction
${execB} = testThatFunction
where testThisFunction and testThatFunction are CMake targets (unit tests) and
${A} = "testA"
${B} = "testB"
${C} = "testC"
${addOptions} = "-WithThisFlag"
store names of the tests and options, respectively.
While I have the access to CMakeLists.txt, I strongly prefer to do this solely on ctest level after CMake configuring and subsequent compilation are already completed (thus, not generating list of executables using CMake commands in CMakeLists.txt).
If this is relevant, I am using CTest 3.10.2, but open to upgrade.
Firstly, you only need the -N or the --show-only option in the ctest command, not both. In your case, CTest silently ignored your command line option -N,--show-only because it was not recognized. The output indicates that your tests did run. To simply list them, use:
ctest --show-only
Getting to your question: If you upgrade to CMake 3.14 or higher, you gain the JSON-formatted ctest --show-only option.
ctest --show-only=json-v1
This will print information about each of your tests, including the arguments passed to each. Your output from this may contain something like this:
"tests" :
[
{
"backtrace" : 1,
"command" :
[
"src/folder1/test/testThisFunction"
],
"config" : "Debug",
"name" : "testA",
"properties" :
[
{
"name" : "WORKING_DIRECTORY",
"value" : "src"
}
]
},
{
"backtrace" : 3,
"command" :
[
"src/folder2/test/testThatFunction"
],
"config" : "Debug",
"name" : "testB",
"properties" :
[
{
"name" : "WORKING_DIRECTORY",
"value" : "src"
}
]
},
{
"backtrace" : 5,
"command" :
[
"src/folder1/test/testThisFunction",
"-WithThisFlag"
],
"config" : "Debug",
"name" : "testC",
"properties" :
[
{
"name" : "WORKING_DIRECTORY",
"value" : "src"
}
]
}
],
In the output, the full path to the executable and the test's command line arguments are listed after "command" :.

Use PowerShell To Enable TCP/IP in SQL Server Configuration Manager

My company sells/supports a product that utilizes a SQL database. I've been trying to create a PowerShell script to prep the entire server for a new install. The script needs to install all the required Windows Server Roles/features, then install SQL, then SQL Server Management Studio, and finally, Enable TCP/IP for SQL. I have gotten all but the last step to work, and trying to figure this one out is kicking my butt...
I feel like I'm on the right path here, but I'm currently stuck...
If I run:
$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer')
$wmi
I actually get results showing:
ConnectionSettings :
Microsoft.SqlServer.Management.Smo.Wmi.WmiConnectionInfo
Services : {MSSQL$WEBACCESS, MSSQLFDLauncher$WEBACCESS,
SQLAgent$WEBACCESS, SQLBrowser}
ClientProtocols : {np, sm, tcp}
ServerInstances : {SQLSERVER}
ServerAliases : {}
Urn : ManagedComputer[#Name='HOSTNAME']
Name : HOSTNAME
Properties : {}
UserData :
State : Existing
I'm then using this information and running:
$uri = "ManagedComputer[#Name='']/ ServerInstance[#Name='']/ServerProtocol[#Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp
With this, I get the following error:
Exception calling "GetSmoObject" with "1" argument(s): "Attempt to retrieve data for object failed for ManagedComputer 'HOSTNAME'."
At line:9 char:1
+ $Tcp = $wmi.GetSmoObject($uri)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : FailedOperationException
Anybody have any idea what I'm doing wrong? I feel like, if I can figure this part out, I can figure out how to alter the settings, but I can't even pull up the settings at this point.
You should consider looking at dbatools, a PowerShell module written by SQL Server and PowerShell MVPs with hundreds of really useful functions for managing SQL Server.
I thought they might have a function that does what you need already. It looks like they don't, but in searching I had a look at Set-DbaTcpPort, and finally at the source code for that function on GitHub, where I saw this code snippet:
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $instance
$wmiinstance = $wmi.ServerInstances | Where-Object { $_.Name -eq $wmiinstancename }
$tcp = $wmiinstance.ServerProtocols | Where-Object { $_.DisplayName -eq 'TCP/IP' }
$IpAddress = $tcp.IpAddresses | where-object { $_.IpAddress -eq $IpAddress }
$tcpport = $IpAddress.IpAddressProperties | Where-Object { $_.Name -eq 'TcpPort' }
So that led me to conclude that you could do the same with your object; your $wmi object seems to be the same as their $wmiinstance object even if you arrived at them slightly differently.
From there you can query with Where-Object or the .Where method:
$tcp = $wmi.ClientProtocols.Where({$_.DisplayName -eq 'TCP/IP'})

Terraform template_file get pass all received variables to a function

is there in Terraforom in template_files a way to pass through all the received variables to other place?
I mean something similar than $# in bash.
For example:
resource "template_file" "some_template" {
template = "my_template.tpl")}"
vars {
var1 = "value1"
var2 = "value2"
}
}
and then from the rendered file:
#!/bin/bash
echo "Var1: ${var1}"
echo "Var2: ${var2}"
echo "But I want it in someway similar to this:"
for v in $#; do
echo "$v";
done
According to the documentation, no.
From https://www.terraform.io/docs/providers/template/d/file.html
Variables for interpolation within the template. Note that variables
must all be primitives. Direct references to lists or maps will cause
a validation error.
Primitives in terraform are string, number and boolean.
So it means you can not pass a hash or a list to group all the variables in one.
Use join and pass all the variables as one and parse/split them within a script (with tr/IFS tricks)
join("; ", [var.myvar1, var.myvar2, var.myvar3])
and then
IN="${allvars}"
IFS=';' read -ra ADDR <<< "$IN"
for i in "${ADDR[#]}"; do
echo "$i"
done

Saving Warnings to a variable in powershell

So what I'm trying to do is this
$corruptAccounts = Get-Mailbox | select-string -pattern WARNING
The intent is to fill the variable $corruptAccounts with the warnings from Get-Mailbox. What actually happens is it processes the Get-Mailbox command, displaying the warnings, and puts nothing into the variable.
I'm new to powershell so I'm still trying to learn some of the basics.
Try this:
Get-MailBox -WarningVariable wv
$wv
-WarningVariable is a common parameter available for all advanced functions and binary cmdlets.
Here is a generic example:
Function TestWarning {
[CmdletBinding()]
param (
)
Write-Warning "This is a warning"
}
PS C:\> TestWarning -WarningVariable wv
WARNING: This is a warning
PS C:\> $wv
This is a warning
You can try this:
[System.Collections.ArrayList]$var = #();
Get-Mailbox -WarningVariable +var -ResultSize unlimited
$buf = Get-Mailbox 2>&1 | Out-String
Will add warnings to $buf at front

How to set default values for Tcl variables?

I have some Tcl scripts that are executed by defining variables in the command-line invocation:
$ tclsh84 -cmd <script>.tcl -DEF<var1>=<value1> -DEF<var2>=<value2>
Is there a way to check if var1 and var2 are NOT defined at the command line and then assign them with a set of default values?
I tried the keywords global, variable, and set, but they all give me this error when I say "if {$<var1>==""}": "can't read <var1>: no such variable"
I'm not familiar with the -def option on tclsh.
However, to check if a variable is set, instead of using 'catch', you can also use 'info exist ':
if { ![info exists blah] } {
set blah default_value
}
Alternatively you can use something like the cmdline package from tcllib. This allows you to set up defaults for binary flags and name/value arguments, and give them descriptions so that a formatted help message can be displayed. For example, if you have a program that requires an input filename, and optionally an output filename and a binary option to compress the output, you might use something like:
package require cmdline
set sUsage "Here you put a description of what your program does"
set sOptions {
{inputfile.arg "" "Input file name - this is required"}
{outputfile.arg "out.txt" "Output file name, if not given, out.txt will be used"}
{compressoutput "0" "Binary flag to indicate whether the output file will be compressed"}
}
array set options [::cmdline::getoptions argv $sOptions $sUsage]
if {$options(inputfile) == ""} {puts "[::cmdline::usage $sOptions $sUsage]";exit}
The .arg suffix indicates this is a name/value pair argument, if that is not listed, it will assume it is a binary flag.
You can catch your command to prevent error from aborting the script.
if { [ catch { set foo $<var1> } ] } {
set <var1> defaultValue
}
(Warning: I didn't check the exact syntax with a TCL interpreter, the above script is just to give the idea).