Hey guys,
I actually have a problem with writing a Script to shutdown a Datacore Server.
First of all I have to say I even started writing Scripts for Powershell.
So I don't really understand all the "functions" of Powershell Scripting.
Because of that I ask for your help because learning by doing didn't solve my Problem.
Here is the Problem:
In case of a Powerfailure we want to shut down the Servers smoothly.
In a normal case of Maintenance we connect remote to the Server and do the following Tasks:
Connect remote to the Datacore Server
Open the SANsymphonie Console and stop the Datacore Service
Afterwards we can shut down or restart the Server.
When the Server comes up again we restart the Datacore Service and the Mirroring is done in a few Seconds.
For this SANsymphonie offers a Skript which opens imports the Commandlets for Datacore (RegisterDcsCmdlets.ps1).
In PS you are afterwards can connect to the Datacore Server
Connect-DcsServer -Server <Servername> -UserName <User> -Password <myPassword> -Connection SSV1Connect
and stop the Service
(Stop-DcsServer -Server <Servername>)
This works!
What I want to do is to do these Steps in one PS1 which afterwards also shuts down the Server.
How can I do that?
Kind regards
André
Here the content of RegisterDcsCmdlets.ps1
param([ScriptBlock]$scriptBlock, [switch]$forceExit, [string[]]$params)
$configurationPath = $Env:TEMP | Join-Path -ChildPath ([Guid]::NewGuid())
New-Item -Path $configurationPath -ItemType Container > $null
@"
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
"@ | Set-Content -Path $configurationPath\powershell.exe.activation_config -Encoding UTF8
$envVariableName = 'COMPLUS_ApplicationMigrationRuntimeActivationConfigPath'
$envVariableOld = [Environment]::GetEnvironmentVariable($envVariableName)
[Environment]::SetEnvironmentVariable($envVariableName, $configurationPath)
$importCmdletBlock = {
$bpKey = 'BaseProductKey'
$regKey = get-Item "HKLM:\Software\DataCore\Executive"
$strProductKey = $regKey.getValue($bpKey)
$regKey = get-Item "HKLM:\$strProductKey"
$installPath = $regKey.getValue('InstallPath')
Import-Module "$installPath\DataCore.Executive.Cmdlets.dll" -DisableNameChecking -ErrorAction Stop
Write-Host "Successfully registered SANsymphony-V Cmdlets for Windows PowerShell."
}
try
{
Cls
}
catch
{
# Nothing to do. This will throw an exception only when it is called
# without a console.
}
try
{
if ($scriptBlock -ne $null)
{
$finalBlockString = $importCmdletBlock.ToString() + "`n" + $scriptBlock.ToString()
$finalBlock = [scriptblock]::Create($finalBlockString)
if ($forceExit)
{ & powershell.exe -Command $finalBlock -args $params}
else
{ & powershell.exe -NoExit -Command $finalBlock -args $params }
}
else
{
& powershell.exe -Command $importCmdletBlock -NoExit
}
}
finally
{
[Environment]::SetEnvironmentVariable($envVariableName, $envVariableOld)
$configurationPath | Remove-Item -Recurse
}