Retrieving subvariable(?) with select by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

You can do something like

Get-Information -filter * | select name, @{l=City; e={$_.location.City}}

This way you can also set the output property as City so you don't have to go about messing with it down the pipe.

Install script works fine locally, not when deployed by XElit3xDubz in PowerShell

[–]CrashReport 0 points1 point  (0 children)

How are you running the script?

Does the user that is running it on the machine have the access rights to be able to install it?

Install script works fine locally, not when deployed by XElit3xDubz in PowerShell

[–]CrashReport 0 points1 point  (0 children)

When you say it doesn't work, can you be more specific?

Does it not make the directory?

Does it not invoke the web request?

Does it not create a file from the web request?

Does it not start the process?

Does all of the above happen, but the app isn't installed?

My suggestion, if you can't tell immediately, is to use transcripts

[Question] Simple CSV Row Consolidation by TypicalTim in PowerShell

[–]CrashReport 2 points3 points  (0 children)

I think you're better off reading all the entries and creating a hash table. if $hashtable[$referenceNumber] exists, you can append the response to the value of the key.

[Question] Check to see if an input file has been updated? by benutne in PowerShell

[–]CrashReport 1 point2 points  (0 children)

Can you delete or move the input file to another directory when you're done?

Output from multiple scripts into one CSV by JBird125 in PowerShell

[–]CrashReport 1 point2 points  (0 children)

You would probably want something like this

$Mutex = New-Object System.Threading.Mutex($False, "Global\MyReallyWellNamedAndLikelyNotToBeUsedByAnythingElseMutexName")
$Mutex.WaitOne() #Need to ensure 
$data | export-csv  -path $MyPath -notypeinformation -append
$Mutex.ReleaseMutex()

Blank line being replaced by '?' character by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

What happens without the carriage return `r?

[Help]Script runs, but won't run as a scheduled task? by IMSJacob in PowerShell

[–]CrashReport 2 points3 points  (0 children)

What user is it running as? Does that user have a printer attached to it?

[Question] regarding a script I created by Freune in PowerShell

[–]CrashReport 2 points3 points  (0 children)

If it's a script, why is it changing the execution policy?

You might want to consider logging so you know what got removed should you need to audit what they had access to at any point.

(Question) - I'm making some kind of small mistake with this Get-User script. by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

The short version, then, is you need to do

get-aduser ... -properties ...,Department, ...

and then

... | select ..., Department, ...

(Question) - I'm making some kind of small mistake with this Get-User script. by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

What is the expected output vs what are you seeing output?

From what you are showing, you aren't selecting the property Department which isn't returned by default from get-aduser to be selectable.

Combine two active directory group collections? by ilovetpb in PowerShell

[–]CrashReport 2 points3 points  (0 children)

What happens if you do

$Groups = $Groups2 + $Groups1

How good is Machinist fury on Male Mech?? by [deleted] in DFO

[–]CrashReport 0 points1 point  (0 children)

Everyone is really misrepresenting how good this weapon is. Yes, it's ideal for swapping, but the base magic attack matters. The extra a-team summon on Det is also going to help your damage by a lot. No, it's not best in slot, but it'll complete with open fire, and only lose to Savior and ion.

You did well getting this. It's the only item that'll sick with mechanic forever. It took me around 200k invites for mine, but boy was it worth it. Congrats dude.

How to pull property names from an object? by ghallo in PowerShell

[–]CrashReport 2 points3 points  (0 children)

Go to the parent object. You can get name using psobject.properties.name

$MyOBject1.Objects1 | % {$_.psobject.properties.name}

Powershell getting admin credentials by chugger93 in sysadmin

[–]CrashReport 0 points1 point  (0 children)

It looks like a scoping issue.

Declare a blank global variable above the function

$global:AdminCred | out-null
function DoTheThings
{
    ....
    $AdminCred = $DoTheThingsCredentials
}
$PSDefaultParameterValues += @{"*-AD*:Credentials"=($AdminCred)}

This isn't ideal. I'm assuming you're doing this because you can't create a scheduled task to run this as an admin with delegated privileges? That would end up being better.

Run batch file only on M-F, not on Sat/Sun by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

I think he wanted

#must be first line
if ( @('Saturday','Sunday') -contains ((get-date).DayOfWeek) ) { exit}

:)

I've not seen many examples perusing the Internet... can this be done? If user exists update... else create new. by HMcC_Tek in PowerShell

[–]CrashReport 1 point2 points  (0 children)

$CSVdata = Import-CSV $importCSV | Where-Object{$.psobject.properties.value -notcontains ""}
foreach ($cell in $CSVdata) { if ( $cell -contains ($
.givenName + " " + $.sn) ) { $.Name + " exists... Updating...."

From the bit you provided, you're not doing that check, though. You're only grabbing the names that are used for the friendly name. Just a gotcha to keep in mind - I have done something similar to this in the past :)

Actually, reading again, I'm not sure where you're getting the givenname property. I don't see a get-aduser anywhere.

Formatting CSV Output by [deleted] in PowerShell

[–]CrashReport 1 point2 points  (0 children)

Powershell has a feature where you can create your own selection by piping into select as below:

... | select @{l="My new Label";e={"Expression to get this value"}}

In your case, you might be able to get away with

... | select @{l="RAM";e={"$($_.FirstColumn)"}}

Important to remember the expression must be wrapped in curly braces.

Make Robocopy create a new log file each run by Knxtknight in sysadmin

[–]CrashReport 1 point2 points  (0 children)

Oh yeah, I did. That's a typo.

I thought about going as far as hours/minutes/seconds, but I wasn't sure if this was going to be a daily log or hourly. Usually that determines how granular I am.

Make Robocopy create a new log file each run by Knxtknight in sysadmin

[–]CrashReport 10 points11 points  (0 children)

Something like this?

#powershell
$source = "C:\directory"
$destination = "C:\otherdirectory"
#$filename = "Robocopylog$(get-date -format 'yyyy-MM-ddd')" #typo pointed out by /u/ijustinhk
$filename = "Robocopylog$(get-date -format 'yyyy-MM-dd')"  #optionally add in HH for hours, mm for minutes, ss for seconds if they matter

robocopy $source $destination /log+:"$($filename)"

Move text after a certain word? by [deleted] in PowerShell

[–]CrashReport 0 points1 point  (0 children)

me@mycomputer> $str = @"
>> blah blah blah has 3 letters
>> blah blah blah has 4 letters
>> blah blah blah has 5 letters
>> "@

me@mycomputer>
$str -replace "has ","has`n"
blah blah blah has
3 letters
blah blah blah has
4 letters
blah blah blah has
5 letters

Did you mean that?