Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Importing data into Skype/Teams

$
0
0

Hi 

In our organisation we are updating our list of emergency locations in the admin section of Teams.

We were able to export the current out of date list using 

Get-CsOnlineLisLocation | Select-Object companyname, description, HouseNumber, Streetname, City, p
ostalcode | Export-Csv c:\temp\skypelocation.csv -NoTypeInformation -Append

We now have the correct up to date list populated in a CSV and we would like to know if its possible to import this back to teams?

There is no import-CsOnlineLisLocation command so I am unsure if this is even possible.

Is there a way to use import-csv and then pipe it into the New-CsOnlineLisLocation command?


ForEach-Object -Parallel in PS 7

$
0
0

I got PS 7 installed and run (thanks Leon). And trying to test by following script. My purpose is to access each array element in each parallel process but not working. any other way to do that?

$s = '111','222','aaa','bbb','ccc'
0..4 | ForEach-Object -Parallel { $s[$_] }

Cannot index into a null array.
At line:1 char:2
+  $s[$_]
+  ~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Get a list of devices managed by Office 365 MDM

$
0
0

I'm trying to find a way to get a list of devices that are managed by Microsoft office 365 MDM that show up on the portal.

I've tried various commands which bring back a list of devices with ActiveSync mailboxes, but I just wanted those with MDM 

an policy enabled.

The idea is to remove mobile devices not managed by MDM.

Thanks in advance.

 

How can I call a functin in ForEach -Parallel ?

$
0
0

Function Show($s) { $s }
'1234','5678','asdf'| ForEach -Parallel { Show $_ }

When running above, I got error below. what's wrong?

Show : The term 'Show' 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.
At line:1 char:2
+  Show $_
+  ~~~~
+ CategoryInfo          : ObjectNotFound: (Show:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

How to copy Excel pivot charts to an email using PowerShell

$
0
0

Hi,

How can I copy a chart or more from an Excel sheet and paste to an Outlook email?

Thank you!



Copy-Item with file exclusions using -Exclude parameter

$
0
0

I am writing a PowerShell task using psake to copy over a directory structure and I am having some problems with the copy task:

$ExclusionFiles = @("packages.config", "connectionStrings.config")

    Copy-Item -Path $SourcePath -Destination $DestinationPath -Exclude $ExclusionFiles -Recurse -Force

When I run this command, it works properly but does not exclude the files that I specified in the $ExclusionFiles array parameter.

How can I get the Copy-Item to properly exclude my specified files (they exist at the root of my source path directory)?

Please advise.

Thanks.  


Cannot bulk delete old AD user objects due to insufficient privleges on subcontainers.

$
0
0

I use the below script to bulk remove users in AD


import-module activedirectory
$users = import-csv -Path "C:\delusers.csv"
$usernames = $users | select samaccountname
foreach ($username in $usernames) {
     $($username.samaccountname) | Remove-ADUser -Confirm:$false
}

I am getting a lot of error messages like this due to insufficient privleges.  

Remove-ADUser : Cannot find an object with identity: 'JDoe' under: 'DC=mydomain,DC=com'.
At line:5 char:36
+      $($username.samaccountname) | Remove-ADUser -Confirm:$false
+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (JDoe:ADUser) [Remove-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.RemoveADUser

I use ADSIEDIT and nagivate to the account and grant myself right to the Exchangeactivesyncdevice folder and delete the object.  

Is there anything in my script I could modify to do this automatically?

I am trying this script.  If I want to test this against an OU which contains disabled user accounts, should I replace the second line from $OUDomain=" " to $OUDomain="distingushed name of the OU"?

If every thing works, I replace it to $OUDomain="mydomain.com".  

Please advise again.  

#Variables
$FilePath = "C:\Scripts\ActiveSync\removed-eas-students.csv"
$OuDomain = " "

$EASDevices = Get-Mailbox -resultsize unlimited -OrganizationalUnit $OuDomain | `
Where-Object {$_.ExchangeUserAccountControl -match 'AccountDisabled'}

ForEach($mailbox in $EASDevices) {
      Get-ActiveSyncDevice -Mailbox $mailbox.Identity |`
      Remove-ActiveSyncDevice -Confirm:$True
}

$EASDevices | Select-Object DisplayName , Alias | Export-Csv $FilePath -NoTypeInformation

Can a powershell script gather the credentials of the person who ran it?

$
0
0

I have an interesting problem. I have been working on an automation script for a process we have with a Citrix product called AppLayering. This product has the ability to run a script after an action to output a disk to one of their provisioning boxes. This interface allows me to put in alternate credentials to execute the script. So one of the items in the script is a get-wmiobject call to the other servers in the farm to find out if they have enough disk space to copy the file to them. I keep getting access denied on this even though the user account i specified is an administrator on all of those boxes. More info on how this is executed is a linux appliance kicks off what looks to be a powershell remote process to run the script. So since all of this is being done without user interaction or a visual prompt, is there a way to gather the current credentials of the person running the script? I do not want to farm a secure string from a share, and i don't want to store credentials in the script. Any other thoughts would be helpful. Thanks


Redirect (Save) Output to an Existing File

$
0
0

Hello Everyone,

Just to start with, I am a new user of Powershell so please excuse me if you find my inquiry dumb. :)

I have a command which is "cleartool space -vob \test | select -last 1 |ForEach-Object {Write-Host ($_ -split ' ')[5,7,8]}" that gives me an output of \test 400 Mb. I want this output to be saved in a file calledD:\BackupFiles\result.txt.

I tried executing the command "cleartool space -vob \test | select -last 1 |ForEach-Object {Write-Host ($_ -split ' ')[5,7,8]} | Out-File D:\BackupFiles\result.txt -Append"but this doesn't save the output to the file. Instead, it shows only the output in the screen.

I tried also "cleartool space -vob \test | select -last 1 |  ForEach {Write-Output ($_ -split ' ')[5,7,8]} | Out-File D:\BackupFiles\result.txt -Append"instead of the Write-Host and it indeed saved to the file but instead of a one-liner, it saves as 3 lines like this:

\test

400

Mb

Can you please tell me what is wrong with the command I executed and what is the right way instead?

Your help is much appreciated.

Best regards,

Maria


Foreach - List Only Those With Errors

$
0
0

Hello,

I tried searching here for a topic related to my inquiry but cannot find one.

I have a file (c:\users\test\test.csv) that contains a list of names(view tag). In this list of names, I want to check which one is returning an error so I can remove them in my final list. For me to identify if it is returning an error or not, I have to run the command "cleartool lsview -l -prop <view tag> | find "Last modified" | ForEach-Object { (($_ -split ' ')[2])}". 

Currently, I have this code to start with but I am missing the part where it echo or list the name which is returning an error (to ignore that name that will give the standard output)?

$views = get-content c:\users\test\test.csv
    foreach ($list in $views){
       cleartool lsview -l -prop $list | find "Last modified" | ForEach-Object { (($_ -split ' ')[2])}
    }

To give you an idea, when the name has no issue, it will return something like this:

2011-06-30T17:56:48+02:00

If there is an error with the name, it will return this:

cleartool : cleartool: Error: No matching entries found for view tag "trial_only".
At line:3 char:8
+        cleartool lsview -l -prop $list | find "Last modified" | ForEa ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (cleartool: Erro...rg_xgold_618s".:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Really hope you can help me with this.

Thank you and best regards,

Maria


Capture Error Return codes on computer rename using PowerShell

$
0
0

Hi,

Currently I am using below PS lines to rename computer name in different scenarios and working fine.

Standalone Computer

Rename-Computer -NewName "DESKTOP-NewName"

Domain Computer

$Username = "DomainAccount"
$Password = "Plaintext" | ConvertTo-SecureString -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential($Username ,$Password)
Rename-Computer -NewName $TargetComputerName -ComputerName $ComputerName -DomainCredential $Creds
 

Is there any way to capture error's and logs in case of "Rename-Computer" execution failed (i.e Access Denied, Invalid new host name length, Invalid charters in new host name, Domain user id and password cred wrong, Domain network unavailable... etc.)

I tried with "Try and Catch" method but no luck. It's not logging anything.

Appreciates on your comments.

Regards

Er Reddy

Enable Disable HBA card in windows server 2012R2

$
0
0

It is possible to disable/enable HBA card using powershell command.

(Get-CimInstance Win32_PnPEntity -ErrorAction Stop | Where-Object{$_.Name -eq $HBA -and $_.DeviceID -eq $DeviceID}).Enable

The above command is not working in windows-2012R2

With out any DeviceManagement.psd1 script or Devcon.exe.

we Need to do enable/disable, Plz help

Powershell Script to Delete Users Profile if placeholder file is older than 30days

$
0
0
File server with folder structure as follows:
DATA$(Top Level Share)
 Folder1
 Folder2
 Folder3
 etc
 etc


Check each subfolder of Data$ for the existence of a text file named "mig.txt"
If "mig.txt" doesn't exist
 Then Do Nothing
If "mig.txt" exists
 Check "mig.txt" creation date
If creation date is over 30days ago
 Delete contents of subfolder

I want to run the above as a scheduled Task once a day from the file server


unicode in PowerShell Console

$
0
0

Hi!
Moving to Windows 10 version 1903 I have problems with the PowerShell console.
At first, no UniCode characters could be displayed and have followed this advice .
And now, typing Unicode characters does not work, for example
 echo.
And now I notice that each time you start the PowerShell Console,
the font setting is lost and every time Raster fonts are used, which can not display Unicode characters.

How to fix that somehow?

Thank you

Erhy


Powershell version

$
0
0

If I go to windows and do a search about powershell, it comes out and right click the path:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.

Does that mean this is Powershell version 1 since I see v1.0 in the path?

Thanks


Thanks


Formatting Powershell Output Help Needed

$
0
0

Good morning everyone.

I need some assistance on how to incorporate something in to a PowerShell "buildbook" script that I have. I can get the results I need if I run the following command by itself:

$cname = $env:COMPUTERNAME;
$cname = $cname + "_Groups";
$groups = Get-LocalGroup;
foreach ($group in $groups){
    #echo $group.Name;
    echo $group.name | Out-File -FilePath .\$cname.txt -Append;
    Get-LocalGroupMember -group $group.name | Format-Table -AutoSize | Out-File -FilePath .\$cname.txt -Append;
    echo "-----------------------------------------------------------" | Out-File -FilePath .\$cname.txt -Append;
    }

What I am trying to do, is insert those results in to the Powershell file I have that creates a nicely formatted html file of results such as Event Logs, OS info, etc. I am trying to replace the info in the following image, with the code I attached above.


What am I missing and/or doing wrong???

Thank you in advance for the assistance.

Task Scheduler Hidden powershell with no popup

$
0
0

Does anyone knows how to make the Task Scheduler to start to run ps1 script as Hidden without Poping up the window for a second (so to say - background task)...

Currently I am using as arguments:

-nologo -windowstyle Hidden -file FileLocation

But even if the script runs in background - it still at the beginnings pops up for a second - before hides it-self...

I just want to log into the log file the result of: netstat -f -b

EDIT:

I found a solution (maybe though not the best one): I set up to run that script as SYSTEM - but to make it more secured in this case - I set the script to be editable only by Administrator... Even System can't edit it without Admin rights...


Script for downloading IP addresses from webserver and convert them into hostbased firewall to block those

$
0
0

Hi Folks,

I am really in a need for powershell script which could download the the malicious IP addresses stored on my web server in .txt format and convert those in a hostbased blocking firewall rules.

Since I do not have any competency wondering if community can help me? pls?

Lets suppose my file name is hp-mal.txt stored http://172.16.5.10

Can someone please give me hints or script, pls?

Thanks,

blason R


Thanks, Blason R

Copy file from a file list preserving directories

$
0
0

Hello to everyone 

I need an help because i have to export a lot of file from a file list, bu i need also to preserse the folder. If i need to mirror data i could use Robocopy with the option /MIR but i don't have to copy al the file from a directory but only the files in a text files

This command should work to mirror manually from a Source Folder

Get-ChildItem -Path $source | Copy-Item -Destination $dest -Recurse -Container

but if a have a list of file with the full path there is a way to do it with powershell?

Renaming largest files that contain distinct sub strings of set length

$
0
0

Hello,

I have been struggling with the following on powershell:

I have files with the first 36 characters referencing an ID and the rest of the filename contains a timestamp.


98418c5d-a832-42e1-b249-96aabb6037a5.2019_10_18_04_02_10.3B17EADBAB014153DE76        SIZE: 5KB

98418c5d-a832-42e1-b249-96aabb6037a5.2019_10_21_04_26_03.2A30A786509F457REETC         SIZE  7KB

98418c5d-a832-42e1-b249-96aabb6037a7.2019_10_19_04_03_23.62B8572DE2ECFA52B2E6         SIZE 4KB

98418c5d-a832-42e1-b249-96aabb6037a7.2019_10_21_04_26_03.2A30A786509FE50A521C         SIZE 11KB

Now the files are of different file sizes. What I would like to do is rename the largest files that include a distinct ID.

All the files are in the same folder and can be looped through without recursion.

After completing the task it should have renamed the files:

98418c5d-a832-42e1-b249-96aabb6037a5.2019_10_21_04_26_03.2A30A786509F457REETC

98418c5d-a832-42e1-b249-96aabb6037a7.2019_10_21_04_26_03.2A30A786509FE50A521C

As the first one is the largest file that contains the 36 character substring 98418c5d-a832-42e1-b249-96aabb6037a5

And the second file being the largest file that contains the substring 98418c5d-a832-42e1-b249-96aabb6037a7

Any help would be much appreciated!

Viewing all 21975 articles
Browse latest View live


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