Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

Issue working with "AddAccessRule" in PowerShell

$
0
0

Below is a snippet from a PowerShell script I've written for creating accounts for new hires. This particular snippet is a question of whether to create & set the Home Directory for the newly created user in AD.

For reference, I have Global variables set through various methods and have verified that these are correct as the rest of the script works perfectly...

The part that ISN'T working is: "Exception calling "AddAccessRule" with "1" argument(s): "The trust relationship between this workstation and the primary domain failed."

Now, before anyone goes down the road of "You should unjoin and rejoin your computer from the domain", let me confirm THIS IS NOT THE ISSUE. Prior to this section of the script, I am able to authenticate to AD, create the new account and drop them into the OU I am an Admin of, as well as copy the Group Memberships...


Stringing Powershell Scripts Together

$
0
0

Hello,

My company has a hybrid system for our exchange server. I have developed 3 separate scripts to fully setup a new employees profile. The first script creates the user account, makes sure the correct smtp is set, licenses the mailbox then forces a dirsync. Once the dirsync is completed, the user is asked if they would like add the newly created user to any distribution lists, if the user presses yes, my second script is run to add the users to the distribution lists in O365 and on prem. Once these have been added to the users account, the user is prompted to if they would like to license the user mailbox, if the user presses yes, the third script is run which allows the user to set the mailbox license type and location based of the username.

In all three scripts I have a function pulls from the users encrypted username and password,...

Cannot index into a null array ERROR in PowerShell

$
0
0

I am trying to rename a directory folder name dependent on a mapping table on Sql server.

If the directory folder is matches the Site ID in the SQL table then this will be renamed against the alpha column in the sql table example below:

SQL TABLE example: Siteid -AiB3304 Alpha -AIB001

Existing directory name example (matches siteid): C:\Customer\AiB3304

This needs to be renamed to the alpha column name C:\Customer\AIB001

I have connected to the SQL server using the following script however I get the following error:cannot index into a null array (see attachment)

$Directories sql query brings back the following:

Alpha AIB001 siteid AiB3304

Where am I going wrong? I have attached the exact error.

Text
Text
$SQLServer = "proteandb" #use Server\Instance for named SQL instances! $SQLDBName = "MigrationStaging" $SqlQuery = "Select Alpha,...

Powershell - Text file path variable not working

$
0
0

Hi - Any idea why this script would work with a direct path as a variable but not a path to a text file which contains multiple UNC paths? Example:

This works (removes non inherited permissions):

Powershell
# make sure this folder exists $Path='N:\user'# get explicit permissions$acl=Get-Acl-Path"$Path"$acl.Access|Where-Object{$_.isInherited-eq$false}|# ...and remove themForEach-Object{$acl.RemoveAccessRuleAll($_)}# set new permissions$acl|Set-Acl-Path"$Path"

This works:

Powershell
# make sure this folder exists $Path='\\networkfolder\\Disable.txt'# get explicit permissions$acl=Get-Acl-Path"$Path"$acl.Access|Where-Object{$_.isInherited-eq$false}|# ...and remove themForEach-Object{$acl.RemoveAccessRuleAll($_)}# set new permissions$acl|Set-Acl-Path"$Path"

This doesn't work...

Set timeout threshold in skype for Business Managemnet Shell

$
0
0

I'm trying, and failing fairly miserably to get a bit of powershell sorted to divert and change the behaviour of a Queue in skype for business. I've got the divert bit sorted, it's simple and I'm happy but I cannot find a way to alter the timeout threshold within the same script.

It's meant to be a time saving exercise but my google skills are failing me.

Send help.

Office 365 PowerShell MFA & Avoiding Double Log-In

$
0
0

Hi all,

I'm currently working on automating some processes at work, and I've recently discovered there are 2 modules for Office 365 required when using MFA:

1. The MSOnline module (for things like adding/removing licenses); and

2. The Exchange module (for things like converting mailboxes to Shared).

My question is, is there a way to avoid the double log-in required for both modules?

For example, say I have a user with an assigned license that has recently left. Our policy is to convert their mailbox to a shared mailbox, and remove their license so it can be used elsewhere. Because we're using MFA, and Microsoft haven't published a better method of acquiring the necessary module, I have to:

1. Download the Exchange Online Remote PowerShell Module for multi-factor authentication

2. Dot source the downloaded module (because it's set as a .ps1...

Adding Colums Powershell

$
0
0

Dear Experts

Good Day. I have the below code to list from a CV of users and groups the name, samaccountname,object class and title.

I manage to bring my report to list exactly what i need the only thing left is how can i export them to an empty CSV creating the colums as well? I want the name to go to name, sammaccountname to go to column Username etc.

Is there a way while exporting on an empty CSV to define the columns i want to be created and attach each data to the proper column? I am listing below my code

$users=Import-csv C:\Users\tech\Desktop\users.csv
ForEach($user in $users)
{
$NTName = $User.User
Get-ADObject -Filter {sAMAccountName -eq $NTName} -Properties Name,sAMAccountName,Department,Title,Objectclass | Select-Object -Property Name,sAMAccountName,Department,Title,Objectclass

}

Hi All, I am trying to add a line on my PS script but it keeps giving me errors

$
0
0

I am getting errors when i addAdd-DistributionGroupMember -Identity "GROUP Name" -Member $emailto my script.

Error:

Add-DistributionGroupMember : The term 'Add-DistributionGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.

It used to work fine but it just stopped. I have$UserCredential = Get-Credential andConnect-MsolService -Credential $UserCredential to connect to O365, and alsoImport-Module ActiveDirectory running in the first lines of my script but when it gets to the Add-Distr... my script stops working.

Any help is much appreciated. Thank you.


Powershell Error - Cannot find an overload for...

$
0
0

I am trying to work with a Microsoft API and Powershell, both of which I am still learning about, and I am getting the following error...

Text
Cannot find an overload for "UpdateDeviceValues" and the argument count: "3". At C:\PowerShellScripts\API-UpdateDeviceValues-ICC.ps1:13 char:37 + $accounts = $pmws.UpdateDeviceValues <<<< ('18B81F1FD790','DisableICC','True'); + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest 

My code is...

Powershell
$pmws=New-ObjectPrincipalManagement;$pmws.Credentials=$cred;$pmws.url="http://172.31.9.2/bss/PrincipalManagement.asmx";$accounts=$pmws.UpdateDeviceValues('18B81F1FD790','DisableICC','True');$accounts

Not really sure what this error means. I believe it means I need to pass three values, which is what I am doing. So, any help would be very much appreciated.

Thanks,

Jason....

O365 Permissions cmdlets disparity

$
0
0

Good morning, Spiceheads. I'm (unfortunately) using a specific VIP mailbox for this experiment, because this morning she got "The modified permissions can not be saved" when revoking permissions on her O635 mailbox for NLE employees ("No Longer Employed"). Great, sounds like a good way to kick off a firestorm and another week of PowerShell skullduggery.

Connected to 365, imported session, blah blah. When I run

Powershell
Get-MailboxFolderPermission-IdentityVIP:\calendar|ft

I get a list clearly showing usernames of NLE employees. But when I run

Powershell
Remove-MailboxFolderPermission-IdentityVIP:\calendar-UserUMcUserface

I get "There is no existing permission entry found for user: UMcUserface"

Since the Get- is showing permissions, where is it reading them from that the Remove- can't reach?

This whole ordeal reminds of ...

Follow Up - Account Expiration Notification

$
0
0

I hope you guys can help me with something. The end goal is to alert users whose accounts will expire after a 45 day period. They are normally disabled but their email will still be working.

The script is to look for those who have been expired after 45 days of the last logon date and are marked as disabled and send them an email. I can get the data to show up properly but converting it to email is something that I am struggling with.

Here is the code:

Powershell
################################################################################################################### Please Configure the following variables....$smtpServer="mail.server.com"$expireindays=10$from="Company Administrator "$logging="Enabled"# Set to Disabled to Disable Logging$logFile="C:\Users\username\Logs.csv"# ie. c:\mylog.csv$testing="Enabled"...

Get idle time from a machine

$
0
0

We are an MSP and have recently moved from Connectwise to Autotask, including the RMM. One of the biggest let downs inside of Datto RMM (quite a few) is the complete lack of idle time. They are trying to make it better but I can't really wait and even though I hammer it on my sales guy a feature like this isn't even on the radar.

I find that I really, really miss idle time. It's a PITA without it. I find myself opening labtech in hopes the machine is still in LT JUST for the idle time.

I found on the interwebs a decent powershell script but AT only runs quick jobs as SYSTEM, so it grabs the SYSTEM time.

Provided I can run as SYSTEM, is their a way to identify the current logged in user and then impersonate that user to run the script? All without the user's password?

maybe even do it from the same powershell script? Maybe even a third...

Display a list (different line)when converting objects to string and send mail

$
0
0

Hi,

I have some objects stored in a variable and would like to use the select-object, do a format table and send them in an email.

I am managing to do this by converting them to a string, however the formatting of the string/email is a one liner.

How can I separate them to a different line? I want them to show , as when you do Format-Table for example.

This is what I am doing (In soon expiring there are multiple thing):

$body = $soonexpiring | Select-Object -Property samaccountname, @{label='Person Responsible';expression={$_.manager -replace '^CN=|,.*$'}} | Format-Table | Out-String

send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high

How can this be done?

Thanks in advance!


Write-Host and Get-xyz | Separate "Get" Outputs with Headers

$
0
0

My head is getting sore from banging it against the wall on this.

What I have:

Write-Host "Server Options";Get-DhcpServerv4OptionValue | Select OptionID, Name, Value | ? OptionId -In 3,6,15
Write-Host "Scope Options";Get-DhcpServerv4OptionValue -ScopeID "$($Scope).0" | Select OptionID, Name, Value | ? OptionId -In 3,6,15

Actual result:

Server Options

Scope Options
OptionID Name Value
-------- ---- -----
3 Router {aaa.bbb.ccc.ddd}
15 DNS Domain Name {EXAMPLE.COM}
6 DNS Servers {aaa.bbb.ccc.ddd ,aaa.bbb.ccc.ddd ,aaa.bbb.ccc.ddd }
3 Router {aaa.bbb.ccc.ddd }
6 DNS Servers {aaa.bbb.ccc.ddd, aaa.bbb.ccc.ddd, aaa.bbb.ccc.ddd}
15 DNS Domain Name {EXAMPLE.COM}

Desired result:

Server Options
OptionID Name Value ...

More Love in the "Scripts Center"?

$
0
0

Hey fellow Spice Heads,

While randomly looking at helpful posts, I decided to look at the Scripts Center (and take a look at a useful script I submitted a month ago) and was quite surprised at what I found. While going through it, I'm seeing some pretty cool, useful scripts but an average of 4- downloads, making me wonder if the Script Center is getting enough visibility/ love. It wouldn't matter much if not for the fact that in order to receive peppers (other than 1 pepper per download) on a submission, one must have 10 downloads, whereas How-To's require 5 up votes and most submissions are hitting that goal. Maybe it's just me, but for the ones out there who love writing and sharing their scripts with the community, it makes it hard to want to contribute in an area that doesn't get much activity.

To give a slightly better...


powershell to set logonworksations to null on AD

$
0
0

hey guys ,

usually when you want to set an AD user to logon to a specific workstation u go to properties/Account/Log on To and set it from there ..

now i wanna remove those restrictions from a list of users

i tried this

Powershell
$userlist=Import-Csv-Path'c:\users.xlsx'foreach($userin$userlist){Set-ADUser-LogonWorkstations$null}

but its not working ... when i use

Powershell
Set-ADUseruser1-LogonWorkstations$null

it works ...

help please

Datetime Formatting

$
0
0

Hi All,

I have the following code which gives me the second friday of the month as11 January 2019 00:00:00

Is there a way i can strip out the time?

Powershell
$FindNthDay=1$WeekDay='Friday'[datetime]$Today=[datetime]::NOW$todayM=$Today.Month.ToString()$todayY=$Today.Year.ToString()[datetime]$StrtMonth=$todayM+'/7/'+$todayYwhile($StrtMonth.DayofWeek-ine$WeekDay){$StrtMonth=$StrtMonth.AddDays(1)}$CCDATE=$StrtMonth.AddDays(7*($FindNthDay-1))$CCDATE

Thank you

How can I write-host and add-content to a text file in ONE line?

$
0
0

I'm trying to write something to a log file and what I want to do here is save myself a line of code each time by making the "Write-Host" part also write to the log. So, here's what I want to do:

Powershell
Write-Host"Woo, some cool text"|Add-Content$outLogPath-ErrorActionSilentlyContinue

and here's what I currently have and also works:

Powershell
Write-Host"y e e t"$log="y e e t"|Add-Content$outLogPath-ErrorActionSilentlyContinue

Any ideas why the top example doesn't work and the bottom does? Note that $log is just some throwaway variable I keep reusing to get the logging to work. Any ideas on how I could do this?

Also, if you have the time, I can't get my head around why this hits the "if" each time when the processes I'm trying to start actually do start?

Powershell
functiontestApps{$arrApps,$arrShortApps=...

Formatting phone numbers in AD via script?

$
0
0

I'm super nit-picky about things being consistent and uniform. Our user objects in AD are mess when it comes to phone numbers. They are all formatted differently:

  • (xxx)xxx-xxxx
  • xxx.xxx.xxxx
  • xxx-xxx-xxxx
  • xxx xxx-xxxx
  • xxx xxx xxxx
  • etc..

Is there a clean way to have these all formatted to xxx.xxx.xxxx without having to go in and do it by hand? Figured I'd ask before we start hand-jamming away.

Love,

Me

Fetch the Daily check-up of SCCM components report through powershell

$
0
0

Hi,

I need to fetch the daily checkup of sccm components report using powershell. i am able to fetch the details using thia command " Get-CMComponentStatusMessage " but not getting the other header which is needed for the report.

I am attaching the headers list which I need to include in the report.

Thanks in advance.

Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>