Need Helping Editing Perl Script for PowerChute Network Shutdown - perl

I found the perl script on the vmware community. The problem is that within APC's PCNS it will not let you specify parameters to run with the script.
The script requires calling on a host-list file Usage: ./shutdownHostViaSOAPAPICall.pl [HOST_FILE]
So I would like to add the hosts I want to shutdown directly into the script instead of having to call a hostlist file.
Can anyone help with this? Here is the Vsphere thread for reference. And so that you can download the script.
https://communities.vmware.com/docs/DOC-11623
Thanks

Replace
my $host_username = 'fillmein';
my $host_password = 'fillmein';
#### DO NOT EDIT PAST HERE ####
my #hostlist;
my ($file,$request,$message,$response,$retval,$cookie);
&verifyUserInput();
&processFile($file);
With
my $host_username = 'yourusername';
my $host_password = 'yourpass';
#### DO NOT EDIT PAST HERE ####
my #hostlist = ("host1.somedomain", ""hostx.somedomain"");
my ($file,$request,$message,$response,$retval,$cookie);
#&verifyUserInput();
#&processFile($file);
I only have 1 host at each site to shut down so this is a clean solution for me.

Related

Need assistance modifying a PowerCLI script

I was wondering if someone could please help with the following query. We are using the following script to enable Virtualization Based Security on a per VM level.
https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Turn-on-Virtualization-based-security-...
The script is running from within VMware Realize Automation / Orchestration in order to enable VBS as part of an specific workflow. The modified script for vRA/vRO is below.
The issue that I am having is that VBS can only be enabled when the VM is powered off, in some cases the workflow takes a little longer to run and by then the VM is running already which will make the task (script) to fail.
That being said, I was looking for some way to improve the script a little bit perhaps by adding something to power off the VM if it's running then execute the code in the script and then bring the VM back on. I feel that with something like this hopefully we will make sure that VBS is enabled when the VM is not running and once VBS is enabled it will turn on the VM to proceed. I have unsuccessfully tried to modify the code but I can't find a way to stop and start the VM successfully. Can someone please help?
Thank you
// Input: inputProperties from vRA
var enableVBS = inputProperties.customProperties.enableVBS
if (enableVBS == "true") {
var name = inputProperties.resourceNames[0]
var vms = VcPlugin.getAllVirtualMachines(null, name)
vm = vms[0]
var bootOpts = new VcVirtualMachineBootOptions()
var flags = new VcVirtualMachineFlagInfo()
var spec = new VcVirtualMachineConfigSpec()
bootOpts.efiSecureBootEnabled = true;
flags.vbsEnabled = true;
flags.vvtdEnabled = true;
spec.firmware = VcGuestOsDescriptorFirmwareType.efi;
spec.nestedHVEnabled = true;
spec.bootOptions = bootOpts;
spec.flags = flags;
vm.reconfigVM_Task(spec)
}

OnedriveMapper.ps1 4.04 script is showing network drive

I am using famous Onedrivemapper version 4.04 powershell script from https://gitlab.com/Lieben/OnedriveMapper_V3/-/blob/master/OneDriveMapper.ps1
This is basically used for adding Sharepoints as network drive. when I mention my sharepoint link in the script and run, it shows that the drive is mapped but the drive is not showing in my machine.
The issue is the "...DavWWWRoot\\teamsite..." double backslash, therefor the net use command throws an error.
Add this to line 608 of his 4.04 script and it should work:
$driveMapping.webDavPath = $driveMapping.webDavPath.Replace('DavWWWRoot\\', 'DavWWWRoot\')
Your code should look like this:
.........
function MapDrive{
Param(
$driveMapping
)
$driveMapping.webDavPath = $driveMapping.webDavPath.Replace('DavWWWRoot\\', 'DavWWWRoot\')
if($driveMapping.targetLocationType -eq "driveletter"){
.........
I know it's dirty, but I didn't want to go through 3000 lines of code to solve this

capistrano upload! thinks ~ referenced local directory is on remote server

So every example I've looked up indicates this is how one is supposed to do it but I think I may have found a bug unless there's another way to do this.
I'm using upload! to upload assets to a remote list of servers. The task looks like this:
desc "Upload grunt compiled css/js."
task :upload_assets do
on roles(:all) do
%w{/htdocs/css /htdocs/js}.each do |asset|
upload! "#{fetch(:local_path) + asset}", "#{release_path.to_s + '/' + asset}", recursive: true
end
end
end
If local_path is defined as an absolute path such as:
set :local_path:, '/home/dcmbrown/projects/ABC'
This works fine. However if I do the following:
set :local_path:, '~/projects/ABC'
I end up getting the error:
The deploy has failed with an error: Exception while executing on ec2-54-23-88-125.us-west-2.compute.amazon.com: No such file or directory - ~/projects/ABC/htdocs/css
It's not a ' vs " issue as I've tried both (and I didn't think capistrano paid attention to that anyway).
Is this a bug? Is there a work around? Am I just doing it wrong?
I ended up discovering the best way to do this is to actually use path expansion! (headsmack)
irb> File.expand_path('~dcmbrown/projects/ABC')
=> "/home/dcmbrown/projects/ABC"
Of course what I'd like is to do automatic path expansion but you can't have everything. I think I was mostly dumbstruck that it didn't automatically; so much so I spent a couple of hours trying to figure out why it didn't work and ended up wasting time asking here. :(
I don't think the error is coming from the remote server, it just looks like it since it's running that upload command in the context of a deploy.
I just created a single cap task to just do an upload using the "~" character and it also fails with
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#XXX: No such file or directory # rb_file_s_stat - ~/Projects/testapp/public/404.html
It appears to be a Ruby issue not Capistrano as this also fails in a Ruby console
~/Projects/testapp $ irb
2.2.2 :003 > File.stat('~/Projects/testapp/public/404.html')
Errno::ENOENT: No such file or directory # rb_file_s_stat - ~/Projects/testapp/public/404.html
from (irb):3:in `stat'
from (irb):3
from /Users/supairish/.rvm/rubies/ruby-2.2.2/bin/irb:11:in `<main>'

Gitblit services not started

After the execution of batch file in Gitblit, gitblit service won't start.
Install Java 7
Install Gitblit GO in Win 7 - 64 bit machine
Goto service and view the service status.
Win 7 - gitblit GO-1.3.2 - jdk-7u51-windows-x64
gitblit service is required to open the gitblit in browser?
Based on this following site, i exected the gitblit batch files.
http://gitblit.com/setup_go.html
Kindly let me know, what else i need to do.
Regards,
Sathishkumar Pannerselvam
Service isn't required to start Gitblit.
On Windows Envrionnement : you can use the batch script gitblit.cmd to start it. But don't forget the configuration's step in the file gitblit.properties (server.httpPort...). After you can access Gitblit with this url http:\localhost:8080
I encountered a similar problem.
But I solved as follows:
Open installService.cmd with text editor like notepad.
In line 12, I changed SET ARCH=amd64 into SET ARCH=x86. (The architecture of my computer is x86.)
Run installService.cmd by double-clicking it or run installService in Command Prompt.
CD may not be found .Try to add CD definition:
#REM arch = x86, amd64, or ia32
SET ARCH=amd64
SET CD=E:/gitblit-1.8.0
It may work.

Powershell remoting and page file

I wrote a powershell script that connects to a remote machine with the intent of executing a software rollout on said machine. Basically it connects, maps a drive, copies the rollout from the mapped drive to the target machine, then executes a perl script to install the rollout. If I do those steps manually everything works fine. When I try using my script, the perl script fails on the remote machine saying, "The paging file is too small for this operation to complete".
Can someone explain the considerations I need to take into account when operating remotely? I've tried monitoring memory usage and I don't see anything out of the ordinary. Is the page file OS wide or is there some type of per user configuration my script should be setting when it connects?
I can post snippets of my script if needed, but the script is 426 lines so I think it would be overwhelming to post in its entirety.
I found that the remote shells are managed differently than logging onto the box and executing a powershell session. I had to increase the maximum amount of memory available using one of the commands below:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024
winrm set winrm/config #{MaxMemoryPerShellMB="1024"}
The default is 150MB which didn't cut it in my case. I can't say that I recommend 1GB, I'm just a developer. I tried upping it until I found what worked for me.
I tried this code to run the puppet client as an administrator but the framework still complains with "Access Denied"
Exe (C:\Users\lmo0\AppData\Local\Temp\Microsoft .NET Framework 4 Setup_4.0.30319\Windows6.1-KB958488-v6001-x64.msu) failed with 0x5 - Access is denied. .
using System;
using System.Diagnostics;
namespace RunAsAdmin
{
class Program
{
static void Main(string[] args)
{
Process proc = new Process();
Process p = new Process();
p.StartInfo.FileName = #"powershell.exe";
p.StartInfo.Arguments = #"invoke-command -computername vavt-pmo-sbx24 -ScriptBlock {&'C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat' agent --test --no-daemonize --verbose --logdest console}";
p.StartInfo.Verb = "runas";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
while (p.HasExited == false) {
Console.WriteLine(p.StandardOutput.ReadLine());
}
Console.ReadLine();
p.WaitForExit();
p.Close();
}
}
}