Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

Purchase O365 licenses with Powershell?

$
0
0

I originally posted this in the O365 forums, but they pointed me here to see if anyone might be able to assist.

From the other thread:

I've seen a couple threads asking if there is a way to purchase a Office365 subscription license via PowerShell and to the best of my knowledge, there is not one.   I also called Microsoft Billing Support to ask if there was a way to easily add additional licenses without having to manually go into the web portal and add them.  If we only paid for licenses that we assigned to users, I would just add a bunch of licenses every 4-6 weeks and live with it.  But since Microsoft support confirmed that any license added whether it is assigned to a user or not is charged to the company using it, we are only left to manually add a license each time a new user comes on board.

I happen to work for a company that is expanding nationwide and we have new users almost on a daily basis.  I have almost all other onboarding processes scripted, however each time we have to manually add a subscription for each user when an account is created.

Is there not a way to either add some sort of volume license for companies so we don't have to continually add licenses each time a new user is added? Or is there a way for the devs to create a cmdlet that will allow us to purchase a subscription license? (I have no idea how difficult this would be, I'm only asking)  But I know I am not the only admin out there that is running into this problem.  Anyone else have any suggestions?

If this is in the wrong forum I apologize, but since it spans over a few different areas, I'm posting it here first.

Thanks in advance for any guidance!



Need Help With Script of Group Members

$
0
0

Hello , Dear Friends, i need help . I need to export users in Office 365 which aren't in any group . Is there any way to do this? From PowerShell or ?

When i run script  Get-DistributionGroupMember  it only gives me the member who is in that group . I need the All users which aren't in any group ?

Highly appreciate your help . If you know someway please give me some Advices.

Thank you.

How to list all users and groups? Why does "DOMAIN USERS are not shown?

$
0
0

I´m trying to use a lot of scripts in technet library and it´s amazing the number os scripts that don´t run in my environment (win2008R2/WIn2012R2 AD/DC)

After a lot of testing i found a good script in: http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28277287.html

I did some minor modifications and i´m puzzled about something: Why the group "Domain Users" is not shown in the output? Even considereing that it´s the primary groups, make no sense, because the script lists all entities, am I right?

Import-Module Activedirectory
Get-ADUser -Filter {enabled -eq $true} -Properties SAMAccountName,DisplayName,memberof | % {
  New-Object PSObject -Property @{
SAMID = $_.SAMAccountName
UserName = $_.DisplayName
Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join ","
}
} | Select SAMID,UserName,Groups | Export-Csv C:\temp\Lista_Users_Groups.csv -NTI

An end user asks for a user/grupo listing, asking for some method to track permissions, the resulting CSV it´s good enough, a little modificatio in MS Excel do the trick, but i´m thinking about the DOMAIN USERS missing and wondering if something else was not cutted off form the file..

Help required to correct the VBscript

$
0
0

Hi , 

I have written a vbscript to collect localuser information from server. But when the output comes, it give the out like hostname\username . But I want the hostname to be removed from local user name.

Can anyone help me here please?


StrComputer = ""
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_UserAccount Where LocalAccount = True")

For Each objItem in colItems

     Wscript.Echo "Caption: " & objItem.Caption
     Dim Caption,Caption1
Caption1 = Trim(objitem.Caption)
Caption = (Caption1 & ";" & Caption)

      Wscript.Echo
Next


File History (Windows 8.1) Configuration via Powershell

$
0
0

Hi,

I am looking at turning File History on for around 1000 users to protect user data on local machines. 

Is there a script I can use to specify the settings?

I would need to specify:

  • Network Location for Backup
  • Save Copies of Files
  • Size of Offline Cache
  • Keep Saved Versions

I have looked through the registry for these settings and have not been able to find them so hoping I an script this in some way.

Thanks


Call variables in a function?

$
0
0
Hi,

I have made this function which deploys an AppV package:

Before it loads, I need to load the specific variables:
F.e.
$Publisher = "Microsoft"
$AppName = "Office"
$AppVersion = "2010"
$PackageVersion = "1.0"

Then I load a ps1 which contains the variables which do not change
. 'c:\Script\GeneralVariables.ps1'
In this PS1 is defined, f.e.
$FullApplicationName  = "$Publisher - $AppName - $AppVersion - $PackageVersion"
$Description = "Generated by Powershell"

My actual script loads:
Deploy-AppVPackage
{New-CMApplication -name $FullApplicationName -Description $Description}

I would like this script, so I can load the variables in 1 go, so could use
Deploy-AppVPackage -Publisher Microsoft -AppName  Microsoft etc

Please advise.
J.

Jan Hoedt

Help with powershell script to delete *.bak files older N number of days

$
0
0

I have below powershell script to delete 21 days older files into D:\Backup\Full

Script runs and display the files older than 21 days but they are not deleting

the user runs script has full rights on folder

extension of files into folder are *.bak

forfiles-p"D:\Backup\Full"-s-m*.*/D-21/C"cmd /c echo @files"


Muhammad Mehdi

PowerShell: ForEach-Object asks for parameter

$
0
0

Hi guys,

I have a script snippet, in which my "ForEach-Object" part asks for parameters. But I don't know where they should be.

#### Check if MailContact is already in AD Group ####

    $inG = 0;
    (Get-DistributionGroupMember -Identity "$distGroup" -ErrorAction SilentlyContinue) | ForEach-Object
    {
        if($_.name -match $name)
        {
            $inG = 1; #Name found, so contact in Group"$name already in $distGroup, search complete!";
            break; #Break from ForEachObject
        } else {
            $inG = 0; #Not found, continue with loop
        }
    }

    if($inG -eq 0)
    {
        #Not in group at all, add
        "Adding $name to $distGroup";
        Add-DistributionGroupMember -Identity "$distGroup" -Member "$name";
    }

The console output is the following:

<emailremoved> ist bereits als Kontakt vorhanden #<-- comes from a part not in the snippet
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process[0]: 

Best regards,

Phillip




Check the value of an index position in a string powershell

$
0
0

Hello Team,

I need help to know the value of an index position in a string using powershell.

for an instance $array[]= "AH3756997,HLD68900,GIG39707"

I could like to know the value positioned at 3 if this is integer or a char. Example:for AH3756997 the output should be "3" or "intiger". At the same time for HLD68900 the ouput should be "D" or "char"

Regards,

Suman Rout

Powershell - Hashtable - Deleting Items

$
0
0

Hi

I have a program which can have typically 5 processes, i get these in OK.

I then check if a process has died, now until the remove part, i had this working by doing a foreach, getting the key then using this.

However the code would abort on the remove because i was inside enumeration.

I then tried to use a raw index, from the top to the bottom, hoping i can then remove an item..

This is where i came undone, i can't get the syntax right.

>> Help please ?

Now there are probably other ways to deal with this, but i am interested on how you can delete items in this circumstances..

Write-Host $_.Name $_.ProcessId $type $cluster

# $arr is a hash table, gets 5 items refresh

$arr[$_.ProcessId.ToString()] = @{} $arr[$_.ProcessId.ToString()]["Type"] = $type $arr[$_.ProcessId.ToString()]["Count"] = $count # $count gets incremented at the end of the loop which runs every 10s

..... # Now look for processes that have not been updated count wise, if this happens it means that the process no longer exists

$processes = $arr.Count while ($processes -ge 1){ $theProcess = $arr.Keys[$processes] $theCount = $theProcess["Count"] if ($theCount -ne $count) { Write-Host ("{0} process has died in 10s before {1}" -f $arr[$theProcess]["Type"].Value, $date) # other action needed $arr.Remove($arr.Keys[$processes]) } $processes-- }

NB: Indexing is wrong here, should be zero based, however that is not the reason it did not work

Thanks in advance





Dism /online /Get-Features with where clause

$
0
0
Is there any method of filtering a DISM statement with a where enabled clause?  I am trying to do a

Get-ClientFeature|sortstate,name|Format-Table-AutoSize

fromhttps://psclientmanager.codeplex.com/ but without having to install the function on every computer that I want to run it against.  I have tried

Dism/online/Get-Featureswhere"state -eq enabled"

and

I have tried Dism /online /Get-Features Where-Object {$_.State -match “True”}

Conversely if I could run the codeplex script against multiple computers, that would also work.

Modules not loading

$
0
0

Hi,

My modules are suddenly not loading. They were before, checked the $env:PSModulePath and my modulepath is there.

Rebooted machine, nothing helps. Autocomplete of my commands don't work anymore(!) When I load a psm1 and load the function, it does work correctly.

Please advise.
J.


Jan Hoedt

Set-ScreenResolution cmdlet

$
0
0

I have seen a lot of posts about using the Set-ScreenResoltuion command. I am running PowerShell 4.0 and there is no such command. When I run it I get an error.  It says it can't find the cmdlet.  I've searched Google for this and so far I can't find it.  Where can I download the Set-ScreenResolution cmdlet?


mqh7

Need to get a list of network adapters from remote computers

$
0
0

I am running windows 8.1 

Name             : Windows PowerShell ISE Host
Version          : 5.0.10514.6

The domain is a mix or 2008 r2 and 2012 

if i run the command below from my windows 8 PC against one of our hyperv host it works perfect and i get a list of all the network adapters. 

If i run the same command from my windows 8 PC on any of the  virtual servers it host i get a error (see below).

I do have full admin rights to all the servers. Is their a better way to do this or a different command i can run to get the info?

I know i can go old school but this really limits the info 

$systeminfo =    systeminfo -s ms900hvp01 
$systeminfo |  select-string -pattern "Connection Name:"

Thanks so much i do hope i have provided enough detail 

get-netadapter -CimSession MyPhysicalServer

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed PSComputerName       
----                      --------------------                    ------- ------       ----------             --------- --------------       
Host                      Intel(R) I350 Gigabit Network Conn...#4      15 Up           6C-AE-8B-1C-F0-15         1 Gbps ms900hvp01           
Ethernet 3                Intel(R) I350 Gigabit Network Conn...#3      14 Not Present  6C-AE-8B-1C-F0-14          0 bps ms900hvp01           
VM Data-Schools           Intel(R) I350 Gigabit Network Conn...#2      12 Up           6C-AE-8B-1C-F0-13         1 Gbps ms900hvp01           
Ehternet 2                Intel(R) I350 Gigabit Network Connec...       9 Not Present  6C-AE-8B-1C-F0-12          0 bps ms900hvp01           
Local Area Connection     IBM USB Remote NDIS Network Device            5 Disabled     6E-AE-8B-1C-F0-11       9.7 Mbps ms900hvp01    

get-netadapter -CimSession MyVirtualServer



get-netadapter : MS513DS01: Cannot connect to CIM server. The client cannot connect to the destination specified in the request. Verify that
the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service
running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the
destination to analyze and configure the WinRM service: "winrm quickconfig".
At line:1 char:1+ get-netadapter -CimSession MS513DS01+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : ResourceUnavailable: (MSFT_NetAdapter:String) [Get-NetAdapter], CimJobException+ FullyQualifiedErrorId : CimJob_BrokenCimSession,Get-NetAdapter


Lishron

Script for deploying Outlook Forms

$
0
0

Hello. I need to deploy some custom Outlook forms to about 100 users on Office 365.  This means I don't have an Organizational Forms Library and must deploy the forms programmatically.  I'm trying to create a VBScript that I can then convert to an MSI file to use with a group policy.  I started with some VB code that another person posted on-line.  But since I don't have Visual Studio I'm trying to make this work as a VBScript.  Unfortunately some of the variables aren't supported in VBScript.  Can anyone tell me how to replace the Dir$ statement below with something that works in VBScript?  I'm getting an Invalid Character error at Line 8, Char 16.

Thanks!
Joe

Sub main()
 Dim filename
 Dim Temp
 Dim endpos
 Dim mylength
 Set myOlApp = GetObject("", "Outlook.Application")
 ' retrieve Outlook Templates
 filename = Dir$("c:\common\formsdata\*.fdm", vbNormal)
 Do Until filename = ""
 mylength = Len(filename)
 ' strip off the extension from the filename. This will be the
 name of the form.
 endpos = InStr(1, filename, ".oft", 1)
 strTemp = Trim(Mid(filename, 1, endpos - 1))
 ' publish all Outlook forms into the Personal Registry
 Set myItem =
 myOlApp.createitemfromtemplate("C:\common\formsdata\" & filename)
 Set myform = myItem.formdescription
 myform.Name = strTemp
 myform.PublishForm olPersonalRegistry
 filename = Dir$
 Loop
 End Sub


how to run STE-WSMANQUICKCONFIG on multiple servers remotely to enable PSREMOTING.

$
0
0
how to run STE-WSMANQUICKCONFIG on multiple servers remotely to enable PSREMOTING.

Cycle through files using itextsharp

$
0
0

Hello,

I want to use itextsharp to cycle through many files (within powershell) but can't seem to find any info on it either on the powershell side or the itextsharp side.  Any ideas?

I apologize if this is not the place to be asking.

Thanks,

Bernard

ScheduledJob scriptblock failing

$
0
0


I'm writing a script involving scheduledjob cmdlets which opens files that users want at a specific time. I'm able to schedule a job to run a scriptblock which opens .bat and .mp3 but I couldn't use the scriptblock to open other extension file (.txt, .doc, .mp4, .ps1). It's like this:

These commands worked fine:

register-scheduledjob -name abc -trigger $abc -scriptblock {start "d:\folder\a.mp3"}

register-scheduledjob -name abc -trigger $abc -scriptblock {start "d:\folder\a.bat"}

But these commands failed:

register-scheduledjob -name abc -trigger $abc -scriptblock {start "d:\folder\b.txt"}

register-scheduledjob -name abc -trigger $abc -scriptblock {start "d:\folder\b.doc"}

register-scheduledjob -name abc -trigger $abc -scriptblock {start notepad}

In the scriptblock I have tried using invoke-item and invoke-command but none of those succeeded. I then checked task manager to find running process, it turned out that those files I have failed to open were running in the background with no windows opened

Why does it happen? Do you guys have any solution? Please help me. It took me very long time trying to fix that problem! Thanks in advance


Get-WinEvent formatting conundrum

$
0
0

Hi All

I monitor a number of servers which I manage, by extracting the event logs each morning.  I do have a working script usingget-eventlog, which retrieves only errors and warnings for the past 24 hours, and e-mails the logs to myself.  This method has worked perfectly for several years now.  I now wish to redesign the script usingget-winevent.

Now I have noticed a few differences in the way each cmdlet works, as well as the different syntax to be used.  I have created the functions, and appears to be working as expected.  However, my OCD is starting to kick in, causing me some headaches.

When the function completes, it e-mails the results, but the columns is all messed up in Outlook, whereas it appears fine in ISE.  Here is the function I have so far:

Function SystemLog {
    foreach ($Server in $SRV) {
        $HT = @{
            LogName = 'System';
            StartTime = $Yesterday = (get-Date) - (new-TimeSpan -Day 1);
            }

        $MessageParameters = @{
                    Subject = "$Server System Event log - $((Get-Date).ToShortDateString())"
                    Body = Get-WinEvent -ComputerName $Server -FilterHashtable $HT |
                            Where-Object {$_.LevelDisplayName -eq 'Error' -or $_.LevelDisplayName -eq 'Warning'} |
                            Format-table -Wrap |
                            Out-String
                    From = "abc@local"
                    To = "abc@local"
                    SmtpServer = "smtp.local"
                }
                Send-MailMessage @messageParameters
        }
}



In ISE the results are fine, within the appropriate columns, but when it e-mails it, I get the following:

   ProviderName: Microsoft-Windows-WindowsUpdateClient

 

TimeCreated                    Id LevelDisplayName Message                                                                                                                                                  

-----------                    -- ---------------- -------                                                                                                                                                  

01/10/2015 07:00:29            16 Warning         Unable to Connect: Windows is unable to connect to the automatic updates service and therefore cannot download and install updates according to the set  

                                                   schedule. Windows will continue to try to establish a connection.                                                                                        

As you can see, this makes difficult reading, where a longer message wraps back to the beginning of the following line.  I want it to be contained\formatted under the appropriate column headers.  Now some might say it is due to me using ft -wrap, but sadly happens with or without it. 

I also tried to pipe this into the ConvertTo-Html cmdlet, but come across a different issue (result below):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>HTML TABLE</title>

</head><body>

<table>

<colgroup><col/><col/><col/><col/><col/><col/></colgroup>

<tr><th>ClassId2e4f51ef21dd47e99d3c952918aff9cd</th><th>pageHeaderEntry</th><th>pageFooterEntry</th><th>autosizeInfo</th><th>shapeInfo</th><th>groupingEntry</th></tr>

<tr><td>033ecb2bc07a4d43b5ef94ed5a35d280</td><td></td><td></td><td></td><td>Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo</td><td></td></tr>

<tr><td>9e210fe47d09416682b841769c78b8a3</td><td></td><td></td><td></td><td></td><td>Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry</td></tr>

<tr><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>

<tr><td>4ec4f0187cb04f4cb6973460dfe252df</td><td></td><td></td><td></td><td></td><td></td></tr>

<tr><td>cf522b78d86c486691226b40aa69e95c</td><td></td><td></td><td></td><td></td><td></td></tr>

</table>

</body></html>

Any tips or trick I could try and resolve this?  Why is the formatting different from ISE and e-mail?  All I want is for the results to be neatly formatted in the e-mail received.

Cheers

Leo

VBScript to create Outlook Rule on Rss Feeds

$
0
0

I have been looking with no success.  I need to create a rule to do the following:

When new RSS feed arrives

display a new alert on desktop.  I would prefer in VB rather than powershell.  Scripting guy HEEEEELLLLPPP :)

 

Viewing all 15028 articles
Browse latest View live


Latest Images

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