Go Premium for a chance to win a PS4. Enter to Win

x

Powershell

16K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Share tech news, updates, or what's on your mind.

Sign up to Post

We are looking for ideas on getting Microsoft to defederate a domain.

We were looking to purchase Office 365 through GoDaddy. During that process, they asked if our domain pbhcpa.com had been federated previously to 365. Since we (here in IT) had made no conscious decision to do so, we said “no, it has not been federated.” We have three O365 accounts that are pbhcpa.onmicrosoft.com but pbhcpa.com was not affected by this. We purchased office 365 through GoDaddy. Our GoDaddy team got the message “pbhcpa.com has already been used to setup an Office 365 account at Microsoft. Before you can create any new users here, you must remove pbhcpa.com and any associated accounts from your previous Office 365 account.”

pbhcpa.com has already been used to setup an Office 365 account at Microsoft
We didn’t have any 365 accounts with pbhcpa.com so we opened a case with Office 365 support. The first tech found that someone at the firm, a year ago, created a Power BI account. The signup caused Office 365 to reserve our domain but never set it up as an actual tenant. This caused a shadow tenancy. The tech said this is a flaw on the Microsoft side and that he would have to escalate it. He had us log into our onmicrosoft account and run a Powershell script to defederate.

We connected to Exchange Online using https://technet.microsoft.com/library/jj984289.aspx

Then he had us run a modified version of this:

Set-Mailbox Identity -EmailAddress <NEW primary E-mail address>
Set-Mailbox identity -EmailAddresses @{Remove="<E-mail …
0
Ready for your healthcare security check-up?
Ready for your healthcare security check-up?

In the past few years, healthcare organizations have become a prime target for advanced attacks. Does your organization have what it needs to defend itself? Schedule your healthcare security check-up today and download our free Healthcare Security Resource Kit today!

So I found a vbs script to write information into the computer description field upon login

Here's the code and my error shows below the code.

Not sure how to fix this, especially since I'm a scripting novice

Option Explicit
Const ADS_PROPERTY_UPDATE = 2 
Dim objSysInfo, objUser, objNetwork, strComputer, strDescription

Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

strDescription = "Logged on to " "&" strComputer "&" " at " "&" Date "&" " " "&" Time

objUser.Put "description", strDescription
objUser.SetInfo

Open in new window


I want to run this as a PS1 file but I get the following errors

At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:35
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                   ~~~
Unexpected token '"&"' in expression or statement.
At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:34
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                  ~
Missing closing ')' in expression.
At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:58
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                                          ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
I need help in fixing this script. When I run it, it gives me the HostName of the computer but the TaskName does not come out correct. This script is checking for any scheduled tasks that run under the "UserA" account

This is how I would like it to show in the CSV file
Example.
HostName, TaskName
Server100, Reboot
Server100, Shutdown
Server101, Reboot


$Servers = Get-Content servers.txt
$user = "UserA"

foreach ($computername in $Servers)
{

$schtask = schtasks.exe /query /s $computername /V /FO CSV | ConvertFrom-Csv | Where { $_."Run As User" -eq $user}

    {
    $object = New-Object –TypeName PSObject
            $object | Add-Member –MemberType NoteProperty –Name HostName –Value $computername
                  $object | Add-Member –MemberType NoteProperty –Name TaskName –Value $($schtask.TaskName)
                  $findings+=$object;
    }
}

$findings | Export-CSV -path ServerSchedultTasks.csv

Your help is greatly appreciated.
0
Hey EE

Can someone help add to this script a progress bar ?  I use this to add 1000s of accounts and it would be nice to see a progress or percentate status ,

Import-Csv "c:\Temp\YourCSVFile.csv" |
ForEach{
       Add-ADGroupMember -Identity $_.Group -Members $_.SamAccountName    
       }
0
Hi All,

I am trying to put together a little GUI to be used by my team so that we can run a selection of PS scripts at the click of a few buttons.

The idea i have seen in an old job several years back was something sort of like this,

Basically a page with Buttons and text box descriptions,

then a text file or even integrated for a task list that I can edit the Function and Description of the buttons.

Has anyone seen anything like this, i am new to programming and cant afford to spend several hundred for PowerStudio i was hoping to find a easier way that I can edit someone elses work?

thanks
ideas
0
Hello all,

I've come up with an issue and was wondering if the pros could assist :)

Is it possible to lock, secure or encrypt the properties of an image file? Basically, when you right click the image and select properties you can see all the meta data details such as date, time, author, user, modified date etc.

I know through various methods and applications such as powershell, it is easy to clear these and amend but I want it so that noone can amend it! A tough ask, especially in this day in age of technology where everything can be manipulated but would really like a hand in this.

Happy to use/pay for a third-party application if needed.

By heavy Google searches people have mentioned to watermark the image but that's pretty low key on terms of protecting the image stamp.

Any help as always will be highly appreciated!

N00b
0
Can you help me get started with writing a script that will insert text at the very top of ever php file in a directory? This is what I need.
<?php
if (!isset($_SESSION)){
 session_start();
 }
 ?>
0
I have CSV file which has following line
111,222," 1,876,890"

I would like to have output as follows
111,222,1876890

How can I do this in Power Shell?
0
I started using the Profile tab for user's in Active Directory (2012r2) to map a network drive for the specific user.  We use to do this before by putting a login script in the startup folder on the client machines.  The login script would map the company network drives as well as each individual users drive on the server.  I have now started to use Group Policy to map our network drives, but needed a way to map individual user drives.  For this reason just used the AD Profile tab for these individual drives.  It works just fine but I had a user complain to my about his PowerShell when opened defaulting to this network user drive now.  I have also noticed that within the individual network user drives there is now a windows folder created automatically.  Is this the reason for the PowerShell issue?  Is there away around this?  Is there a way to set this so the windows directory is not created in the users network folder?
0
I need to create a Task Scheduler for 10 pm every day, but if the PC is off at that time, it needs to forgot this event and wait until next day 10 pm.  In other works if the PC is off skit the event.
Right now my script create the event but if the computer is off, the event occur at soon user log on in the morning, I need to avoid it.
Any ideas and thanks for your help.
 
#Create a 10 pm task Scheduler

$taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $jobname }

if($taskExists)
{}
else
{
$script =  "-ExecutionPolicy Bypass -file $File"
$action = New-ScheduledTaskAction –Execute "powershell.exe" -Argument "$script"
$trigger = New-ScheduledTaskTrigger -daily -At $Time
$Description = "Shutdowm computers at $Time every day."
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -DontStopOnIdleEnd
Register-ScheduledTask -TaskName $jobname -user "theuser" -Password "password"-Action $action -Trigger $trigger -RunLevel Highest -Settings $settings -Description $Description
}
0
Lessons on Wi-Fi & Recommendations on KRACK
Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

Personally, I think that PowerShell should be called PowerSh**.

There's regular PS and then there's the Azure one and then there's the Exchange management shell that is sort of another PS and who knows, there may be more.

Geez...

So, I've worked my way thru this once before, but have now come up empty in remembering what I did.  I've spent about an hour or so perusing the Internet looking for the commands that have to go in front of the commands that I want to do.  And, of course there doesn't appear to be a single article that outlines exactly the commands. And even when I trace the supposed commands that go before the ones that I need, I usually end up with an error that the command I've just executed isn't a valid command.

So, here are the two commands that I want to ultimately execute:

Get-MSOLUser –UserPrincipalName <UPN of the affected user> | FL | Clip
Get-Mailbox –Identity “User Name” | FL | Clip

I'm trying to track down an issue between on -premise AD and Office 365.

Can you tell me which PS  or PS's I really want to run for these and what commands have to come first in order for these to be recognized?  I'm running these either on a Windows 2012 server or  Windows 10 PC.
0
I will try to explain this the best I can from the information a user gave me.

So apparently he has a macro on Excel 2016 that runs which fixes a raw .xlsx file by formatting it to the end users specifications. So to break it down a program outputs a .xlsx in raw format then he opens the raw .xlsx file on his computer and runs the macro to fix the formatting.

The question we have is can we automate this process in task scheduler or something similar to run the macro on the raw .xlsx file on someone's computer or a server? Most likely the user will not have Excel open because this will occur around 5 am when no one is working.

(Program outputs .xlsx  to network drive > user's computer or server runs the automated macro to the format data > end user is able to use the output.)

Thanks for helping!

- Excel 2016
- Windows 10 Pro x64 or Windows Server 2012 R2
0
Hi,

For example:

$DisabledADUser = Get-ADUser -Filter {Enabled -eq $false} -properties mail | Select name,enabled, mail | Export-csv c:\temp\Disabled-Account.csv

$OUDisabledUsers = Get-ADUser -SearchBase "OU=Disabled User Accounts,DC=AU,DC=local" -Filter * -properties mail | Select name,enabled, mail | Export-csv c:\temp\AU-OU-DisabledUsers.csv

How can I merge $DisabledADUser and $OUDisabledUsers  (without duplication) and export the final result in csv file?
1
I am not an expert on PowerShell and I was asked by my company to come up with a way to do the following: I am not sure how to actually make this happen and was hoping to get some assistance from the experts here at Experts Exchange. Sorry that I am such a Novice.

1. If the server names contain XA65Build2 then
2. Copy epic.cli and server.bgi from Share Location to C:\ProgramData\Epic\Config and to C:\BGInfo and overwrite if present
3. If the server names contain XA65Build1 then
4. Copy epic.cli and server.bgi from Share Location to C:\ProgramData\Epic\Config and to C:\BGInfo and overwrite if present

I believe the PowerShell script could be ran from a Task Scheduler upon Startup. Just not sure how to actually make it work.

Thank you again for your help.

Brian
0
I am trying to come up with a Powershell script that will search multiple computers and list the name of the computer with what services has a specific account running that service and export to a CSV file.

Ex. ComputerName, Displayname, StartName, State
      ComputerA, BITS, UserA, running
0
Hello Experts

I'm trying to import modules using Powershell. However, when I issue the command, I don't get any errors, see image however, none of the modules are imported.

module
Can someone let me know what I'm doing wrong?

Cheers
0
Hi,

What would be the easiest way to fix copy paste (nothing happens), hopefully powershell based?

J.
0
I am looking at the various way to copy files from a users local PC to a specific folder location - on a Remote Server.  Essentially, it would work in the following way:

  • User copies files on local PC
  • They switch to the RDP server
  • Press a button on our application that runs a script and pastes the file into a specific folder

We need this paste function to run int the background and I was wondering if we could use Powershell to do this.  Incidentally, our server is running 2012 R2.
0
Hi All,

I have this line of code that test connection for servers:

PS G:\> Test-Connection -ComputerName  sdindc01, sraddc01, sdendc01, senadc01, sewcdc01, solidc01 -Count 1 | selec
t address

Open in new window


if the ping is successful I then want to Mstsc in to the servers, I've tried:
$t=Test-Connection -ComputerName  sdindc01, sraddc01, sdendc01, senadc01, sewcdc01, solidc01 -Count 1 | selec
t address
$t | % {mstsc /v:$_}

Open in new window


However this does not work. please help
0
Free Tool: IP Lookup
LVL 11
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question: 150 users , new accounts , every user different password, no exchange mailbox, proxysmtp for each user , Office 365 syncsyncAd ,
no group memberships for any user , no telephone or address or any other details, just account with password and proxy SMTP for office 365.
I have list of users in .csv also google found only adding users but not creating new proxy email under the user attribute tab. does anyone please can advise on script to complete this task.
....I know there are many scripts out there  :) I was searching but none of them doing all at once...creating users and also creating proxy email under the attributes ..this is what I have


Import-Module ActiveDirectory


Import-Csv "C:\Scripts\NewUsers.csv" | ForEach-Object {


$userPrincinpal = $_."samAccountName" + "@TestDomain.Local"


New-ADUser -Name $_.Name `


-Path $_."ParentOU" `


-SamAccountName $_."samAccountName" `


-UserPrincipalName $userPrincinpal `


-AccountPassword (ConvertTo-SecureString "MyPassword123" -AsPlainText -Force) `


-ChangePasswordAtLogon $true `


-Enabled $true


and now need to continue by creating SMTP:user@domain.com proxy email attributes for users accounts for sync with azure office 365 :( sorry newbie with PS
0
Dear,
I will have to PowerShell a data import from HR software to AD.
The purpose is to track ADD/Update/Delete as usual AND also the changes (names/adress.....)

Following your own experience, what would you suggest as best format to be used to track things. Any hint? tips & tricks are welcome.
I'm thinking of CSV, html, XML, at the very end (but no time for the moment a SQL DB)... OR maybe does AD already have such functionality and therefore almost Nothing to be foreseen ?
Maybe I'm missing a evident solution?

Thanks to all.
0
Do one of you SharePoint 2010 gurus have the Powershell script to check in or undo-checkout of all item's in a picture library.  If you used SP2010 you are probably failure with when you check them in sometimes they still show checked-out.  I know there is a -force way to do it.  I just cannot remember it.  

Goal: Loop through all the documents in a specific Picture Library in a particular site and check them all in (or undo checkout)
0
All,

I found these PowerShell commands on a website to pull a software lists from two separate machines and compare the lists.  My questions are:

1.  Is it possible to automate this with PowerShell ISE?
2.  Can this be scripted so it accepts the domain credentials and both computer names as variables?
3.  Can the output be saved to a network share?  \\servername\myshareddrive, for example.

I have figured out how to run single commands in PowerShell, but I have zero experience with PowerShell ISE and scripting multiple commands.  What would the script look like if this can be accomplished?

 Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object Displ
ayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\Users\User1\Documents\InstalledPrograms
-PS.txt

 Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object Displ
ayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\Users\User2\Documents\InstalledPrograms-PS2.txt

 Compare-Object -ReferenceObject (Get-Content C:\Users\User2\Documents\InstalledPrograms-PS.txt) -DifferenceObje
ct (Get-Content C:\Users\SavedToNetworkShare\Documents\InstalledPrograms-PS2.txt)

Open in new window

0
In my test environment at home I need to create a Server 2016 PowerShell script that will launch the Office 365 PowerShell command line commands and automatically sign on with an Office 365 administrator username and password.

This isn't a security hazard since this will only be used on an Office 365 test domain on a computer at home that no one else has access to.

Please provide me with the correct syntax for doing this.
0
What is the correct process to upgrade to PowerShell 5 within Server 2012 R2?

I have already downloaded and tried to install Power shell 5 but I get messages saying that this update is not for your computer.
0

Powershell

16K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.