SAPIEN Forums » PowerShell
197 FOLLOWERS
Since 1990, SAPIEN Technologies has produced information technology and software solutions that make a difference. Today, we're focused on making IT easier, through a best-in-class suite of solutions that include software, training, publishing, and community. This section of the forum is a place to discuss PowerShell.
SAPIEN Forums » PowerShell
9M ago
I am starting to move away from the soon to be deprecated powershell module for Azure (AZ - ie. connect-msolservice etc) and use the MS Graph API
When coding in Sapien Powershell Studio, it doesn't recognise these commands and there's no inline help for this (hover over the command and it states "unknown connect-mggraph").
Is there a way to import the module(s) into Sapien?
Using the Powershell ISE works fine so I assume I have to import the commands somehow in to Sapien?
Thanks
G
Statistics: Posted by GNS_Licenses — July 26th, 2023, 4:06 am ..read more
SAPIEN Forums » PowerShell
10M ago
Thank you Alexander & JVierra for your assistance
Statistics: Posted by Woody_033 — July 19th, 2023, 5:52 am ..read more
SAPIEN Forums » PowerShell
10M ago
The pipeline was designed t handle all returns. It can return null, a singularity or a collection. Collections are enumerated into the pipeline. This is the recommended method.
Another technique is to "cast" the return to an array.
[$mgmtsObjects = [array](Get-WmiObject ....)
Now your result will always be of the same type.
Statistics: Posted by jvierra — July 19th, 2023, 1:53 am ..read more
SAPIEN Forums » PowerShell
10M ago
You haven't avoided yet that $PowerOn can have a different type. You cannot simply cast your way out of this.
function DoSomething($PowerOnObject)
{
#process your object
}
$WMIReturn = Get-WmiObject MSPower_DeviceEnable -Namespace Root\WMI
if($WMIReturn.GetType().BaseType -eq [system.Array]) #the returned value is an array of objects
{
foreach( $PowerOn in $WMIReturn)
DoSomething($PowerOn)
}
else
{
DoSomething($WMIReturn); # the returned value is the object
}
This is pseudocode of course. You should still check if each element of the array is the desired type and skip it if not or error out ..read more
SAPIEN Forums » PowerShell
10M ago
Sorry, I though I had attached it on the first post, I will try again
DevicePower.ps1
This is as fare as I got when I got stuck
Statistics: Posted by Woody_033 — July 18th, 2023, 9:03 pm ..read more
SAPIEN Forums » PowerShell
10M ago
Probably means your cast is incorrect. Can you post the complete code?
Statistics: Posted by Alexander Riedel — July 18th, 2023, 7:34 pm ..read more
SAPIEN Forums » PowerShell
10M ago
Untitled.png
Computer 1 - Drive 0 - Current OS
Computer 1 - Drive 1 - Fresh install (WIP) - [Note]
Computer 2 - is a test unit - [Note]
[Note]: These 2 installations are practically identical only the hardware is different.
dotnet-sdk-6.0.408-win-x64
dotnet-sdk-7.0.302-win-x64
MSChart
VC_redist.x64
VC_redist.x86
Code:
Write-Debug -Message "Before"; $PowerON.GetType()
If ($PowerON.GetType().BaseType -eq [system.Array]) {
Write-Debug -Message "PowerON[0]"; $PowerON[0].gettype()
}
Else {Write-Debug -Message "Else"; $PowerON.GetType() }
# as you predicted
DEBUG: Before
IsPublic IsSerial Name Bas ..read more
SAPIEN Forums » PowerShell
10M ago
This is actually pretty common for PowerShell to return different types from a cmdlet.
If there is only one object to return a cmdlet may only return the object. If there is more than one, the same cmdlet might return a collection.
Not knowing what you use to get this return, you may have to code this like (pseudo code)
if (type -eq System.Array)
object[0].gettype()
else
object.gettype()
to get the desired result.
Statistics: Posted by Alexander Riedel — July 18th, 2023, 3:15 pm ..read more
SAPIEN Forums » PowerShell
10M ago
Product: PowerShell Studio 2023 (64 Bit) Build: v5.8.225
OS: Windows 10 Pro (64 Bit) Build: v10.0.19045.0
I have the same script on two Machines
DevicePower.ps1
One Machine it gives me:
Code:
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array ..read more
SAPIEN Forums » PowerShell
10M ago
Hmm, how stupid of me x)
I just found what I needed
For other users, if you're looking for the same thing, select files and folders on the right and scroll down to find the following "output folder" items.
Statistics: Posted by RISFRANCE — July 7th, 2023, 9:41 am ..read more