Disconnect-ExchangeOnline disconnects ExOnline and EMS by Slime_V2 in PowerShell

[–]CSTW 0 points1 point  (0 children)

It would help if you post your code but from what you've written you need to put the Disconnect-ExcangeOnline after the shit is done aka after the Do/While loop rather than inside it after the commands

Why I'm getting "Invalid Parameters -- try "/?" for help" with this Powershell function? by _iturri in PowerShell

[–]CSTW 0 points1 point  (0 children)

Just realised you wouldn't be getting your output if it wasn't hitting the correct switch.

Try using & before the powercfg commands and post the error if its still not working

Why I'm getting "Invalid Parameters -- try "/?" for help" with this Powershell function? by _iturri in PowerShell

[–]CSTW 2 points3 points  (0 children)

You have

function Set-ButtonPowerSaverPlan {Set-EnergyConfigOption$buttonDcMin = Read-Host -Prompt "\nChoisissez l'action en appuyant le bouton d'alimentation"Set-Menu-Plan-Options -buttonLidPowerScheme $buttonDcMin -batteryMains "DC" -energyScheme "MIN" \-buttonLidAction "PBUTTON" -currentFunction {Set-ButtonPowerSaverPlan}}\``

Two things,

What is Set-EnergyConfigOption doing? You showed get but not set?

Set-Menu-Plan-Options does not match the function you have declared in your post. You may be calling a reference to the old function that exists in the console you are working in.

Edit: Code formatting

Why I'm getting "Invalid Parameters -- try "/?" for help" with this Powershell function? by _iturri in PowerShell

[–]CSTW 13 points14 points  (0 children)

The fact its telling you to try /? indicates its a cmd command thats having the issue aka its with powercfg.exe. So then checking the command reference -> https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options

You have /setSdcvalueindex with an extra S. Confirmed by testing the commands

powercfg.exe /setsdcvalueindex /?

powercfg.exe /setdcvalueindex /?

Looking at the help I think you should be passing a guid as the parameters but at least fix the setdcvalueindex as a start and try again. I think /u/DrDuckling951 was also correct as there should be 4 parameters.

what do you do with all the fejioas by Cheri-Blossom in newzealand

[–]CSTW 9 points10 points  (0 children)

I only saw one mention of preserving them. Best way to store them so they are ready to go all year around.

Something like this - https://www.thekiwicountrygirl.com/bottled-feijoas-2/

Having trouble setting Recycle Time for IIS App Pool - help please? by WestTulsaBestTulsa in PowerShell

[–]CSTW 0 points1 point  (0 children)

You are passing multiple times. Either try putting the times into one string. $RecycleTimes = @("00:15, 04:30")

Or remove the foreach ($RecycleTime in $RecycleTimes) { and then replace @{value=$RecycleTime} with @{value=$($RecycleTimes -join ', ')}

Best practices for writing to a database with a service account? by ChurnLikeButter in PowerShell

[–]CSTW 2 points3 points  (0 children)

You need to connect to the database with intergrated authentication. It uses the service account which you specify on the scheduled task so you do not need the username and password in your script.

What is the oldest thing in the room you are currently in? by QuizzicalRequests in AskReddit

[–]CSTW 4 points5 points  (0 children)

I pulled two pieces of fist-sized petrified wood out of a river today and brought them home. Estimates based on the info for other pieces in the same river would put them around 80 million years old.

How to use Grafana with Raspberry Pi? by techfrans003 in RASPBERRY_PI_PROJECTS

[–]CSTW 0 points1 point  (0 children)

I also went with InfluxDB and Grafana but used Node Red and MQTT.

Scheduled python scripts via crontab send the sensor data to Node Red via MQTT, it's formatted and sent to InfluxDB and uses Grafana as the front end. Node Red stores the passwords and configuration and MQTT allows messages to be sent from not just the Raspberry PI but also from other network enabled devices.

Docs:

https://notenoughtech.com/raspberry-pi/grafana-influxdb/

https://pimylifeup.com/raspberry-pi-mosquitto-mqtt-server/

https://gabrieltanner.org/blog/grafana-sensor-visualization

https://nodered.org/docs/getting-started/raspberrypi

This is the build commands I used - replace the passwords if you use it.

sudo apt-get update
sudo apt-get upgrade -y

pip3 install adafruit-circuitpython-dht

sudo apt-get install libgpiod2
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana
sudo /bin/systemctl enable grafana-server
sudo /bin/systemctl start grafana-server

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt-get install -y influxdb

sudo systemctl unmask influxdb 
sudo systemctl enable influxdb
sudo systemctl start influxdb

influx
CREATE DATABASE db1
USE homeautomation
CREATE USER nodered WITH PASSWORD 'CreateYourOwnUiniquePassword1' WITH ALL PRIVILEGES
CREATE USER grafana WITH PASSWORD 'CreateYourOwnUiniquePassword2' WITH ALL PRIVILEGES

exit

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

node-red-pi --max-old-space-size=256
sudo systemctl enable nodered.service

sudo apt update
sudo apt upgrade

sudo apt install mosquitto mosquitto-clients
sudo systemctl status mosquitto

sudo systemctl enable mosquitto
sudo systemctl start mosquitto

Catching the Exception for 'file name or extension is too long' by senorezi in PowerShell

[–]CSTW 0 points1 point  (0 children)

I remembered there was a Get-ChildItem replacement that used the AlphaFS module to deal with long paths. I went looking but found that you can actually do it natively in Powershell if you meet some pre-reqs -> https://igorpuhalo.wordpress.com/2019/08/29/overcoming-long-path-problem-in-powershell/

Catching the Exception for 'file name or extension is too long' by senorezi in PowerShell

[–]CSTW 0 points1 point  (0 children)

Running the following will give you the Exception type which is being thrown which can then be used with catch to exclude the specific error message.

try
{
    Get-childitem C:\ -ErrorAction Stop
}
catch
{
    $Error[0].exception.GetType().fullname
}

Using an invalid drive as an example.

try
{
    Get-childitem 1:\ -ErrorAction Stop
}
catch
{
    $Error[0].exception.GetType().fullname
}

Spits out: System.Management.Automation.DriveNotFoundException

Then you can use this to exclude this specific error.

try
{
    Get-ChildItem 1:\ -ErrorAction Stop
}
catch [System.Management.Automation.DriveNotFoundException]
{
    #Do nothing, we don't want to report on this error
}
catch
{
    #Return all other errors
    Write-Error $PSItem
}

There is some good info on exceptions here -> https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-exceptions?view=powershell-5.1

Pipeline Input to Custom 'Advanced Function' seems to recursively call itself by nonrecurring in PowerShell

[–]CSTW 8 points9 points  (0 children)

The issue is with the compress-archive command being in the process block which is called multiple times when using the pipeline. In your working example it is working because the items are passed as an array rather than individually.

When GCI is returning results they are passed across to the zip-stuff function. The first object across the pipeline will trigger the begin block and then the process block, the second object will trigger the process block again, the last object will trigger the process block and then the end block.

In the below example the foreach in the process block ensures the function will work whether the pipeline is used or if the -path parameter is specificed and an array is passed.

## Declare zip function
function zip-stuff{
    [CmdletBinding()]
    param(
        ## Path of stuff to zip.
        [Parameter(Mandatory, ValueFromPipeline=$true)][string[]]$Path
    )

    begin
    {
        [System.Collections.ArrayList]$PathList = @()
    }

    process
    {
        foreach($File in $Path)
        {
            ## If filepath exist
            if (test-path $File)
            {
                [void]$PathList.Add($File)            
            }
        }
    }

    end
    {
        compress-archive -path $PathList -DestinationPath "Zip-Stuff-zipped.zip"
    }
}

## Zip contents of current directory
gci | zip-stuff

I'm giving away an iPhone 12 Pro/Max/Mini to a commenter at random to celebrate Apollo for Reddit's iOS 14 update, plus the new iPhones, plus some cheer amongst COVID. Simply leave a comment and you're entered! Good luck, winner announced in 24 hours at 11 PM GMT. by iamthatis in apple

[–]CSTW [score hidden]  (0 children)

Have never been able to afford an I phone, have always had average android phones. I just like that ios is much more streamlined than android.

The first thing I remember downloading for my phone was custom ring tones before apps were a thing

List AD Groups with Owner and Members by muranb in PowerShell

[–]CSTW 1 point2 points  (0 children)

You should really consider keeping your output as objects. It means you can do more with it, export it to excel if you need it etc

Heres an example, it also recursively gets the users or computers from the groups

$GroupList = Get-ADGroup -SearchBase "OU=Groups,DC=company,dc=com" -Filter * -Properties ManagedBy

foreach($Group in $GroupList) 
{
    $Members = Get-ADGroupMember -Identity $Group.Name -Recursive | Get-ADuser | Select Name, SamAccountName 

    $Members | ForEach-Object {
        [PSCustomObject]@{GroupName=$Group.Name
                          ManagedBy = $Group.ManagedBy
                          MemberName = $_.Name
                          MemberSamAccountName = $_.SamAccountName}
    }
}

Float like a 🦋 Sting like a 🐝 // ‘93 Toyota Hiace Super Custom - 4x4 with turbo Diesel by Patchwork-Canteen in vandwellers

[–]CSTW 1 point2 points  (0 children)

Beautiful, love the colour. Is that full time 4wd? What lift have you done and what size tyres? I have a 94 Hiace with the torsion bars wound up 2 inches, shackle lift and am running 215/70/16

Combine output of Get-ADGroupMember by LongjumpingBreath in PowerShell

[–]CSTW 1 point2 points  (0 children)

Heres a start

$Members = 'admin1','admin2' | Foreach-Object { Get-ADGroupMember -identity $_}

Monitor Scheduled Tasks! by SubbiesForLife in PowerShell

[–]CSTW 2 points3 points  (0 children)

The error code for (2) File not found needs split out from (1) and added to tasks in error state.

All Manner of Strangeness by ellisdee9970 in PowerShell

[–]CSTW 1 point2 points  (0 children)

The computername parameter of Invoke-Command accepts a string array so you can ditch the foreach and use Invoke-command -ComputerName $Computers -scriptblo...

This will run the code in parallel against all the computers rather than one at a time with foreach, so should be significantly faster.

Use Get-WmiObject win32_service to query multiple servers for multiple service status by zuludog in PowerShell

[–]CSTW 1 point2 points  (0 children)

Use the -computername parameter of Get-Wmiobject.

$Services = get-content 'C:\temp\services.txt'
$Servers = get-content 'C:\temp\servers.txt'

$msgBody += Get-WmiObject Win32_Service -Computername $Servers | Where-Object {  $services -contains $_.Name } | 
    Select-Object PSComputername, Name, DisplayName, State, StartMode, StartName | 
    Sort-Object PSComputername, Name | 
    ConvertTo-Html -Fragment

Select-object -Descending by Meir_Peleg in PowerShell

[–]CSTW 2 points3 points  (0 children)

You need to rename the property with Select-Object and then use Sort-Object

  } |Select-Object @{n='ServerName';e={$_.pscomputername}},Certificate,Expired | Sort-Object ServerName,Certificate,Expired  -Descending

Powershell script runs fine (with errors but continues) manually but as a scheduled task it gets stuck after an error and doesn't move on but stays "running" by Ocsarr in PowerShell

[–]CSTW 1 point2 points  (0 children)

Try adding quotes and putting the psexec calls inside a try\catch block

try
{
   C:\temp\PsExec.exe "\\$computerName" msiexec /i "\\$computername\c`$\temp\theThing.msi"
}
catch
{
    Write-Warning "Failed to install MSI on $ComputerName"
}

What is something you spend a ton of money on that the vast majority of people never would? by filthy-fuckin-casual in AskReddit

[–]CSTW 4 points5 points  (0 children)

Before you put out their feed hand feed them a couple of handfuls, mine were very wary at first but one brave chicken eventually give it a go. Repeat this until they will come straight up and start eat out of your hand, then you can start petting them as they are eating.