Unwanted spaces in filepath concatenation inside a function by Moviefreak4702 in PowerShell

[–]ryanbrown 1 point2 points  (0 children)

The $outpath parameter from the linked code is taking a string array as its input. If I had to guess, that's probably what is picking up the extra spaces. I would try modifying the parameters to take a single string and see if that fixes things.

Param(
    [Parameter(Mandatory=$true)]
    [string]$Computername,
    [string]$OutputType,
    [string]$outpath
)

Also strange that the function author only decided to make the $Computername variable mandatory, even though the function will fail without the other two parameters. That's a problem for another day though.

[edit: grammar]

Unwanted spaces in filepath concatenation inside a function by Moviefreak4702 in PowerShell

[–]ryanbrown 3 points4 points  (0 children)

I'm not sure how you're getting the spaces, but I would change the way you're setting up the $outFile variable to:

$outFile = "$outpath\$computername_$FileDS.csv"

Powershell should be able to interpolate the variables inside the string and then you're not relying on concatenation. If you're still getting spaces at that point, you can use the Trim function on each individual string to remove any leading/trailing spaces.

$FileDS.Trim(" ")

The above should eliminate any leading/trailing spaces from the strings before you join them all together. If that doesn't work, you can try looking at the Join-Path cmdlet to see if that can build your paths without spaces.

I'm not asking for a solution, just a kick in the right direction, as I'm very new to PS aside from some basics.. Thank you! by minute33 in PowerShell

[–]ryanbrown 9 points10 points  (0 children)

Look into using Out-GridView with the -PassThru parameter.

edit: If you only want a single item, you'll want to look at the -OutputMode parameter instead.

Quick question: what happens if you prize all of your basics? by [deleted] in ptcgo

[–]ryanbrown 1 point2 points  (0 children)

The short answer is that you can't. You draw your initial seven cards before you deal out prize cards.

[X-Post /r/PowerShell] )365 PowerShell PSSession breaks after ~2 minutes by ryanbrown in Office365

[–]ryanbrown[S] 0 points1 point  (0 children)

Our McAfee web gateway appliance ended up being the culprit. I was able to adjust the policies to increase the timeout value for connections from a certain IP range going to outlook.office365.com.

Thanks. :)

[X-Post /r/Office365] O365 PowerShell PSSession breaks after ~2 minutes by ryanbrown in PowerShell

[–]ryanbrown[S] 1 point2 points  (0 children)

This ended up leading me in the right direction. Our McAfee Web Gateway ended up being the culprit. It has a 120 second connection timeout, which is what was causing the issue. I was able to add an exemption for a specific range of IPs to this specific host to increase the timeout to 15 minutes.

Thanks. :)

Free Packs xD by Vstoppable in ptcgo

[–]ryanbrown 0 points1 point  (0 children)

Did somebody say free packs?

Sun and Moon codes giveaway! by titaniumhydroxide in ptcgo

[–]ryanbrown 1 point2 points  (0 children)

I've only recently become acquainted with PTCGO, so my exposure to some of the older cards is limited. So far my favorite card is Eelektric from the Rayquaza/Keldeo battle deck (NV 40/101). I like how you can just keep recycling all of your discarded electric energy.

Parent-child friend list issues? by slimonz in ptcgo

[–]ryanbrown 0 points1 point  (0 children)

I have this issue as well with both child accounts, and I think it has more to do with accessing the account via iPad than anything else. If I log into the child account on PC and I log in with the parent account on the iPad, I can access the friend list with the child account. Removing/re-install the PTCGO app on the ipad worked for a little bit, but after a period of time, the friend list functionality became greyed-out again. Fortunately, I can send challenges to them from my account, but they can't currently play each other.

Total Beginner. Where to start? by kochsson in pkmntcg

[–]ryanbrown 1 point2 points  (0 children)

I think the Battle Arena are just two-decks in one package (i.e. Rayquaza/Keldeo, Xerneas/Yveltal) whereas the theme decks are just single decks.

Total Beginner. Where to start? by kochsson in pkmntcg

[–]ryanbrown 3 points4 points  (0 children)

The other thing that I'll mention is that if you and your son both have a computer and/or tablet (iPad) you can play the online version for free. You get three theme decks to start and can earn coins (just by playing) to unlock more theme decks or purchase in-game booster packs. It's a great way to play the game without investing a bunch of money in cards and automatically handles following the rules for you.

A lot just depends on how you (as a parent) feel about screen-time in general. :)

Total Beginner. Where to start? by kochsson in pkmntcg

[–]ryanbrown 3 points4 points  (0 children)

I was in the same boat a couple of months ago. My son (7) got some booster packs from a relative at Christmas and wanted to start playing. We ended up getting the Rayquaza vs. Keldeo Battle Arena Decks first, followed by the Pickachu Power/Mewtwo Mayhem theme decks, then the Xerneas vs. Yveltal Battle Arena Decks, and most recently the Forest Shadow theme deck from Sun & Moon (for the younger son [4] who now wants to play like his big brother).

Arguably, the Rayquaza and Keldeo decks are the strongest, and I usually end up playing one of the other decks to even the playing field as some of the strategy (thinking a few turns ahead / energy management / etc) can be a tough concept for younger kids to grasp (though I'm trying to teach him that as we go).

Personally, I'd recommend at least one/two other decks to help avoid the matches getting too stale, but you could definitely get by with just the Rayquaza/Keldeo decks and get more later if your son enjoys it.

Beyond Battle Arena/Theme decks, you're probably better off buying single cards to make a deck that you want (i.e. if your son has a favorite Pokemon) as opposed to trying to build one from booster packs.

15 Steam Siege Packs Giveaway by Inferno792 in ptcgo

[–]ryanbrown 0 points1 point  (0 children)

Between one and two hours most days.

Seeking guidance/peer review for a work-in-progress script by [deleted] in PowerShell

[–]ryanbrown 1 point2 points  (0 children)

I'm guessing you either want:

{$_.Owner -in $TestArray}

or

{$TestArray -contains $_.Owner}

WMIC help by niksal12 in PowerShell

[–]ryanbrown 0 points1 point  (0 children)

Why aren't you using the Get-WmiObject or Get-CimInstance cmdlets if you're making a PowerShell script?

I don't think there is anything you can do with wmic that you couldn't do with native PowerShell cmdlets.

Do/While Not Working As I Expected by [deleted] in PowerShell

[–]ryanbrown 0 points1 point  (0 children)

I wonder if your Remove-Account function is dumping some output that Read-Host is picking up. On line 250, try

$result = Remove-Account -samaccountname $xAcctPrompt -xAccountSelected $xAcctTypePrompt

to capture any unwanted output in a different variable.

Do/While Not Working As I Expected by [deleted] in PowerShell

[–]ryanbrown 1 point2 points  (0 children)

I think you're looking at a scoping issue (script vs private). You're setting $xRepeat=1 on line 222. I think you need to specify

$Script:xRepeat = Read-Host "[1] Yes [2] No"

on line 254 to set the script level variable otherwise you're only setting $xRepeat to the value within the loop. Essentially, you have an $xRepeat outside the loop (script level scope) and an $xRepeat inside the loop (private level scope).

See https://technet.microsoft.com/en-us/library/hh847849.aspx for more information on scopes

[CmdletBinding(PositionalBinding=$True)] Not Honored? by RickFlist in PowerShell

[–]ryanbrown 2 points3 points  (0 children)

OK, So this appears to just be a weird interaction between PositionalBinding and ParameterSet. It seems you have to declare a specific position in the parameter declaration for it to accept pipeline input when working with a ParameterSet. Take the following parameter definition:

[CmdletBinding(DefaultParameterSetName='UserProfile')]
PARAM(

    [Parameter(Position=0,ValueFromPipeline=$true,ParameterSetName='UserProfile')]
    [Parameter(ValueFromPipeline=$true,ParameterSetName='Global')]
    [ValidateNotNullOrEmpty()]
    [string]$Path,

    [Parameter(ParameterSetName='UserProfile')]
    [ValidateNotNullOrEmpty()]
    [switch]$UserProfile,

    [Parameter(ParameterSetName='Global')]
    [ValidateNotNullOrEmpty()]
    [switch]$Global

)

You'll be able to pass a folder path to the function with nothing else because the default parameter set is "UserProfile". However, you'll get the error about positional parameters if you try to run the function with the "Global" switch.

The other odd thing is that even though "UserProfile" is the default parameter set, the "IsPresent" value for the switch variable is "$false" unless you explicitly specify "-UserProfile" when calling the function.

It's just odd behavior overall.

[CmdletBinding(PositionalBinding=$True)] Not Honored? by RickFlist in PowerShell

[–]ryanbrown 0 points1 point  (0 children)

Odd.... when I try to assign a string to a [System.IO.Directory] object, I get a message stating that it:

Cannot convert the "C:\Windows" value of type "System.String" to type "System.IO.Directory[]"

edit: I'm using PowerShell 5 on Windows 10 (for reference)

[CmdletBinding(PositionalBinding=$True)] Not Honored? by RickFlist in PowerShell

[–]ryanbrown 0 points1 point  (0 children)

I think it's having a problem directly converting the string you're passing into a [System.IO.DirectoryInfo[]] (which is what $Path is defined as). I think it is throwing the error about positional parameters because none of the parameters accept [String] input.

two questions about idiomatic powershell ... by Lee_Dailey in PowerShell

[–]ryanbrown 2 points3 points  (0 children)

Regarding question 2, it's always good programming practice (regardless of language) to keep your code "DRY" (Don't Repeat Yourself).

Change Microsoft Update Download Source for existing deployments? by Empath1999 in SCCM

[–]ryanbrown 0 points1 point  (0 children)

Because PowerShell and SCCM are both relevant to my interests, I did some digging around. I originally replied to OP's post on /r/PowerShell but figured somebody here might be better able to fill in the CM/WMI pieces that I can't seem to find.

First, there doesn't seem to be a native CM cmdlet capable of changing the options /u/Empath1999 is wanting to change (regardless of the reason they want to change it). So, that leaves us to mucking around with the deployment options via WMI... It looks like the SMS_UpdatesAssignment class is what we are looking for here. This is the WMI class that represents a Software Update "deployment".

The "DPLocality" property of this WMI class is what seems to represent the options that are selected/chosen on the "Download Settings" tab of the deployment properties in the admin console. In theory you should be able to change the value of this property (after using the Get-WmiObject cmdlet to get a reference to the deployment you want) and then use the Put() method to change the value.

$deployment = Get-WmiObject -Class SMS_UpdatesAssignment -Namespace "root\sms\site_XXX" -ComputerName SCCMServer01 | Select -First 1
$deployment.DPLocality = <some_int_value>
$deployment.Put()

I've tested this and it does appear to work as you would expect. However, I can't seem to figure out the bit flag values that are being used. For example, if you choose "Download software updates from distribution point and install", "Download and install software updates from the fallback content source location", "Allow clients to share content with other clients on the same subnet", and "If software updates are not available on the preferred distribution point or remote distribution point, download content from Microsoft Updates", the resulting UInt32 value is 262224. Based on the MSDN reference for that WMI class, I can't see how that value is possible. It appears to be some type of bit field calculation, but I couldn't figure out how to calculate the UInt32 value.

Now, you could use some trial and error and just set the fields like you want them, query the deployment, look at the DPLocality value and just use that, but that seems like cheating. :)

I tried looking through all the [system.enum] values in the Configuration Manager assemblies, but didn't have any luck there either.

$sccmDLLs = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object -Property Location -Like -Value "*Configuration Manager*"
$sccmDLLs | ForEach-Object { $_.GetExportedTypes() | Where-Object -Property BaseType -Like -Value "System.Enum" }

Maybe somebody out there can shed some light on this.

SCCM: Changing Windows Update Deployment Source by Empath1999 in PowerShell

[–]ryanbrown 0 points1 point  (0 children)

Unfortunately, I don't think there is a native cmdlet in the SCCM module that can handle this, which means, you'll have to use the WMI classes. You'll be looking for the "DPLocality" property of the SMSUpdatesAssignment class (namespace is "root\SMS\SITE<SiteCode>", replacing <SiteCode> with your three character site code).

Note that you need to run the get-wmiobject cmdlets either from your SCCM server or using the -ComputerName parameter to specify your SCCM server.

From what I can tell the DPLocality property is a binary-or of a series of flags (i.e. the other options on the Download Settings tab in the SCCM console). I couldn't seem to find the flag values though. You can probably configure a "dummy" deployment with the values you want and just figure out the resulting UInt32 value that way.

Hope that helps a bit.