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
Submarine Sandpaper
May 27, 2007


Getting some odd stuff with SMA and hopefully someone has encountered this before.

Briefly, I'm creating a ticket, applying a template to overwrite it, then pulling the object. Later on I'll be using the object to apply user relationships to it and description changes. What's annoying is that if I launch this as a job in SMA it works, if I run it through the ISE console with the SMA ISE add-on it works, but when I call this with another runbook it errors out with, "A parameter cannot be found that matches parameter name 'eq'. (A parameter cannot be found that matches parameter name 'eq'.)"
It's breaking at: $SRProjection = Get-SCSMObjectProjection -ProjectionName $SRTypeProjection.Name -filter “ID -eq $SRID” @connection
It seems to want a GUID for this filter but when running the get-scsmobjectprojections and selecting any of those objects, none have ID in GUID format :(((((
code:
#properties mandatory are in there but will be overwritten by the template, ID is for callback. 
    $SRProperties = @{"Title" = "Placeholder";     #Required 
                    "Description" = "Placeholder"; #Required 
                    "Priority" = $SRPriority;      #Required  
                    "Urgency" = $SRUrgency;        #Required 
                    "ID" = "SR{0}"
                    }
    #Creates generic SR
    $NewSR = New-SCSMObject -Class $SRClass -PropertyHashtable $SRProperties -PassThru @connection
    
    #Can use __InternalID for GUID if needed
    $SRID = $NewSR.ID 
    
    #Gets service request projection
    $SRTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequest.FormProjection$ @connection
    
    #Uses ID to pull created ticket as projection.
    $SRProjection = Get-SCSMObjectProjection -ProjectionName $SRTypeProjection.Name -filter “ID -eq $SRID” @connection    
    
    #pulls template and applies to ticket
    Set-SCSMObjectTemplate -Projection $SRProjection -Template $SRTemplate @connection
    Write-Output "$TemplateName applied to Service Request $SRID"

    #Pulls ticket as object to apply relationships and changes later
    $SRObject = get-scsmobject -Class $SRClass -filter "ID -eq $SRID" @connection
Driving me crazy, glad its friday.

Submarine Sandpaper fucked around with this message at 21:18 on Oct 26, 2018

Adbot
ADBOT LOVES YOU

Submarine Sandpaper
May 27, 2007


When I purposefully break it by putting an invalid ID and run it manually the exception is asking for a GUID.

/E without writing the property ID, the ID that's generated for the exception just lacks SR so it's not even a guid.

Submarine Sandpaper fucked around with this message at 14:46 on Oct 27, 2018

Submarine Sandpaper
May 27, 2007


PBS posted:

From the error it sounds like it doesn't like your filter.

""A parameter cannot be found that matches parameter name 'eq'. (A parameter cannot be found that matches parameter name 'eq'.)""

Can you try another filter format? Or provide the full body of relevant errors? $error[0] | select *
I think this is everything

writeErrorStream : True
PSMessageDetails :
Exception : Microsoft.PowerShell.Commands.WriteErrorException: A parameter cannot be found that matches
parameter name 'eq'.
TargetObject :
CategoryInfo : InvalidData: (:) [Write-Error], Error Creating Service Request
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Create-SCSMServiceRequest
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Create-SCSMServiceRequest, C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandbo
xes\yteug04o.u1l\temp\srycaoqe.mpc\Create-SCSMServiceRequest.ps1: line 192
at <ScriptBlock>, C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandboxes\yteug04o
.u1l\temp\srycaoqe.mpc\Create-SCSMServiceRequest.ps1: line 198
at <ScriptBlock>, <No file>: line 38
PipelineIterationInfo : {0, 0}

/e- changed the filter syntax to {(logic)} and got:
exception
property (property)
output

writeErrorStream : True
PSMessageDetails :
Exception : Microsoft.PowerShell.Commands.WriteErrorException: property
TargetObject :
CategoryInfo : InvalidData: (:) [Write-Error], Error Creating Service Request
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Create-SCSMServiceRequest
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Create-SCSMServiceRequest, C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandbo
xes\yteug04o.u1l\temp\rpg2k2z4.dsv\Create-SCSMServiceRequest.ps1: line 192
at <ScriptBlock>, C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandboxes\yteug04o
.u1l\temp\rpg2k2z4.dsv\Create-SCSMServiceRequest.ps1: line 198
at <ScriptBlock>, <No file>: line 38
PipelineIterationInfo : {0, 0}

/e- first error when chaning ID to display name so it's not the guid :downs:

Submarine Sandpaper fucked around with this message at 15:10 on Oct 29, 2018

Submarine Sandpaper
May 27, 2007


anthonypants posted:

Is this line 192 or 198?
code:
$SRProjection = Get-SCSMObjectProjection -ProjectionName $SRTypeProjection.Name -filter “ID -eq $SRID” @connection
If so, just change those to normal double-quotes like the one for $SRObject.

192 is the error catch, 198 is the call to the create-scsmservicerequest function.

That helped though, was (and I hope I'm done with this) able to fix it by:

code:
 #Uses ID to pull created ticket as projection. 
    $SRProjection = Get-SCSMObjectProjection -ProjectionName $SRTypeProjection.Name -filter "ID -eq '$SRID'" @connection    
    
    #pulls template and applies to ticket projection      
    Set-SCSMObjectTemplate -Projection $SRProjection -Template $SRTemplate @connection
    Write-Output "$TemplateName applied to Service Request $SRID"

    #Pulls ticket as object to apply relationships and changes later
    $SRObject = get-scsmobject -Class $SRClass -filter "ID -eq $SRID" @connection
Not sure why the first filter wants SRID in singles and the second doesn't. Maybe an issue with smlets?

Submarine Sandpaper
May 27, 2007


aws s3 cp "`"$line`"" "`"$newline`""

those are the escapes you need if i'm reading you right. surround in more quotes if you're using it like a filter string.

Submarine Sandpaper fucked around with this message at 01:05 on Nov 1, 2018

Submarine Sandpaper
May 27, 2007


I was told to do this after a review and don't think it's possible but want to confirm before ignoring it.

Old

code:
for each ($shithead in $shitheads)
$description = "Hey, $shithead, change this"
call-script -description $description.
Next shithead
It was suggested to remove "Hey, $shithead, change this" to a variable outside the loop to make it easier to read and modify

New
code:
$description = "Hey, $shithead, change this"
for each ($shithead in $shitheads)
call-script -description $description.
Next shithead
Obviously $description isn't being updated since it's outside of the loop. Any way to make this work?

Submarine Sandpaper
May 27, 2007


Call Script was a generic and I should have written call-function,
$ExecutionContext.InvokeCommand.ExpandString($description) ended up working out. Hope I won't forget this one.

Submarine Sandpaper fucked around with this message at 18:51 on Nov 12, 2018

Submarine Sandpaper
May 27, 2007


Jowj posted:

What issue is moving the line out of the foreach block solving? I'm sort of confused as to what the end goal is.

code:
$shitheads = (
    "methanar",
    "a big pile of garbage",
    "jowj",
    "submarine sandpaper"
)
foreach($shithead in $shitheads)    {
    $someText = "hi this policy is dumb, how else will i know which $shithead to blame?"
    Write-Host $someText
}
this works just fine and is a fuckload more readable than setting the variable scope or anything outside of the loop unless i'm missing something.
It's not solving an issue and the $ExecutionContext.InvokeCommand.ExpandString($description) has potential security concerns but I don't get paid enough to care or fight. I got to learn something new which is cool though. The next review may tell me to revert it due to the security concerns, which I'll then function it or do the replace like Commando.

Submarine Sandpaper
May 27, 2007


What's the best way to terminate a script not using throw or exit?

Submarine Sandpaper
May 27, 2007


if it's looking for a dict @ that
@{RunningMode=AUTO_STOP,RunningModeAutoStopTimeoutInMinutes=60,RootVolumeSizeGib=80,UserVolumeSizeGib=50}


Anyone have experience using ROBO copy from SMA to remote fileshares? I'm having a bitch of a time. Looking to just get number of files in a specific user's share. Gotta use a PSSession somehow due to rights over the shares.

Submarine Sandpaper
May 27, 2007


thebigcow posted:

code:
 @{'RunningMode'='AUTO_STOP';'RunningModeAutoStopTimeoutInMinutes'='60';'RootVolumeSizeGib'='8';'UserVolumeSizeGib'='50'}
Semi colons


I don't know what SMA is and searching was unhelpful. Are you running into problems with the powershell double hop ?

Turns out permissions are the issue.
SMA is service manager automation. To my understanding it's like in house azure.

Submarine Sandpaper
May 27, 2007


FISHMANPET posted:

Maybe I'm not quite understanding, because if you set the ValidateSet to only $True then you can't do -param:$false. Now granted, setting switches to true by default is apparently against best practice so I guess it's kind of weird that I'm asking "what's the best way to follow best practices when I'm violating best practices."

The reason I'm doing this is my team has a publicly available Powershell Module to interact with data from Google Sheets: https://github.com/umn-microsoft-automation/UMN-Google but I'm sure very few, if any, people are using it. And the module I'm working on, Get-GFilePermissions, is currently so useless that even if you're using the module, you're probably not using that function. But it's there, and it does something and so it's possible that someone is using it. So I'm changing the function to be slightly smarter, and debating how much I want to preserve the current format of the data that it returns vs improving it to be actually useful (but making it easy for someone to fix their code if they want to keep using it the old dumb way?).

I'm most assuredly thinking way too hard about this dumb cmdlet because I could make it work and make it pull all the data by adding 9 characters but damnit I wanna do it right!
Use a switch. Will never hit default though with the param as mandatory.

code:
function Get-GFilePermissions
{
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    Param
    (
        [Parameter(Mandatory)]
        [string]$accessToken,

        #[Alias("spreadSheetID")]
        [Parameter(Mandatory)]
        [string]$fileID,

        # Parameter help description
        [Parameter(Mandatory,ParameterSetName="All")]
        [switch]$allFields,

        # Parameter help description
        [Parameter(Mandatory,ParameterSetName="Specify")]
        [string]$fields
    )

    Switch ($PSBoundParameters.keys)
    {
        allfields {$uri = "https://www.googleapis.com/drive/v3/files/$fileID/permissions/?fields=*" 
            break}
        fields {$uri = "https://www.googleapis.com/drive/v3/files/$fileID/permissions/?fields=$fields" 
            break}
        default {$uri = "https://www.googleapis.com/drive/v3/files/$fileID/permissions/"}
    }
    $headers = @{"Authorization"="Bearer $accessToken"}
    Invoke-RestMethod -Method Get -Uri $uri -Headers $headers
}
/e - actually it will always hit default without the break due to the other mandatory params, maybe add a third in your setname or just dump mandatory? Heck you could also invoke-restmethod in the switch.

Submarine Sandpaper fucked around with this message at 20:46 on Feb 20, 2019

Submarine Sandpaper
May 27, 2007


you can pass via the AD user's sid rather than their sAm

Also (if it's working this probably doesn't matter) but powershell has get-acl and set-acl so you don't need to use the .*AcessControl() methods. Otherwise have you noticed if your intermittent failures are where the user already has permissions? I had a project shelved just adding permissions since it could potentially be too resource intensive if the stars aligned to gently caress up backups. I may have also been fed a crock of poo poo.

Submarine Sandpaper
May 27, 2007


Sometimes powershell just fucks up. I have the following:

code:
$Accounts = get-aduser -filter {enabled -eq $true -and name -like "SV*"} -Properties PasswordLastSet,Manager |
    where { $_.PasswordLastSet -lt (get-date).addyears(-1) }
And it occasionally pulls disabled accounts which really raises questions with the report :shrug:

Submarine Sandpaper
May 27, 2007


Invoke-RestMethod has a flag for -usedefaultcredentials which to my understanding will act as a passthrough. You also have the -SessionVariable parameter which'll create a variable you can then use with further requests via the -webvariable parameter. TBH I've really only used the -sessionvariable and -webvariable with generic invoke-webrequests though.

favorite primer, I dunno, a lot is specific to the API i.e. you need to call any request and get a session token from the expected error's exception method.

Submarine Sandpaper
May 27, 2007


I'm having some regex issues and the various online calcs are not helping me resolve.

Looking to determine if doing a cleanup is worthwhile and I want to see how much is cleaned up if it is.

Creating the txt with:

$DISMAnalyze = & "Dism.exe" /Online /Cleanup-Image /AnalyzeComponentStore

and $DISMAnalyze is a system.string. Will have an expected output like the below:

code:
....
Component Store (WinSxS) information:

Windows Explorer Reported Size of Component Store : 11.06 GB

Actual Size of Component Store : 10.60 GB

    Shared with Windows : 6.06 GB
    Backups and Disabled Features : 4.48 GB
    Cache and Temporary Data : 55.69 MB

Date of Last Cleanup : 2019-10-30 08:23:50

Number of Reclaimable Packages : 2
Component Store Cleanup Recommended : Yes

The operation completed successfully.
I'm looking to extract the Actual Size of component Store.

Even something simple like
$DismAnalyze.ToString() -match '[0-9]*\.[0-9]*\s\wB'
is giving me a false. For whatever reason I still have to .ToString() it to get a return with -match, whether true or false. Online calcs are saying this should return all instances of *.* GB or *.* MB.

I'm going crazy.

Submarine Sandpaper
May 27, 2007


Thanks y'all

Submarine Sandpaper
May 27, 2007


That makes me think, how useful is the built in convert fromsecurestring if you don't have a vault service or otherwise to pull central creds from?

Submarine Sandpaper
May 27, 2007


This is a silly one but how can you determine all the stores on a machine eg sqlserver, certificates, registry

Submarine Sandpaper
May 27, 2007


Is there a handy shorthand for getting array objects as values in a hashtable into an array without messing around out-string or some -join command to avoid the string conversion giving a system.object.whatever?

Submarine Sandpaper
May 27, 2007


Oh I half assed my question. Specifically when converting to CSV it attempts to .tostring() everything so if $hashtable is a value in an array that field returns System.Collections.Hashtable. So when I'm building my report I'm doing some absurd poo poo like

($hashtable | Out-String).trim()

Submarine Sandpaper fucked around with this message at 04:34 on Apr 30, 2020

Submarine Sandpaper
May 27, 2007


TITANKISSER69 posted:

I have 50 security groups that I need to add 2 users to the Delivery Management list so they can send to all of them. They're all in the format companyname.office.cityname, is it possible to add user1@company.com and user2@company.com to the allowed senders for companyname.office.* ?

if I"m reading right:

Set-Mailbox -Identity "Robin Wood" -AcceptMessagesOnlyFrom "Lori Penor","Jeff Phillips" -AcceptMessagesOnlyFromDLMembers "Legal Team 1"

https://docs.microsoft.com/en-us/exchange/recipients/user-mailboxes/message-delivery-restrictions?view=exchserver-2019

Submarine Sandpaper
May 27, 2007


if your csv/text file is something like

1337
6969
420


then use get-content

Submarine Sandpaper
May 27, 2007


Yeah, set-aduser user -manager manager

Submarine Sandpaper
May 27, 2007


Read up on the get-aduser documentation, most properties can be filtered as a parameter rather then piping into a where. You can use -searchscope to specify OU. Pipe the result from this when it looks good to set-aduser -manager manager

Submarine Sandpaper
May 27, 2007


code:
(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices) | gm | ? {$_.name -eq "SetAllowTSConnections"}
TypeName: System.Management.ManagementObject#root\cimv2\terminalservices\Win32_TerminalServiceSetting

Name                  MemberType Definition                                                                                                                           
----                  ---------- ----------                                                                                                                           
SetAllowTSConnections Method     System.Management.ManagementBaseObject SetAllowTSConnections(System.UInt32 AllowTSConnections, System.UInt32 ModifyFirewallException)

(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTSConnections(1,1)
Exception calling "SetAllowTSConnections" : ""
IDK wtf. Maybe it's worthless now? I know I should be using cim but I was stealing from a script I made back in the win7 days, but it still exists and has a method. I've manually set 1,1 to uint32 as well with no luck.


I want it to work because of:
code:
(Get-CimClass -Namespace root\cimv2\terminalservices -ClassName Win32_TerminalServiceSetting).CimClassMethods
SetAllowTSConnections                      UInt32 {AllowTSConnections, ModifyFirewallException}    {Implemented}
But it seems to be a read only property (at least on w10 desktops). How the gently caress would I know that unless I try to set it with CIM for a more robust error?

Submarine Sandpaper
May 27, 2007


ah that explains the error on my personal and the read-only exception.

But it's still an error on the client's machines:
Exception calling "SetAllowTSConnections" : "Invalid Operation"

Hopefully it just won't be needed for this client's task :shrug:
I think these folks have an AV that's been sold to me as blocking all this and I don't have the keys to prevent that.

Submarine Sandpaper
May 27, 2007


purge the klist and see if there are any other creds stored.

Submarine Sandpaper fucked around with this message at 18:18 on Dec 22, 2020

Submarine Sandpaper
May 27, 2007


Can you do what you want to do with the data using a -parallel switch anywhere without jumping through these hoops?

I see what you want to do and there's just gotta be a better way.

Submarine Sandpaper
May 27, 2007


Eh I wouldn't like to do this but it's not a hard solution.

Since you know your tax/shiping/handling is always multiplied by the occurance of the order you can just divide that out.

$math = $CSVfile | group order -NoElement

[...]


@{Name='Taxes' ;Expression={$_.Values[2] / $math[$math.values.IndexOf($_.Values[0])].Count}}, `


[...]

/e thinking about it more you probably will want to rebuild the data so maybe not as easy as just doing a calculation in the expression

Submarine Sandpaper fucked around with this message at 22:19 on Feb 6, 2022

Submarine Sandpaper
May 27, 2007


return will leave the loop if you have a successful first run

Submarine Sandpaper
May 27, 2007


ACLs sorta suck unless they've changed things in PowerShell. Last I did it I needed to be a local file system admin and you needed to pull the acl, modify it, then set via a method. Local admin maybe a lie but I thought i needed it for some reason. You may be best set by using old cmd liners and invoking them on a directory.

Submarine Sandpaper
May 27, 2007


Pile Of Garbage posted:

lmao you're right I'm dumb as poo poo! I've no idea why I thought that was allowed.

Short names?

Adbot
ADBOT LOVES YOU

Submarine Sandpaper
May 27, 2007


Microsoft really does not want email admins to effect or read mailboxes, that's getting all swept to the compliance side of MS admin. I still mourn my inability to use search-mailbox.

You still need to know your dates and all, you could setup an ICAL invite that books all holidays.

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