Questions tagged [powershell-5.1]

280 questions
2
votes
1 answer

Include Enum's from another file

In my Powershell "project" I would like to have all the common Enum's in a single file and then reference that file from the various other scripts. I've tried dot-sourcing the file, and I tried converting the Enum file to a psm1 (Import-Module), but…
Eric
  • 1,321
  • 2
  • 15
  • 30
2
votes
2 answers

PowerShell Approved Verbs for "Archive" and "Unarchive" of Data Items

I have data that supports being Archived and Unarchived but none of the Approved Verbs for PowerShell Commands for data management or resource lifecycle seem to be a good fit. Technically, the relevant data items are actually available over RESTful…
Vjz
  • 61
  • 5
2
votes
0 answers

Why does PowerShell converts array to ArrayList when nested in Hashtable and returned from a job

Consider snippet below $JobResult = Start-Job -ScriptBlock { $Result = @("foo", "bar") Write-Host "Returning type $($Result.GetType().Name)" $Result } | Receive-Job -Wait -AutoRemoveJob Write-Host "Returned type…
pavel1269
  • 21
  • 2
2
votes
1 answer

Where-Object inconsistent behaviour between -InputObject parameter and pipe

Issue Calling the Where-Object cmdlet returns different outputs if the same PSObject is passed using the pipe or the -InputObject parameter: When using the pipe, the condition is applied. When using the -InputObject parameter, the condition is…
Akaizoku
  • 456
  • 5
  • 19
2
votes
1 answer

Why is my WQL Query not accepting my "IS NOT NULL" argument?

Pardon if this is something simple, tried google, and the search function here with some similiar questions, just no answer that worked for me in this scenario. For the sake of trying to avoid the pipeline as much as possible, I was reading into the…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
2
votes
1 answer

Verifying a string is not empty/null in an If condition

I'm writing a script that will accept user input via Read-Host (set to $String), and I want to avoid any issues that could be caused by having a blank value for the variables. Since I'll be using this a lot, I want to implement it into a function…
2
votes
1 answer

Using Set-Date in a Powershell script fails due to permissions

When trying to run Set-Date in my powershell script it fails because it claims to require more permissions. I have added the groups Users and even Everyone to the Adjust system time Local Security Policy. Of course I could run it elevated to admin,…
2
votes
2 answers

Get-WMIObject Uninstall vs Get-CIMInstance Uninstall

Probably a dumb question but, I'm just curious. Is there a difference between Get-CIMInstance and Get-WMIObject when Invoking an Uninstall for an application under the Win32_Product class? Only reason I ask is because: Using Get-CIMInstance to…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
1
vote
1 answer

PowerShell scripts just hangs without moving to next statement when trying to run psftp commands

I have a following PowerShell scripts which is to get a file from remote Linux server to local directory, using psftp and get commands. These two commands as standalone, works just fine. However, as a following script copy.ps1: psftp…
Maven
  • 14,587
  • 42
  • 113
  • 174
1
vote
2 answers

How do I read the "using module" statements in a powershell script?

Powershell 5 has a nice declarative "using module" statement that can be provided at the top of a file to declare the dependencies of the script. Presumably one should be able to use this programmatically to determine what the dependencies of a…
Pxtl
  • 880
  • 8
  • 18
1
vote
1 answer

Question on use of Powershell start-job -scriptblock or sajb

I see many examples along the lines of: Get-ChildItem -Filter "*.txt" | ForEach-Object { sajb {ren $_.fullname ($_.directoryname + "\" + "temp_" + $_.name + ".newext") } } or what I think should be equivalent, using start-job…
1
vote
1 answer

Update yaml file containing comments in powershell, possibly within comments

I'm attempting to update a yaml file that contains comments in powershell. The field I'm attempting to replace is under 1 heading, but one with the same name might appear in another. Here is an example: yertle: "turtle" version: # ea-nasir:…
diemwing
  • 11
  • 2
1
vote
1 answer

ConvertTo-Json ignores array in the inner object

I have an object I need to extend. The issue is after converting to JSON the inner array object is always empty. I don't understand where's my fail :( $settings = @{} # create the nested object $settings | Add-Member -Type NoteProperty -Name…
MegaBomber
  • 345
  • 2
  • 3
  • 11
1
vote
1 answer

Is PowerShell's Invoke-WebRequest scalable?

I have a requirement to check the availability of 1,000 different urls, from a given text file, via a single windows server 2016 virtual machine, with PowerShell v5.1 installed. The required check should be in interval of every 5 minutes. My first…
edwio
  • 198
  • 3
  • 20
1
vote
0 answers

PowerShell Function Ran After Other Code Completes

I'm writing a PowerShell script that will allow our teams to rename network adapters on Windows Server Core. The script contains a function that will gather info on the network adapters and list them in a table with their DeviceID (Index) number,…
sudosysadmin
  • 23
  • 1
  • 7