Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
I'm trying to write a basic set of checks in Powershell to make sure that any given server isn't pegged on resources. We've had a few times recently where servers hung but didn't get reported to us for a long time which held up processing. What would be the best way to monitor CPU/RAM in a way that won't false-report (mostly)? Basically at the end of it I just need the script to return either "Failure" if a server is pegged for a prolonged period (I used 5 minutes) or "Success" if it's fine (I'm using Write-Host because the result is captured in a log).

This is what I have currently, but I'm sure there's a better method:
code:
Function PollResources ([Collections.Arraylist]$LoadArray) {
	$CPULoads = @((Get-WmiObject win32_processor).LoadPercentage)
	$Repoll = $False
	For ($i = 0; $i -lt $CPULoads.Count; $i++) {
		$CPULoad = $CPULoads[$i]
		if ($CPULoad -gt 95) {
			Write-Host "CPU $i processing capacity at <5% remaining ($CPULoad%).  Repolling in 5 seconds"
			$Repoll = $True
		} else {Write-Host "CPU $i processing capacity normal ($CPULoad%)."}
	}
	$Memory = (GWMI -Class win32_operatingsystem)
	$MemoryUsage = “{0:N2}” -f  $((($Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory) * 100) / $Memory.TotalVisibleMemorySize)
	$TotalMemory = [math]::Round($Memory.TotalVisibleMemorySize/1MB)
	If ($MemoryUsage -gt 95) {
		Write-Host "Memory utilization at <5% remaining ($MemoryUsage% of $TotalMemory GB)."
		$Repoll = $True
	} else {Write-Host "Memory use normal ($MemoryUsage% of $TotalMemory GB)."}
	If ($Repoll) {Write-Host "One or more resources exceeded 95% utilization!  Repolling server resources in 30 seconds..."}
	return $Repoll
}

$Loop = 0
Do {
	If ($Loop -gt 0) {Start-Sleep -s 30; Write-Host ""}
	$Repoll = PollResources
	$Loop++
} While ($Repoll -And $Loop -lt 10)
If ($Loop -eq 10) {
	Write-Host "One or more resources have remained at 95%+ utilization for 5 minutes.  Sending notification."
	Return "Failure"
}
Return "Success"
I'd prefer to collect the various CPU results into an array per processor and RAM to make sure the flags aren't just jumping around, but at the current time I haven't implemented that. Appreciate any suggestions. If anyone would be willing to critique my script that'd be great, I'm still fairly new to PS and always love pointers.

Adbot
ADBOT LOVES YOU

Pile Of Garbage
May 28, 2007



If you're simply trying to determine whether or not a server is responsive then a much better approach is to deploy a heartbeat script that runs on each server as a Scheduled Task and periodically writes to a file on an SMB share. Then you have a separate script on a dedicated monitoring host which parses the files in the SMB share and checks whether a single server has not logged a heartbeat recently.

The general heartbeat function which would run on each server is as follows:

code:
function Write-HeartBeat {
    Param(
        [Parameter(Mandatory=$true)]
        [ValidateScript({ Test-Path -Path $_ -PathType Container })]
        [String]$Path,

        [Parameter()]
        [String]$Name = $env:COMPUTERNAME
    )

    # Write heartbeat file
    Out-File -InputObject (Get-Date).ToString('s') -FilePath (Join-Path -Path $Path -ChildPath $Name) -Force
}
Write-HeartBeat will create a file with the same name as the server in the location specified by $Path and will write the current date+time to the file in ISO 8601 format.

The function which checks the heartbeat files in the SMB share would be like this:

code:
function Read-HeartBeats {
    Param(
        [Parameter(Mandatory=$true)]
        [ValidateScript({ Test-Path -Path $_ -PathType Container })]
        [String]$Path,

        [Parameter(Mandatory=$true)]
        [Int32]$MaxHeartbeatAge
    )

    # Setup return array
    $ReturnArray = @()

    # Iterate through each file in the heartbeat folder
    foreach ($File in (Get-ChildItem -Path $Path -File)) {
        # Retrieve the heartbeat file contents cast as a DateTime
        [DateTime]$LastHearbeat = Get-Content -Path $File.FullName

        # Create a new custom object
        $ReturnObject = New-Object -TypeName System.Object

        # Add NoteProperty members to the return object
        Add-Member -InputObject $ReturnObject -NotePropertyMembers ([ordered]@{
            Server = $File.Name
            LastHeartbeat = $LastHearbeat
            Responding = (Get-Date).Subtract($LastHearbeat).TotalSeconds -lt $MaxHeartbeatAge
        })
        
        # Append the custom object to the return array
        $ReturnArray += $ReturnObject
    }

    # Return the array of objects
    return $ReturnArray
}
Read-HeartBeats will read each file in the heartbeats share and return an array of objects containing the server name, last heartbeat date+time and whether or not the last heartbeat date+time is older than the threshold specified by $MaxHeartbeatAge.

So yeah, implementing a client-side model is much more scalable and if you are trying to identify when servers become unresponsive checking heartbeats in this manner is far more reliable that trying to analyse resource utilisation.

I should note that I just whipped those two functions up now and haven't tested them, let me know if you run into issues.

Pile Of Garbage fucked around with this message at 19:54 on Jan 30, 2018

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

PierreTheMime posted:

I'm trying to write a basic set of checks in Powershell to make sure that any given server isn't pegged on resources. We've had a few times recently where servers hung but didn't get reported to us for a long time which held up processing. What would be the best way to monitor CPU/RAM in a way that won't false-report (mostly)? Basically at the end of it I just need the script to return either "Failure" if a server is pegged for a prolonged period (I used 5 minutes) or "Success" if it's fine (I'm using Write-Host because the result is captured in a log).

This is what I have currently, but I'm sure there's a better method:
code:
Function PollResources ([Collections.Arraylist]$LoadArray) {
	$CPULoads = @((Get-WmiObject win32_processor).LoadPercentage)
	$Repoll = $False
	For ($i = 0; $i -lt $CPULoads.Count; $i++) {
		$CPULoad = $CPULoads[$i]
		if ($CPULoad -gt 95) {
			Write-Host "CPU $i processing capacity at <5% remaining ($CPULoad%).  Repolling in 5 seconds"
			$Repoll = $True
		} else {Write-Host "CPU $i processing capacity normal ($CPULoad%)."}
	}
	$Memory = (GWMI -Class win32_operatingsystem)
	$MemoryUsage = &#147;{0:N2}&#148; -f  $((($Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory) * 100) / $Memory.TotalVisibleMemorySize)
	$TotalMemory = [math]::Round($Memory.TotalVisibleMemorySize/1MB)
	If ($MemoryUsage -gt 95) {
		Write-Host "Memory utilization at <5% remaining ($MemoryUsage% of $TotalMemory GB)."
		$Repoll = $True
	} else {Write-Host "Memory use normal ($MemoryUsage% of $TotalMemory GB)."}
	If ($Repoll) {Write-Host "One or more resources exceeded 95% utilization!  Repolling server resources in 30 seconds..."}
	return $Repoll
}

$Loop = 0
Do {
	If ($Loop -gt 0) {Start-Sleep -s 30; Write-Host ""}
	$Repoll = PollResources
	$Loop++
} While ($Repoll -And $Loop -lt 10)
If ($Loop -eq 10) {
	Write-Host "One or more resources have remained at 95%+ utilization for 5 minutes.  Sending notification."
	Return "Failure"
}
Return "Success"
I'd prefer to collect the various CPU results into an array per processor and RAM to make sure the flags aren't just jumping around, but at the current time I haven't implemented that. Appreciate any suggestions. If anyone would be willing to critique my script that'd be great, I'm still fairly new to PS and always love pointers.
Have you measured what resources this script will use? Also, be careful with the “ and ” double quotes.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Thanks. I think I may be getting a little too in-depth and a heartbeat option is probably fine.

Coredump
Dec 1, 2002

Anyone ever have the -whatif switch still execute the function you're trying to test? I'm writing my first function in powershell, passed the arguments with the -whatif switch and the dang thing still executed.

Zaepho
Oct 31, 2013

Coredump posted:

Anyone ever have the -whatif switch still execute the function you're trying to test? I'm writing my first function in powershell, passed the arguments with the -whatif switch and the dang thing still executed.

You have to build support for whatif into your function. something like the below.
php:
<?
Function Do-Stuff{
[CmdletBinding(SupportsShouldProcess=$true)]
    param([string[]]$Objects)
 
    ForEach($item in $Objects){
        if ($pscmdlet.ShouldProcess("$item", "DoStuff")){
            "Actually performing `$Action on $item"
            }
 
      }
}
?>

Coredump
Dec 1, 2002

Ooooohhhh. poo poo. :downs: Thanks for that, I'll have to look into it.

Dr. Arbitrary
Mar 15, 2006

Bleak Gremlin
I think that Briantist was lobbying Microsoft to make -whatif work in a safer and more intuitive way or something a ways back.

Coredump
Dec 1, 2002

I'll admit up front what I'm trying to do is probably not the best way of doing things but work wants us to remove people from distribution groups that handle shared inbox permissions and add people directly to shared inboxes within office 365. Here's what I've come up with so far. I would welcome a sanity check.

code:
function RemoveSharedInboxDG ($mboxName,$groupName) {
# Adding group rights to a mailbox
 if (-not(get-variable groupName,mboxName)) {
  write-host -foregroundcolor yellow -backgroundcolor black "Syntax:  Add-MailboxRights MailboxName GroupName"
  break
 }
$groupMembers = get-distributiongroupmember -Identity $groupName
 	echo "Users in this group:  $groupMembers.alias"
 foreach ($groupMember in $groupMembers){
 	echo "Adding Full Access and Send As permissions for each dgmember to shared mailbox"
  Add-MailboxPermission -Identity $mboxName -user $groupMember.alias -accessrights fullaccess -inheritancetype all
  Add-RecipientPermission -Identity $mboxName -Trustee $groupMember.alias -AccessRights SendAs -confirm:$false
}
 	echo "Removing distribution group"
 remove-distributiongroup $groupName -Confirm:$False
 }

Pile Of Garbage
May 28, 2007



Dr. Arbitrary posted:

I think that Briantist was lobbying Microsoft to make -whatif work in a safer and more intuitive way or something a ways back.

IDK what idiot you're talking about but they didn't do poo poo because I've used plenty of first party cmdlets that "support" WhatIf but still just go and do their poo poo anyway.

Coredump posted:

I'll admit up front what I'm trying to do is probably not the best way of doing things but work wants us to remove people from distribution groups that handle shared inbox permissions and add people directly to shared inboxes within office 365. Here's what I've come up with so far. I would welcome a sanity check.

That's an exceptionally hosed situation but still do-able. I didn't read what you posted but it'll probably work? Just test it in your own environment. You may want to push back hard on their reasoning for taking such an approach. If they have issues with reporting for compliance purposes then explain to them that perhaps you can work on those issues instead of reconfiguring everything.

Edit: for the record I've implemented some extremely greasy hacks when it comes to O365 and Exchange hybrid. With EXO and AAD PowerShell the skies the limit really and you can implement a lot of crazy poo poo. Replicating on-premises distribution group members to EXO distribution group members? Yeah I thought on that recently and it's easy as piss. But it's turbo-hosed and would break with the slightest change by MSFT on the backend.

Pile Of Garbage fucked around with this message at 21:21 on Feb 9, 2018

Dr. Arbitrary
Mar 15, 2006

Bleak Gremlin

I think this is what I was misremembering.

thebigcow
Jan 3, 2001

Bully!
Wasn't(Isn't?) whatif broken entirely for the active directory cmdlets?

nielsm
Jun 1, 2009



I'm using New-ADGroup -WhatIf regularly as part of a script, works fine.

Potato Salad
Oct 23, 2014

nobody cares


PierreTheMime posted:

I'm trying to write a basic set of checks in Powershell to make sure that any given server isn't pegged on resources. We've had a few times recently where servers hung but didn't get reported to us for a long time which held up processing. What would be the best way to monitor CPU/RAM in a way that won't false-report (mostly)? Basically at the end of it I just need the script to return either "Failure" if a server is pegged for a prolonged period (I used 5 minutes) or "Success" if it's fine (I'm using Write-Host because the result is captured in a log).

This is what I have currently, but I'm sure there's a better method:
code:
Function PollResources ([Collections.Arraylist]$LoadArray) {
	$CPULoads = @((Get-WmiObject win32_processor).LoadPercentage)
	$Repoll = $False
	For ($i = 0; $i -lt $CPULoads.Count; $i++) {
		$CPULoad = $CPULoads[$i]
		if ($CPULoad -gt 95) {
			Write-Host "CPU $i processing capacity at <5% remaining ($CPULoad%).  Repolling in 5 seconds"
			$Repoll = $True
		} else {Write-Host "CPU $i processing capacity normal ($CPULoad%)."}
	}
	$Memory = (GWMI -Class win32_operatingsystem)
	$MemoryUsage = &#8220;{0:N2}&#8221; -f  $((($Memory.TotalVisibleMemorySize - $Memory.FreePhysicalMemory) * 100) / $Memory.TotalVisibleMemorySize)
	$TotalMemory = [math]::Round($Memory.TotalVisibleMemorySize/1MB)
	If ($MemoryUsage -gt 95) {
		Write-Host "Memory utilization at <5% remaining ($MemoryUsage% of $TotalMemory GB)."
		$Repoll = $True
	} else {Write-Host "Memory use normal ($MemoryUsage% of $TotalMemory GB)."}
	If ($Repoll) {Write-Host "One or more resources exceeded 95% utilization!  Repolling server resources in 30 seconds..."}
	return $Repoll
}

$Loop = 0
Do {
	If ($Loop -gt 0) {Start-Sleep -s 30; Write-Host ""}
	$Repoll = PollResources
	$Loop++
} While ($Repoll -And $Loop -lt 10)
If ($Loop -eq 10) {
	Write-Host "One or more resources have remained at 95%+ utilization for 5 minutes.  Sending notification."
	Return "Failure"
}
Return "Success"
I'd prefer to collect the various CPU results into an array per processor and RAM to make sure the flags aren't just jumping around, but at the current time I haven't implemented that. Appreciate any suggestions. If anyone would be willing to critique my script that'd be great, I'm still fairly new to PS and always love pointers.

Frankly, the most reliable way to do this might be on an ancient tech, SNMP.

I've never checked whether server core has the windows SNMP client available.

Potato Salad
Oct 23, 2014

nobody cares


If it matters to you, using the SNMP client is way, way lighter than polling wmi.

hihifellow
Jun 17, 2005

seriously where the fuck did this genre come from

thebigcow posted:

Wasn't(Isn't?) whatif broken entirely for the active directory cmdlets?

Set-ADAccountPassword ignores -WhatIf . That was a fun one to find out, thank god that script worked right the first time.

Supposedly fixed in Server 2016 and its RSAT.

Eschatos
Apr 10, 2013


pictured: Big Cum's Most Monstrous Ambassador
My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder...

code:
get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath 
or the folders containing at least one file modified in the last hour have their entire contents backed up, not just the files modified in the last hour.

code:
 get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath  -Recurse -Container 
Yall know a technique to get the full folder structure, but only the recently modified files?

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

Eschatos posted:

My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder...

code:
get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath 
or the folders containing at least one file modified in the last hour have their entire contents backed up, not just the files modified in the last hour.

code:
 get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath  -Recurse -Container 
Yall know a technique to get the full folder structure, but only the recently modified files?
Why can't you turn on volume shadow copy?

Eschatos
Apr 10, 2013


pictured: Big Cum's Most Monstrous Ambassador

anthonypants posted:

Why can't you turn on volume shadow copy?

Originally the requirement was to run the backup every 15 minutes, and I'm half expecting it to revert to that.

nielsm
Jun 1, 2009



Volume shadow copy on the file server gives you instant-to-take snapshots of the entire file system, and lets you/users restore files directly from File Explorer. It's the best thing ever for getting out of "oops data gone" situations.
It's called Previous Versions in File Explorer.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Eschatos posted:

My boss has asked me to help protect people from their own mistakes by setting up hourly backups for our file server to supplement the usual daily backup. I've successfully been able to test a script to back up all files modified in the last hour. The one problem is that I haven't been able to figure out how to replicate the folder structure properly for files backed up. Either everything gets dumped in one single folder...

code:
get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath 
or the folders containing at least one file modified in the last hour have their entire contents backed up, not just the files modified in the last hour.

code:
 get-childitem -path $FileserverPath -recurse | where-object {$_.LastWriteTime -gt $comparedate } | copy-item -destination $fullBackupPath  -Recurse -Container 
Yall know a technique to get the full folder structure, but only the recently modified files?

This is a solved problem; RoboCopy ships with the OS.

Pile Of Garbage
May 28, 2007



New Yorp New Yorp posted:

This is a solved problem; RoboCopy ships with the OS.

Basically this. Alternatively, get actual backup software?

Eschatos
Apr 10, 2013


pictured: Big Cum's Most Monstrous Ambassador

New Yorp New Yorp posted:

This is a solved problem; RoboCopy ships with the OS.

Robocopy was the first way I tried, but the /MAXAGE flag only can filter by individual days, not by hours.

The Fool
Oct 16, 2003


Eschatos posted:

Originally the requirement was to run the backup every 15 minutes, and I'm half expecting it to revert to that.

Shadow Copies can be run as often as you want, and they are the solution you should be using instead of kludging together a script that will break when you need it most.

Eschatos
Apr 10, 2013


pictured: Big Cum's Most Monstrous Ambassador

The Fool posted:

Shadow Copies can be run as often as you want, and they are the solution you should be using instead of kludging together a script that will break when you need it most.

The shadow copy configuration screen explicitly states not to run it more than once per hour. But ok, I see your point. In any case this isn't some business critical functionality, it's a more-frequent supplement to our existing daily backup scheme so that we can occasionally save the day after someone deletes files they shouldn't have. I'll stick to hourly volume shadow copies for the time being.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
What would you all consider the "best" SFTP module/implementation for Powershell? I'm working with some file automation and the current method is a bit clunky and could work better if I could step things in code to better allow for errors and such.

Pile Of Garbage
May 28, 2007



Can you not just use SMB instead? Is there a specific reason that you need to use SFTP?

Potato Salad
Oct 23, 2014

nobody cares


Posh-SSH is useful.

Collateral Damage
Jun 13, 2009

cheese-cube posted:

Can you not just use SMB instead? Is there a specific reason that you need to use SFTP?
SMB across the internet is kind of iffy. :v:

Pile Of Garbage
May 28, 2007



No one said internet.

MC Fruit Stripe
Nov 26, 2002

around and around we go

cheese-cube posted:

No one said internet.
You just did, now we need to consider it

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

cheese-cube posted:

No one said internet.

This would be to access files on a remote network, yes.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum
Is there a way to use a specific cmdlet in a specific module? Like how Get-Cluster exists in both VMware's PowerCLI and Microsoft's Failover Cluster modules, or how Get-VMHost exists in both VMware's PowerCLI and Microsoft's Hyper-V modules. The existing workaround is to just run Remove-Module for the one you don't want and/or Import-Module for the one you do, which I guess works, but imo if it would be great if I could just specify which one I want without having to worry about that.

The Fool
Oct 16, 2003


You should be able to specify the module namespace by typing ModuleName\CmdLetName

ie, "ActiveDirectory\Get-Aduser" and "Get-AdUser" are the same

The other option may be to pass session objects around.

I don't have the vmware modules to be able to verify your specific use case though.

nielsm
Jun 1, 2009



https://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx talks about exactly that problem, you can specify a prefix in Import-Module that gets appended to the noun part:

Import-Module Hyper-V -Prefix Hv
Import-Module VMware.VimAutomation.Core -Prefix Vmw

That should get you commands named Get-HvVMHost and Get-VmwVMHost instead.

^^^ but that module "namespace" prefix sounds like a perhaps better solution.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

The Fool posted:

You should be able to specify the module namespace by typing ModuleName\CmdLetName

ie, "ActiveDirectory\Get-Aduser" and "Get-AdUser" are the same

The other option may be to pass session objects around.

I don't have the vmware modules to be able to verify your specific use case though.
Yeah, this totally works:
code:
PS C:\Windows\system32> failoverclusters\Get-Cluster
WARNING: If you are running Windows PowerShell remotely, note that some failover clustering cmdlets do not work remotely. When possible, run the cmdlet locally and specify a remote computer as the target.
 To run the cmdlet remotely, try using the Credential Security Service Provider (CredSSP). All additional errors or warnings from this cmdlet might be caused by running it remotely.
failoverclusters\Get-Cluster : The cluster service is not running.  Make sure that the service is running on all nodes in the cluster.
    There are no more endpoints available from the endpoint mapper
At line:1 char:1
+ failoverclusters\Get-Cluster
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (:) [Get-Cluster], ClusterCmdletException
    + FullyQualifiedErrorId : ClusterEndpointNotRegistered,Microsoft.FailoverClusters.PowerShell.GetClusterCommand

PS C:\Windows\system32> vmware.powercli\Get-Cluster
WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a better product. You can join using the following command:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to improve its products and services, to fix problems, and to advise you on how best to deplo
y and use our products.  As part of the CEIP, VMware collects technical information about your organization’s use of VMware products and services on a regular basis in association with your organization’s
 VMware license key(s).  This information does not personally identify any individual.

For more details: type "help about_ceip" to see the related help article.

To disable this warning and set your preference use the following command and restart PowerShell: 
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
vmware.powercli\Get-Cluster : The module 'vmware.powercli' could not be loaded. For more information, run 'Import-Module vmware.powercli'.
At line:1 char:1
+ vmware.powercli\Get-Cluster
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (vmware.powercli\Get-Cluster:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

nielsm posted:

https://mcpmag.com/articles/2013/08/20/powershell-name-duplicates.aspx talks about exactly that problem, you can specify a prefix in Import-Module that gets appended to the noun part:

Import-Module Hyper-V -Prefix Hv
Import-Module VMware.VimAutomation.Core -Prefix Vmw

That should get you commands named Get-HvVMHost and Get-VmwVMHost instead.

^^^ but that module "namespace" prefix sounds like a perhaps better solution.
And I had no idea this existed either, but this is also cool.

The Fool
Oct 16, 2003


Is anyone aware of a better way to put a GUI wrapper around a powershell script? Even with poshgui.com, WinForms is a total loving nightmare.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

The Fool posted:

Is anyone aware of a better way to put a GUI wrapper around a powershell script? Even with poshgui.com, WinForms is a total loving nightmare.
Port your script to C#?

mystes
May 31, 2006

anthonypants posted:

Port your script to C#?
Unfortunately this is probably literally the easiest way.

If you're determined you can use vs to generate C# and rewrite it in powershell, or just use the c# from powershell but it's probably not worth the trouble.

I guess if you already have a complete script and just want a UI for it you could also run the powershell script from c#.

But basically everything is going to be more trouble than just rewriting it in c#.

Adbot
ADBOT LOVES YOU

Pile Of Garbage
May 28, 2007



anthonypants posted:

Port your script to C#?

Seconding this. Developing GUIs with PowerShell is dirty and IMO completely antithetical to how PowerShell is designed to be used.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply